tmux-git icon indicating copy to clipboard operation
tmux-git copied to clipboard

Add zsh support

Open rlue opened this issue 3 years ago • 2 comments

This commit modifies tmux-git to support zsh. Prior to this commit, there were three reasons that it failed on zsh:

  1. 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 -e
    

    This commit extracts the -e flag out of the $READLINK variable.

    See https://unix.stackexchange.com/questions/528502 for more details.

  2. in zsh, $status is a special variable that stores the exit code of the most recent command (like $?).

    This commit removes the $status variable altogether, since it is only referenced in one place.

  3. zsh does not recognize the PROMPT_COMMAND variable. Instead we append to the $precmd_functions array.

    See https://superuser.com/questions/735660 for more details.

rlue avatar Sep 01 '22 23:09 rlue

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!

drmad avatar Sep 03 '22 03:09 drmad

All done, sorry for the delay!

rlue avatar Sep 18 '22 15:09 rlue