Add alias -s/--save, which saves the alias.

Also updates the `alias` documentation to mention the `-h`/`--help` option,
which was previously undocumented.
This commit is contained in:
Thom Chiovoloni 2018-04-06 10:27:40 -07:00 committed by Fabian Homborg
parent 6c0f31d622
commit 25169a44ed
3 changed files with 13 additions and 3 deletions

View file

@ -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). - `functions --handlers` can be used to show event handlers (#4694).
- Variables set in `if` and `while` conditions are available outside the block (#4820). - 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). - 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 ## Other significant changes
- Command substitution output is now limited to 10 MB by default (#3822). - Command substitution output is now limited to 10 MB by default (#3822).

View file

@ -3,8 +3,8 @@
\subsection alias-synopsis Synopsis \subsection alias-synopsis Synopsis
\fish{synopsis} \fish{synopsis}
alias alias
alias NAME DEFINITION alias [OPTIONS] NAME DEFINITION
alias NAME=DEFINITION alias [OPTIONS] NAME=DEFINITION
\endfish \endfish
\subsection alias-description Description \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_. 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 <a href='#funcsave'>funcsave</a>.
\subsection alias-example Example \subsection alias-example Example
The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. The following code will create `rmi`, which runs `rm` with additional arguments on every invocation.

View file

@ -1,5 +1,5 @@
function alias --description 'Creates a function wrapping a command' 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 argparse -n alias --max-args=2 $options -- $argv
or return or return
@ -69,5 +69,8 @@ function alias --description 'Creates a function wrapping a command'
set -l cmd_string (string escape -- "alias $argv") set -l cmd_string (string escape -- "alias $argv")
set wrapped_cmd (string join ' ' -- $first_word $body | string escape) 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 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" #echo "function $name --wraps $wrapped_cmd --description $cmd_string; $prefix $first_word $body \$argv; end"
end end