atweiden / fzf-extras

Key bindings from fzf wiki
MIT License
192 stars 23 forks source link

zsh 5.5.1 error with fbr: bad math expression: operand expected at `" 3"' #12

Closed jatcwang closed 5 years ago

jatcwang commented 5 years ago

I'm getting this error on zsh 5.5.1 when trying to use fbr to change branches

Here's the fix. If you can reproduce it I'll put up the PR.

fbr() {
       --format='%(refname:short)'
   )" || return

-  num_branches="$(wc -l <<< "$branches")"
+  num_branches="$(echo $(wc -l <<< "$branches") | xargs echo -n)"

   branch="$(
     echo "$branches" \
-      | fzf-tmux -d "$((2 + "$num_branches"))" +m
+      | fzf-tmux -d "$((2 + $num_branches))" +m
   )" || return
atweiden commented 5 years ago

See: Alternate-Shells-FAQ

Please duplicate any code you want to work from fzf-extras.sh into fzf-extras.zsh and exclusively source fzf-extras.zsh if you are using Zsh. I will not accept PRs modifying the Bash code to work with other shells.

jatcwang commented 5 years ago

That's fine (Sorry I haven't seen that wiki page). Will send a PR

aaaaahaaaaa commented 5 years ago

I confirm there's an issue (zsh 5.5.1 (x86_64-apple-darwin17.5.0)).

fbr:18: bad math expression: operand expected at `" 5"'

atweiden commented 5 years ago

Just like hypothetical fish users would be expected to source fzf-extras.fish, not fzf-extras.sh, zsh users are expected to source fzf-extras.zsh, not fzf-extras.sh.

Notice if you would how empty fzf-extras.zsh is, currently. Or how README.md starts off by saying "Additional key bindings for fzf, primarily Bash." Emphasis mine.

In reality, this repo is almost entirely devoid of support for zsh, and it has always been this way. At least it is devoid of intentional support for zsh. Evidently unintentional support for zsh has been leading zsh users to source fzf-extras.sh, which they never should've done. Perhaps it is my fault for not making it more clear how zsh users are meant to source fzf-extras.zsh, but I mean, look at the file extension. There's .zsh, that's for zsh users, then there's .sh, which is for Bash users per the readme.

I would much rather a zsh-using contributor step forward to duplicate code into fzf-extras.zsh, and finesse it for zsh compatibility. I will not do this myself as I do not use zsh.

fzf-extras.sh is not and was never intended to be sourced by zsh users.