Created
February 14, 2025 03:18
-
-
Save jscheel/00c3ddf6326536b2cf94f0569be95e57 to your computer and use it in GitHub Desktop.
prodmode switcher for ghostty and fish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just a fish function I use for switching my terminal into "production mode". Sets a few asdf versions and changes the theme to red. | |
function _prodmode_store_colors | |
if test -n "$PRODMODE_COLOR_BACKUP" -a -f "$PRODMODE_COLOR_BACKUP" | |
return | |
end | |
set -gx PRODMODE_COLOR_BACKUP (mktemp) | |
# Save current terminal settings | |
set -l old_stty (stty -g) | |
# Set terminal to raw mode with a shorter timeout | |
stty raw -echo min 0 time 0 | |
for i in 10 11 12 17 19 4/0 4/1 4/2 4/3 4/4 4/5 4/6 4/7 4/8 4/9 4/10 4/11 4/12 4/13 4/14 4/15 | |
printf '\033]%s;?\007' $i | |
sleep 0.01 | |
read -z color | |
if test -n "$color" | |
# Remove the escape character from the start and bell from the end | |
set -l clean_color (string replace -r '^\x1b(.+)\x07$' '$1' $color) | |
if test -n "$clean_color" | |
echo "$clean_color" >> $PRODMODE_COLOR_BACKUP | |
end | |
end | |
end | |
# Restore terminal settings | |
stty $old_stty | |
end | |
function _prodmode_restore_colors | |
if test -n "$PRODMODE_COLOR_BACKUP" -a -f "$PRODMODE_COLOR_BACKUP" | |
# Save current terminal settings | |
set -l old_stty (stty -g) | |
# Set terminal to raw mode with a shorter timeout | |
stty raw -echo min 0 time 0 | |
while read -l line | |
printf '\033%s\007' $line | |
end < $PRODMODE_COLOR_BACKUP | |
# Restore terminal settings | |
stty $old_stty | |
rm $PRODMODE_COLOR_BACKUP | |
set -e PRODMODE_COLOR_BACKUP | |
end | |
end | |
function _prodmode_set_colors | |
printf '\033]11;rgb:7624/2323/2323\007' # Background | |
printf '\033]10;rgb:ffff/ffff/ffff\007' # Foreground | |
printf '\033]12;rgb:ffff/ffff/ffff\007' # Cursor color | |
printf '\033]17;rgb:0736/4242/4242\007' # Selection background | |
printf '\033]19;rgb:ffff/ffff/ffff\007' # Selection foreground | |
end | |
function _prodmode_set_asdf_versions | |
asdf shell kubectl 1.23.6 | |
asdf shell helm 3.8.2 | |
end | |
function _prodmode_unset_asdf_versions | |
asdf shell kubectl --unset | |
asdf shell helm --unset | |
end | |
function prodmode | |
if test (count $argv) -ne 1 | |
echo "Usage: prodmode [on|off]" | |
return 1 | |
end | |
switch $argv[1] | |
case "on" | |
_prodmode_store_colors | |
_prodmode_set_colors | |
_prodmode_set_asdf_versions | |
case "off" | |
_prodmode_restore_colors | |
_prodmode_unset_asdf_versions | |
case '*' | |
echo "Usage: prodmode [on|off]" | |
return 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment