Skip to content

Commit

Permalink
better shell integration with wezterm, less buggy PS1 prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
gzagatti committed Jun 18, 2024
1 parent 134817b commit d434957
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
10 changes: 10 additions & 0 deletions shells/zshenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## wsl {{{
# https://superuser.com/questions/1749781/how-can-i-check-if-the-environment-is-wsl-from-a-shell-script
if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ]; then
# alias for .exe utilities
if hash wezterm.exe 2>/dev/null; then
alias wezterm=wezterm.exe
fi
fi
## }}}

42 changes: 21 additions & 21 deletions shells/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ if [[ $- == *i* ]]; then
# Theme {{{
# https://gist.github.com/thomd/7667642
# https://geoff.greer.fm/lscolors/
if [[ -z "$THEME" ]]; then export THEME=""; fi
if [[ -z "$THEME" ]]; then export THEME="leuven"; fi
export CLICOLOR=1
export LSCOLORS="excxhxDxbxhxhxhxhxfxfx"
export LS_COLORS=""
export LS_COLORS="leuven"
if [[ $THEME == "leuven" ]]; then
LS_COLORS="no=00:fi=00:di=34:ln=32;102:so=30;107:pi=33;103:ex=31:cd=33;107:bd=33;107:su=31;101:sg=34;106:tw=35;101:ow=34;101"
elif [[ $THEME == "dracula" ]]; then
Expand Down Expand Up @@ -225,25 +225,25 @@ if [[ $- == *i* ]]; then
# https://github.com/zsh-users/zsh/blob/master/Misc/vcs_info-examples#L51
precmd_ps1() {

if [[ "$TERM" == "xterm-"* ]] || [[ "$TERM" == "alacritty" ]]; then
# https://gist.github.com/blueyed/c8470c2aad3381c33ea3
# https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color
local oldstty=$(stty -g)
stty raw -echo min 0 time 1
# terminal escape sequence to get the terminal background color
# only works in xterms
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
printf '\033]11;?\033\\'
sleep 0.00000001
read -r termbg
stty $oldstty
local termbg=$(echo $termbg | sed 's/.*\(rgb:[0-9a-f/]*\).*/\1/')
if [[ $termbg == "rgb:f8f8/fbfb/f8f8" ]]; then
THEME="leuven"
elif [[ $termbg == "rgb:2828/2a2a/3636" ]]; then
THEME="dracula"
fi
fi
# if [[ "$TERM" == "xterm-"* ]] || [[ "$TERM" == "alacritty" ]] || [[ "$TERM" == "wezterm" ]]; then
# # https://gist.github.com/blueyed/c8470c2aad3381c33ea3
# # https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color
# local oldstty=$(stty -g)
# stty raw -echo min 0 time 1
# # terminal escape sequence to get the terminal background color
# # only works in xterms
# # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
# printf '\033]11;?\033\\'
# sleep 0.00000001
# read -r termbg
# stty $oldstty
# local termbg=$(echo $termbg | sed 's/.*\(rgb:[0-9a-f/]*\).*/\1/')
# if [[ $termbg == "rgb:f8f8/fbfb/f8f8" ]]; then
# THEME="leuven"
# elif [[ $termbg == "rgb:2828/2a2a/3636" ]]; then
# THEME="dracula"
# fi
# fi

# https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Visual-effects
color=""
Expand Down

0 comments on commit d434957

Please sign in to comment.