Use Julia Evans's script to set terminal colors
dblume

dblume commited on 2025-05-09 19:45:15
Showing 4 changed files, with 90 additions and 10 deletions.


See: https://social.jvns.ca/@b0rk/114479436114893982
I choose catppuccin mocha today.
I renamed the script to set_colorscheme so I can change it.
I'm definitely going to be tweaking colors.
... ...
@@ -143,6 +143,10 @@ case "$-" in
143 143
   stty ixoff # enable sending (to app) of start/stop characters
144 144
   stty ixany # let any character restart output, not only start character
145 145
 
146
+  if [ -f ${HOME}/bin/set_colorscheme ]; then
147
+    source ${HOME}/bin/set_colorscheme
148
+  fi
149
+
146 150
   # Don't use export for CDPATH. This may get appended to in .localrc too.
147 151
   # You may have to explicitly source /usr/share/bash-completion/bash_completion
148 152
   CDPATH=.:$HOME
... ...
@@ -71,15 +71,16 @@ See [config.dlma.com](http://config.dlma.com) for more.
71 71
     3. .local/share/nvim/site/plugin/ plugins
72 72
 4. .gitconfig and .gitignore
73 73
 5. [Ghostty](https://ghostty.org/) config in .config/ghostty/config
74
-6. .tmux.conf
75
-7. .inputrc, for vi mode and a [partially matched command history traversal](http://askubuntu.com/questions/59846/bash-history-search-partial-up-arrow/59855#59855).
76
-8. .editrc, for vi mode and tab word completion in macOS.
77
-9. .ssh/config, for a [fix for CVE-2016-0777](https://news.ycombinator.com/item?id=10901588). (Or upgrade to OpenSSH 7.1p2 released Jan 14, 2016 from http://www.openssh.com.)
78
-10. .ripgreprc, for ripgrep, or [rg](https://github.com/BurntSushi/ripgrep/).
79
-11. .gdbinit
80
-12. .visidatarc, to hide [visidata's](https://www.visidata.org/) menu at the top, for the old school UI.
81
-13. .config/gitui/key\_bindings.ron, for vim key bindings in [gitui](https://github.com/extrawurst/gitui).
82
-14. [i3](https://i3wm.org/) configs.
74
+6. Shell script to set the [Catppuccin Mocha](https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/generic/catppuccin-mocha.sh) color scheme.
75
+7. .tmux.conf
76
+8. .inputrc, for vi mode and a [partially matched command history traversal](http://askubuntu.com/questions/59846/bash-history-search-partial-up-arrow/59855#59855).
77
+9. .editrc, for vi mode and tab word completion in macOS.
78
+10. .ssh/config, for a [fix for CVE-2016-0777](https://news.ycombinator.com/item?id=10901588). (Or upgrade to OpenSSH 7.1p2 released Jan 14, 2016 from http://www.openssh.com.)
79
+11. .ripgreprc, for ripgrep, or [rg](https://github.com/BurntSushi/ripgrep/).
80
+12. .gdbinit
81
+13. .visidatarc, to hide [visidata's](https://www.visidata.org/) menu at the top, for the old school UI.
82
+14. .config/gitui/key\_bindings.ron, for vim key bindings in [gitui](https://github.com/extrawurst/gitui).
83
+15. [i3](https://i3wm.org/) configs.
83 84
 
84 85
 #### Optional manual steps for fresh setups
85 86
 
... ...
@@ -0,0 +1,74 @@
1
+#!/bin/sh
2
+# catppuccin mocha
3
+# https://github.com/mbadolato/iTerm2-Color-Schemes?tab=readme-ov-file#catppuccin-mocha
4
+
5
+# source for these helper functions:
6
+# https://github.com/chriskempson/base16-shell/blob/master/templates/default.mustache
7
+if [ -n "$TMUX" ]; then
8
+  # Tell tmux to pass the escape sequences through
9
+  # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
10
+  put_template() { printf '\033Ptmux;\033\033]4;%d;rgb:%s\033\033\\\033\\' $@; }
11
+  put_template_var() { printf '\033Ptmux;\033\033]%d;rgb:%s\033\033\\\033\\' $@; }
12
+  put_template_custom() { printf '\033Ptmux;\033\033]%s%s\033\033\\\033\\' $@; }
13
+elif [ "${TERM%%[-.]*}" = "screen" ]; then
14
+  # GNU screen (screen, screen-256color, screen-256color-bce)
15
+  put_template() { printf '\033P\033]4;%d;rgb:%s\007\033\\' $@; }
16
+  put_template_var() { printf '\033P\033]%d;rgb:%s\007\033\\' $@; }
17
+  put_template_custom() { printf '\033P\033]%s%s\007\033\\' $@; }
18
+elif [ "${TERM%%-*}" = "linux" ]; then
19
+  put_template() { [ $1 -lt 16 ] && printf "\e]P%x%s" $1 $(echo $2 | sed 's/\///g'); }
20
+  put_template_var() { true; }
21
+  put_template_custom() { true; }
22
+else
23
+  put_template() { printf '\033]4;%d;rgb:%s\033\\' $@; }
24
+  put_template_var() { printf '\033]%d;rgb:%s\033\\' $@; }
25
+  put_template_custom() { printf '\033]%s%s\033\\' $@; }
26
+fi
27
+
28
+# 16 color space
29
+put_template 0  "45/47/5a"
30
+put_template 1  "f3/8b/a8"
31
+put_template 2  "a6/e3/a1"
32
+put_template 3  "f9/e2/af"
33
+put_template 4  "89/b4/fa"
34
+put_template 5  "f5/c2/e7"
35
+put_template 6  "94/e2/d5"
36
+put_template 7  "a6/ad/c8"
37
+put_template 8  "58/5b/70"
38
+put_template 9  "f3/77/99"
39
+put_template 10 "89/d8/8b"
40
+put_template 11 "eb/d3/91"
41
+put_template 12 "74/a8/fc"
42
+put_template 13 "f2/ae/de"
43
+put_template 14 "6b/d7/ca"
44
+put_template 15 "ba/c2/de"
45
+
46
+color_foreground="cd/d6/f4"
47
+color_background="1e/1e/2e"
48
+
49
+if [ -n "$ITERM_SESSION_ID" ]; then
50
+  # iTerm2 proprietary escape codes
51
+  put_template_custom Pg "cdd6f4"
52
+  put_template_custom Ph "1e1e2e"
53
+  put_template_custom Pi "cdd6f4"
54
+  put_template_custom Pj "585b70"
55
+  put_template_custom Pk "cdd6f4"
56
+  put_template_custom Pl "f5e0dc"
57
+  put_template_custom Pm "cdd6f4"
58
+else
59
+  put_template_var 10 $color_foreground
60
+  put_template_var 11 $color_background
61
+  if [ "${TERM%%-*}" = "rxvt" ]; then
62
+    put_template_var 708 $color_background # internal border (rxvt)
63
+  fi
64
+  put_template_custom 12 ";7" # cursor (reverse video)
65
+fi
66
+
67
+# clean up
68
+unset -f put_template
69
+unset -f put_template_var
70
+unset -f put_template_custom
71
+
72
+unset color_foreground
73
+unset color_background
74
+
... ...
@@ -7,7 +7,8 @@ declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" ".editrc" ".gitconfig"
7 7
                      ".gitignore" ".inputrc" ".tmux.conf" ".ssh/config" ".ripgreprc"
8 8
                      ".gdbinit" ".config/gitui/key_bindings.ron" ".visidatarc"
9 9
                      ".config/i3/config" ".config/i3status/config"
10
-                     ".config/dunst/dunstrc" ".config/alacritty/alacritty.toml")
10
+                     ".config/dunst/dunstrc" ".config/alacritty/alacritty.toml"
11
+                     "bin/set_colorscheme")
11 12
 declare -i dry_run=0
12 13
 
13 14
 ## exit the shell (with status 2) after printing the message
14 15