From 25169a44ed9108fd4e0a437cd39a54ab4968790c Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Fri, 6 Apr 2018 10:27:40 -0700 Subject: [PATCH] Add `alias -s/--save`, which saves the alias. Also updates the `alias` documentation to mention the `-h`/`--help` option, which was previously undocumented. --- CHANGELOG.md | 1 + doc_src/alias.txt | 10 ++++++++-- share/functions/alias.fish | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cdb4fae..581f8aea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ This section is for changes merged to the `major` branch that are not also merge - `functions --handlers` can be used to show event handlers (#4694). - Variables set in `if` and `while` conditions are available outside the block (#4820). - The universal variables file no longer contains the MAC address. It is now at the fixed location `.config/fish/fish_universal_variables` (#1912). +- `alias` now has a `-s` and `--save` option to save the function generated by the alias using `funcsave` (#4878). ## Other significant changes - Command substitution output is now limited to 10 MB by default (#3822). diff --git a/doc_src/alias.txt b/doc_src/alias.txt index fc36fbbac..606a05ec7 100644 --- a/doc_src/alias.txt +++ b/doc_src/alias.txt @@ -3,8 +3,8 @@ \subsection alias-synopsis Synopsis \fish{synopsis} alias -alias NAME DEFINITION -alias NAME=DEFINITION +alias [OPTIONS] NAME DEFINITION +alias [OPTIONS] NAME=DEFINITION \endfish \subsection alias-description Description @@ -18,6 +18,12 @@ alias NAME=DEFINITION You cannot create an alias to a function with the same name. Note that spaces need to be escaped in the call to `alias` just like at the command line, _even inside quoted parts_. +The following options are available: + +- `-h` or `--help` displays help about using this command. + +- `-s` or `--save` Automatically save the function created by the alias into your fish configuration directory using funcsave. + \subsection alias-example Example The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 3cedfe24d..0651cc6ac 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -1,5 +1,5 @@ function alias --description 'Creates a function wrapping a command' - set -l options 'h/help' + set -l options 'h/help' 's/save' argparse -n alias --max-args=2 $options -- $argv or return @@ -69,5 +69,8 @@ function alias --description 'Creates a function wrapping a command' set -l cmd_string (string escape -- "alias $argv") set wrapped_cmd (string join ' ' -- $first_word $body | string escape) echo "function $name --wraps $wrapped_cmd --description $cmd_string; $prefix $first_word $body \$argv; end" | source + if set -q _flag_save + funcsave $name + end #echo "function $name --wraps $wrapped_cmd --description $cmd_string; $prefix $first_word $body \$argv; end" end