From 7e5e47a8aa9acdb6e10e2a054bb531e860fecb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=9Aliwka?= Date: Sat, 17 Feb 2018 23:45:46 +0100 Subject: [PATCH 1/2] Demonstrate incorrect homeshick.fish behavior When invoked without arguments, the function prints `test: Unexpected argument type at index 5` before usage info. This commit adds a test ensuring that nothing is printed to stderr in such scenario, which would be correct behavior. --- test/suites/misc.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/suites/misc.bats b/test/suites/misc.bats index 107d1c8f..c9e82a71 100755 --- a/test/suites/misc.bats +++ b/test/suites/misc.bats @@ -30,3 +30,11 @@ load ../helper run grep -q 'nn$' <<<"$output" [ $status -eq 1 ] } + +@test 'fish function should not print errors when invoked without arguments' { + [ "$(type -t fish)" = "file" ] || skip "fish not installed" + cmd="source "$HOMESHICK_FN_SRC_FISH"; and $HOMESHICK_FN" + local stderr + stderr=$( fish <<< "$cmd" 2>&1 >/dev/null ) + [ -z "$stderr" ] +} From 83b05a77465cebfd185c574adbd6fa57a5caeec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=9Aliwka?= Date: Sun, 18 Feb 2018 00:07:52 +0100 Subject: [PATCH 2/2] Fix argument testing in homeshick.fish This commit resolves issue demonstrated in 7e5e47a. The `$argv[1]` expression is being put in quotes, to prevent syntax errors if there are no arguments passed to the function. --- homeshick.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeshick.fish b/homeshick.fish index 4110839b..bfe39eec 100644 --- a/homeshick.fish +++ b/homeshick.fish @@ -4,7 +4,7 @@ # "homeshick cd CASTLE" to enter a castle. function homeshick - if test \( (count $argv) = 2 -a $argv[1] = "cd" \) + if test \( (count $argv) = 2 -a "$argv[1]" = "cd" \) cd "$HOME/.homesick/repos/$argv[2]" else if set -q HOMESHICK_DIR eval $HOMESHICK_DIR/bin/homeshick (string escape -- $argv)