simnalamburt / shellder

:shell: Featured zsh/fish shell theme
Other
292 stars 54 forks source link

A wild "Unknown option -q" error appears in fish 2.7.0 #28

Closed xnuk closed 6 years ago

xnuk commented 6 years ago
~/.config/fish/functions/fish_prompt.fish (line 240): function: Unknown option “-q”
~/.config/fish/functions/fish_prompt.fish (line 240): 
function type -q -a name -d "Check if a function or program is type -q."
^
from sourcing file ~/.config/fish/functions/fish_prompt.fish
    called on standard input

in command substitution
    called on standard input

       functionfunction - create a function
        -

   Synopsis
       function NAME [OPTIONS]; BODY; end

function: Type “help function” for related documentation

function type -q -a name -d "Check if a function or program is type -q."
  type "$name" ^/dev/null >&2
^
from sourcing file ~/.config/fish/functions/fish_prompt.fish
    called on standard input

in command substitution
    called on standard input

Related pull request: #22

simnalamburt commented 6 years ago

Looks like the small hack which made shellder to support both fish<2.2 and fish≥2.2 finally stopped working. The type -q option has been added in fish 2.2 with https://github.com/fish-shell/fish-shell/commit/6f7a7459.

This patch might work but I didn't test it with fish<2.2 yet.

if not printf '%s\n' '2.2.0' $FISH_VERSION | sort --check=silent --version-sort
  function type -q -a name -d "Check if a function or program is type -q."
    type "$name" ^/dev/null >&2
  end
end

Tested with

Reference
simnalamburt commented 6 years ago

Since we just want to check if binary git, svn, and hg do exist, we should use command -v "$name" ^/dev/null >&2 instead of type -q "$name" since it's 80% faster.

# a.fish
for _ in (seq 10000)
  type -q gcc
end
# b.fish
for _ in (seq 10000)
  command -v gcc ^/dev/null >&2
end
$ /usr/bin/time fish a.fish; /usr/bin/time fish b.fish
        0.90 real         0.87 user         0.02 sys
        0.49 real         0.18 user         0.27 sys

But still, the command -v option was also added in fish 2.2.0 with https://github.com/fish-shell/fish-shell/commit/cc565fc16c69affeda4a7e8a1c8d7e419fc5c519 and https://github.com/fish-shell/fish-shell/commit/72e8489d50d749c86d5b57609bb0c4d83a03b41a. I must decide where to fallback in fish<2.2.0

Let's use command -v "$name" ^/dev/null >&2 for fish≥2.2.0, and use type "$name" ^/dev/null >&2 for otherwise.