tmux-git
tmux-git copied to clipboard
Add zsh support
This commit modifies tmux-git to support zsh. Prior to this commit, there were three reasons that it failed on zsh:
-
in bash vs. zsh, unquoted string vars containing spaces are handled differently.
In bash, unquoted string vars are automatically split upon expansion:
READLINK='greadlink -e' GIT_REPO=`$READLINK $dir` # evaluates to GIT_REPO=`greadlink -e $dir`whereas in zsh, they are preserved as a whole string, leading to the following failure:
READLINK='greadlink -e' GIT_REPO=`$READLINK $dir` # evaluates to GIT_REPO=`"greadlink -e" $dir` zsh: command not found: greadlink -eThis commit extracts the
-eflag out of the$READLINKvariable.See https://unix.stackexchange.com/questions/528502 for more details.
-
in zsh,
$statusis a special variable that stores the exit code of the most recent command (like$?).This commit removes the
$statusvariable altogether, since it is only referenced in one place. -
zsh does not recognize the
PROMPT_COMMANDvariable. Instead we append to the$precmd_functionsarray.See https://superuser.com/questions/735660 for more details.
Hey @rlue , thank you very much, this was a long requested feature!
I used the '-e' inside the variable $READLINK in case sometime in the future this script will be ported to another OS with different readlink implementation 😅 but in the mean time, your solution is OK.
The code looks simple enough, should work fine. Just one thing: can you update the fix for the item 3 to something like this:
case $SHELL in
*zsh)
if ! (($precmd_functions[(Ie)update_tmux])); then
precmd_functions=($precmd_functions update_tmux)
fi
;;
*)
PROMPT_COMMAND="update_tmux; $PROMPT_COMMAND"
;;
esac
?
cPanel uses in some cases a shell called 'jailshell' (which is a Bash jailed), and will fail with your code. Let's leave bash as default for now.
Thanks!
All done, sorry for the delay!