+/config
my dotfiles and nix configuration
git clone https://git.julia.blue/+/config
d33df88
main
1# This is mostly taken from kitty's shell integration docs. The subset of 2# features used here should work with wezterm and ghostty as well: 3# - OSC133 prompt awareness 4# - changing window title to current dir/host/command 5# - changing cursor shape to line in the line editor 6# https://sw.kovidgoyal.net/kitty/shell-integration/#how-it-works 7# https://wezfurlong.org/wezterm/shell-integration.html 8# https://ghostty.org/docs/features/shell-integration 9 10typeset -gi _tty_fd 11{ 12zmodload zsh/system && { 13 { [[-w $TTY ]] &&sysopen -o cloexec -wu _tty_fd -- $TTY } || 14 { [[-w /dev/tty ]] &&sysopen -o cloexec -wu _tty_fd -- /dev/tty } 15 } 16}2 >/dev/null || ((_tty_fd =1 )) 17 18typeset -gi _prompt_state 19_prompt_precmd () { 20local -i cmd_status =$? 21if ! zle ;then 22if ((_prompt_state ==1 ));then 23-nu $_tty_fd'\e]133;D;' $cmd_status'\a' 24 ((_prompt_state =2 )) 25elif ((_prompt_state ==2 ));then 26-nu $_tty_fd'\e]133;D\a' 27fi 28fi 29 30local mark1 =$'%{\e]133;A\a%}' 31if [[-o prompt_percent ]];then 32typeset -g precmd_functions 33if [[${precmd_functions[-1]} ==_prompt_precmd ]];then 34local mark2 =$'%{\e]133;A;k=s\a%}' 35 [[ $PS1 ==* $mark1* ]] ||PS1 =${mark1}${PS1} 36 [[ $PS2 ==* $mark2* ]] ||PS2 =${mark2}${PS2} 37 ((_prompt_state =2 )) 38else 39precmd_functions =(${precmd_functions:#_prompt_precmd} _prompt_precmd ) 40if ! zle ;then 41-rnu $_tty_fd-- $mark1[3,-3 ] 42 ((_prompt_state =2 )) 43 fi 44 fi 45 elif! zle ;then 46-rnu $_tty_fd-- $mark1[3,-3 ] 47 ((_prompt_state =2 )) 48 fi 49} 50 51_prompt_preexec () { 52PS1 =${PS1//$'%{\e]133;A\a%} '} 53PS2=${PS2//$'% {\e ]133;A ;k =s\a% }'} 54print -nu $_tty_fd '\e ]133;C\a' 55(( _prompt_state = 1 )) 56 57print -nu $_tty_fd '\e [1q' # block cursor 58} 59 60# use "application mode" inside the line editor so keybinds don't change 61zle-line-init () { 62-nu "$_tty_fd" '\e[5 q' # line cursor 63echoti smkx 64} 65zle-line-finish () {echoti rmkx ; } 66if ((${+terminfo[smkx]} )) && ((${+terminfo[rmkx]} ));then 67zle -N zle-line-init &&zle -N zle-line-finish 68fi 69 70local is_ssh_session ="n" 71if [[-n "$KITTY_PID" ]];then 72elif [[-n "$SSH_TTY" ]];then 73is_ssh_session ="y" 74elif [[-n " $( command -v who ) " ]];then 75 [[" $( command who -m 2> /dev/null ) " =~ "\([a-fA-F.:0-9]+\)$" ]] &&is_ssh_session ="y" 76fi 77 78if [["$is_ssh_session" =="y" ]];then 79functions [_prompt_precmd ]+=" 80print -Prnu $_tty_fd \$'\\e]2;'\"%m: \${(%):-%(4~|…/%3~|%~)}\"\$'\\a'" 81functions [_prompt_preexec ]+=" 82print -Prnu $_tty_fd \$'\\e]2;'\"%m: \${(V)1}\"\$'\\a'" 83else 84functions [_prompt_precmd ]+=" 85print -rnu $_tty_fd \$'\\e]2;'\"\${(%):-%(4~|…/%3~|%~)}\"\$'\\a'" 86functions [_prompt_preexec ]+=" 87print -rnu $_tty_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'" 88fi 89 90preexec_functions +=(_prompt_preexec ) 91precmd_functions +=(_prompt_precmd )