diff options
| author | Marc Vertes <mvertes@free.fr> | 2024-11-07 22:48:59 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2024-11-07 22:48:59 +0100 |
| commit | 662f349e41b6c22b5c66467ede9c5535fd4ce26a (patch) | |
| tree | 6c9d62038867d12c9357e60f16c9c92c85ecdb40 | |
| parent | 21cd2e0f8e8f880847b9dbbcf2198407234c2a29 (diff) | |
termcolor
| -rw-r--r-- | .bashrc | 8 | ||||
| -rwxr-xr-x | bin/termcolor | 52 |
2 files changed, 57 insertions, 3 deletions
@@ -84,6 +84,7 @@ alias ww='(cd ~/Wiki && vi home_page.md)' alias s='(cd ~/Wiki && vi scratch.md)' alias dotfiles='git --git-dir=$HOME/dotfiles --work-tree=$HOME' alias pv='qlmanage -p' +alias tc=termcolor gtr() { go test -v -run "$@"; } export -f gtr @@ -115,9 +116,6 @@ export YAEGI_SYSCALL=1 mkcd() { mkdir -p "$1" && cd "$1"; } -mosht() { mosh "$@" -- tmux a; } -export -f mosht - ssht() { ssh -t "$@" -- tmux a; } export -f ssht @@ -185,3 +183,7 @@ export HOMEBREW_REPOSITORY=/opt/homebrew # Added by Radicle. export PATH="$PATH:/Users/marc/.radicle/bin" + +#case $TERM_PROGRAM in +#Apple_Terminal) termcolor +#esac diff --git a/bin/termcolor b/bin/termcolor new file mode 100755 index 0000000..a310e19 --- /dev/null +++ b/bin/termcolor @@ -0,0 +1,52 @@ +#!/bin/sh +# Change background on a MacOS terminal. + +# hsv2rgb converts a hue-saturation-brightness color into red-green-blue. +hsv2rgb() { + awk -v h="$1" -v s="$2" -v v="$3" 'BEGIN { + h = h / 360 # normalize hue angle in degree (0-360) + s = s / 100 # normalize saturation percentage (0-100) + v = v / 100 # normalize brightness percentage (0-100) + i = int(h * 6) + f = h * 6 - i + p = v * (1 - s) + q = v * (1 - f * s) + t = v * (1 - (1 - f) * s) + j = i % 6 + if (j == 0) { r = v; g = t; b = p } else + if (j == 1) { r = q; g = v; b = p } else + if (j == 2) { r = p; g = v; b = t } else + if (j == 3) { r = p; g = q; b = v } else + if (j == 4) { r = t; g = p; b = v } else + if (j == 5) { r = v; g = p; b = q } + print "{" int(r * 65535) ", " int(g * 65535) ", " int(b * 65535) "}" + }' +} + +sat=8 bri=100 fg="{0, 0, 0}" +case $1 in + white) hue=0 sat=0 ;; + gr[ae]y) hue=0 sat=0 bri=93 ;; + black) hue=0 sat=100 bri=0 fg="{56283, 56283, 56283}" ;; + red) hue=0 ;; + orange) hue=30 ;; + yellow) hue=45 ;; + green) hue=90 ;; + blue) hue=180 ;; + purple) hue=270 ;; + -[0-9]) hue=$((-60 * $1)) ;; + [0-9]*) hue=$1 ;; + *) hue=$((RANDOM % 360)) ;; +esac + +[ "$2" ] && sat=$2 +[ "$3" ] && bri=$3 + +case $TERM_PROGRAM in + Apple_Terminal) tp=Terminal ;; + *) tp='' ;; +esac + +[ "$tp" ] || exit +osascript -e "tell application \"$tp\" to set background color of window 1 to $(hsv2rgb $hue $sat $bri)" +osascript -e "tell application \"$tp\" to set normal text color of window 1 to $fg" |
