From bfc919c4ce43fb12cea52db11a08f44596d1f814 Mon Sep 17 00:00:00 2001 From: TrudeEH Date: Fri, 3 May 2024 22:31:08 +0100 Subject: [PATCH] Misc fixes, color script and hex <-> color conversions --- dotfiles/.bashrc | 33 +++++++++++++++++++++++++++++++++ dotfiles/.config/sway/config | 4 ++-- scripts/colors.sh | 6 ++++++ scripts/oneline.sh | 0 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100755 scripts/colors.sh mode change 100644 => 100755 scripts/oneline.sh diff --git a/dotfiles/.bashrc b/dotfiles/.bashrc index ca93e48c..2c17e157 100644 --- a/dotfiles/.bashrc +++ b/dotfiles/.bashrc @@ -67,4 +67,37 @@ pushall() { fi } +hex2color(){ + hex=${1#"#"} + r=$(printf '0x%0.2s' "$hex") + g=$(printf '0x%0.2s' ${hex#??}) + b=$(printf '0x%0.2s' ${hex#????}) + printf '%03d' "$(( (r<75?0:(r-35)/40)*6*6 + + (g<75?0:(g-35)/40)*6 + + (b<75?0:(b-35)/40) + 16 ))" +} + +color2hex(){ + dec=$(($1%256)) ### input must be a number in range 0-255. + if [ "$dec" -lt "16" ]; then + bas=$(( dec%16 )) + mul=128 + [ "$bas" -eq "7" ] && mul=192 + [ "$bas" -eq "8" ] && bas=7 + [ "$bas" -gt "8" ] && mul=255 + a="$(( (bas&1) *mul ))" + b="$(( ((bas&2)>>1)*mul ))" + c="$(( ((bas&4)>>2)*mul ))" + printf 'dec= %3s basic= #%02x%02x%02x\n' "$dec" "$a" "$b" "$c" + elif [ "$dec" -gt 15 ] && [ "$dec" -lt 232 ]; then + b=$(( (dec-16)%6 )); b=$(( b==0?0: b*40 + 55 )) + g=$(( (dec-16)/6%6)); g=$(( g==0?0: g*40 + 55 )) + r=$(( (dec-16)/36 )); r=$(( r==0?0: r*40 + 55 )) + printf 'dec= %3s color= #%02x%02x%02x\n' "$dec" "$r" "$g" "$b" + else + gray=$(( (dec-232)*10+8 )) + printf 'dec= %3s gray= #%02x%02x%02x\n' "$dec" "$gray" "$gray" "$gray" + fi +} + set completion-ignore-case On diff --git a/dotfiles/.config/sway/config b/dotfiles/.config/sway/config index 5862adc8..6f04b4e2 100644 --- a/dotfiles/.config/sway/config +++ b/dotfiles/.config/sway/config @@ -216,9 +216,9 @@ default_floating_border pixel 3 smart_borders on # Border colors -client.focused #fab387 #fab387 #1e1e2e +client.focused #d75f5f #d75f5f #1e1e2e client.unfocused #1e1e2e #1e1e2e #cdd6f4 -client.focused_inactive #fab387 #fab387 #1e1e2e +client.focused_inactive #1e1e2e #1e1e2e #1e1e2e client.placeholder #f9e2af #f9e2af #1e1e2e client.urgent #f38ba8 #f38ba8 #1e1e2e client.background #1e1e2e diff --git a/scripts/colors.sh b/scripts/colors.sh new file mode 100755 index 00000000..048e699f --- /dev/null +++ b/scripts/colors.sh @@ -0,0 +1,6 @@ +for i in {0..255} ; do + printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i" + if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then + printf "\n"; + fi +done diff --git a/scripts/oneline.sh b/scripts/oneline.sh old mode 100644 new mode 100755