Skip to content

Add the possibility to ignore arguments in alliases#9199

Merged
faho merged 3 commits into
fish-shell:masterfrom
Arkaeriit:alias_ignoring_arguments
Sep 11, 2022
Merged

Add the possibility to ignore arguments in alliases#9199
faho merged 3 commits into
fish-shell:masterfrom
Arkaeriit:alias_ignoring_arguments

Conversation

@Arkaeriit
Copy link
Copy Markdown
Contributor

@Arkaeriit Arkaeriit commented Sep 10, 2022

In other shells such as Bash, one can end its alias with # in order to make the alias ignore additional arguments. Example:

$ alias test='echo test #'
$ test abcd
test

Unfortunately, in Fish, this is not possible yet.

$ alias test='echo test #'
- (line 1): function: test: cannot use reserved keyword as function name
function test --wraps 'echo test #' --description 'alias test=echo test #';  echo test # $argv
^
from sourcing file -
        called on line 70 of file /usr/local/share/fish/functions/alias.fish
in function 'alias' with arguments 'test=echo\ test\ \#'

This PR modifies alias.fish to make it possible to create this kind of alias.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages. (Non applicable ?)
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@faho
Copy link
Copy Markdown
Member

faho commented Sep 10, 2022

You're going to have to adjust the tests as well - see tests/checks/alias.fish.

They print the semicolon so you probably just have to remove it.

The checks/ scripts are normal fish scripts, and their expected output is embedded in the # CHECK: and # CHECKERR: (for stderr) lines.


However, in general: Alias is a cheesy compatibility function. If you want an easier time of working with more control, try defining actual functions! It's much nicer because you don't need to fiddle with that additional layer of quoting, have proper syntax highlighting, can use many more constructs, ...! It's heavily recommended, and it's also been the recommended way to handle it in bash for years.

@faho faho added this to the fish-future milestone Sep 10, 2022
@Arkaeriit
Copy link
Copy Markdown
Contributor Author

The tests have been updated.

Thank you very much for your quick presentation of the tests in fish, it is heartwarming to see how welcoming you are with new contributors.

Thank you as well for the details on the best practice of fish use. I do use function for the wast majority of my aliases but there is some cases were a simple alias fell more suitable.

This can let us add a "#" in our aliases to make
them ignore additional arguments.
This is now compliant with the aliases that can
ignore arguments.
@Arkaeriit Arkaeriit force-pushed the alias_ignoring_arguments branch from 9621cc8 to af2f1a5 Compare September 10, 2022 22:48
@Arkaeriit
Copy link
Copy Markdown
Contributor Author

Should the behavior added in this PR be documented? I feel like this is not necessary as this is a very niche behavior, it does not contradict the code example in the alias documentation, bash does not document the behavior, and functions are preferred over aliases. Yet, If you want me to document that in the alias documentation, I can do it.

@faho
Copy link
Copy Markdown
Member

faho commented Sep 11, 2022

Should the behavior added in this PR be documented? I feel like this is not necessary as this is a very niche behavior, it does not contradict the code example in the alias documentation

Nah, it's fine.

@faho faho merged commit d50e9ff into fish-shell:master Sep 11, 2022
@faho faho modified the milestones: fish-future, fish 3.6.0 Sep 11, 2022
@faho
Copy link
Copy Markdown
Member

faho commented Sep 11, 2022

Merged, thanks!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants