Fishtape is broken with Fish 2.6
arbourd opened this issue · 4 comments
Getting this when trying to use fishtape
with a legitimate path:
$ fishtape test/*test.fish master
- (line 95): Missing end to balance this function definition
function __fishtape@total; if test $__fishtape_count -eq 0; fishtape_cleanup; exit 1; end;; printf "\n1..%s\n" $__fishtape_count; printf "# tests %s\n" $__fishtape_count; printf "# pass %s\n" (math $__fishtape_count - $__fishtape_fails);; if test $__fishtape_fails -gt 0; printf "# fail %s\n" $__fishtape_fails; fishtape_cleanup; exit 1; end;; fishtape_cleanup; printf "\n# ok\n"
^
from sourcing file -
called on standard input
source: Error while reading file '-'
This happens on both Ubuntu 16.04 and macOS 10.12 with Fish 2.6.
The functions
function changed with Fish 2.6 (fish-shell/fish-shell@2e38cf2) to add a comment to the top of the body like :
$ functions fish_clipboard_copy master
# Defined in /usr/local/Cellar/fish/2.6.0/share/fish/functions/fish_clipboard_copy.fish @ line 1
function fish_clipboard_copy
if type -q pbcopy
commandline | pbcopy
else if type -q xsel
commandline | xsel --clipboard
end
end
This comment is breaking https://github.com/fisherman/fishtape/blob/master/fishtape.fish#L62 because sed
is only removing the first and last line of the functions
output, leaving the function
definition.
Post sed
the output now looks like:
$ functions fish_clipboard_copy | sed '1d;$d;s/\\\/\\\\\\\/g' master
function fish_clipboard_copy
if type -q pbcopy
commandline | pbcopy
else if type -q xsel
commandline | xsel --clipboard
end
... causing the error I first mentioned.
I've temporarily fixed this locally by removing the top two lines (sed '1,2d;$d;s/\\\/\\\\\\\/g'
), but this isn't backwards compatible with anything < 2.6 and probably isn't the best solution.
@arbourd Thanks for the bug report. Can you open a PR?
I don't think the fix I have above is the right fix.
The simple backwards compatible way would be checking $FISH_VERSION
, but that feels hacky. Do you have any opinion on how we should address this?
@arbourd Well, we just need to remove comments from whatever definition functions
gives us.
functions fish_clipboard_copy | awk '/^#/ { next } { print }'
We can modify the awk script to do this, or add the snippet above before in the pipeline.
What do you think? :)
I took the easy way out, as I couldn't think of a way to get the already existing awk
script to remove the first line of the function at that point. To be honest, awk is mostly voodoo black magic to me.
This should fix it for now, is backwards compatible and readable. Perhaps not as elegant a solution as you'd implement though.