From d50e9ffff35a12b542f41e1bdf1ad5357fba7ead Mon Sep 17 00:00:00 2001 From: Maxime Bouillot Date: Sun, 11 Sep 2022 09:55:11 +0200 Subject: [PATCH] Add the possibility to ignore arguments in alliases (#9199) * Replace ";" with "\n" in alias-generated functions This can let us add a "#" in our aliases to make them ignore additional arguments. * Update changelog about aliases that ignore arguments * Update test for alias.fish This is now compliant with the aliases that can ignore arguments. --- CHANGELOG.rst | 1 + share/functions/alias.fish | 3 ++- tests/checks/alias.fish | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b8de09673..b6025df82 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -97,6 +97,7 @@ Other improvements ------------------ - The css for fish's documentation no longer depends on sphinx' stock "classic" theme. This should improve compatibility with sphinx versions and ease upgrading (:issue:`9003`). - The web-based configuration tool now works on systems that have ipv6 disabled (:issue:`3857`). +- Aliases can ignore arguments by ending them with ``#``. For distributors diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 0425aa6c7..5fe783cab 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -67,7 +67,8 @@ function alias --description 'Creates a function wrapping a command' set wraps --wraps (string escape -- $body) end - echo "function $name $wraps --description $cmd_string; $prefix $body \$argv; end" | source + echo "function $name $wraps --description $cmd_string; $prefix $body \$argv + end" | source # The function definition in split in two lines to ensure that a '#' can be put in the body. if set -q _flag_save funcsave $name end diff --git a/tests/checks/alias.fish b/tests/checks/alias.fish index b99803949..de725979d 100644 --- a/tests/checks/alias.fish +++ b/tests/checks/alias.fish @@ -29,7 +29,7 @@ alias d "'/mnt/c/Program Files (x86)/devenv.exe' /Edit" functions d # CHECK: # Defined via `source` # CHECK: function d --wraps=\'/mnt/c/Program\ Files\ \(x86\)/devenv.exe\'\ /Edit --description alias\ d\ \'/mnt/c/Program\ Files\ \(x86\)/devenv.exe\'\ /Edit -# CHECK: '/mnt/c/Program Files (x86)/devenv.exe' /Edit $argv; +# CHECK: '/mnt/c/Program Files (x86)/devenv.exe' /Edit $argv # CHECK: end # Use "command" to prevent recusion, and don't add --wraps to avoid accidental recursion in completion. @@ -37,7 +37,7 @@ alias e 'e --option=value' functions e # CHECK: # Defined via `source` # CHECK: function e --description 'alias e e --option=value' -# CHECK: command e --option=value $argv; +# CHECK: command e --option=value $argv # CHECK: end # Don't add --wraps if it looks like a wrapper command to avoid accidental recursion in completion. @@ -45,5 +45,5 @@ alias f 'wrapper around f' functions f # CHECK: # Defined via `source` # CHECK: function f --description 'alias f wrapper around f' -# CHECK: wrapper around f $argv; +# CHECK: wrapper around f $argv # CHECK: end