Merge branch 'issue_4490' (read --silent/-s)

Closes #4490
This commit is contained in:
Mahmoud Al-Qudsi 2018-03-09 12:04:21 -06:00
commit 9206734a4d
5 changed files with 18 additions and 11 deletions

View file

@ -3,11 +3,12 @@ This section is for changes merged to the `major` branch that are not also merge
## Deprecations ## Deprecations
- The `IFS` variable is deprecated and will be removed in fish 4.0 (#4156). - The `IFS` variable is deprecated and will be removed in fish 4.0 (#4156).
- The `function --on-process-exit` event will be removed in future (#4700). Use the "fish_exit" event instead. - The `function --on-process-exit` event will be removed in future (#4700). Use the `fish_exit` event instead.
## Notable non-backward compatible changes ## Notable non-backward compatible changes
- `.` command no longer exists -- use `source` (#4294). - `.` command no longer exists -- use `source` (#4294).
- `read` now requires at least one var name (#4220). - `read` now requires at least one var name (#4220).
- `read` now uses `-s` as short for `--silent` (à la `bash`); `--shell`'s abbreviation (formerly `-i`) is now `-S` instead (#4490).
- `set x[1] x[2] a b` is no longer valid syntax (#4236). - `set x[1] x[2] a b` is no longer valid syntax (#4236).
- For loop control variables are no longer local to the for block (#1935). - For loop control variables are no longer local to the for block (#1935).
- A literal `{}` now expands to itself, rather than nothing. This makes working with `find -exec` easier. (#1109, #4632) - A literal `{}` now expands to itself, rather than nothing. This makes working with `find -exec` easier. (#1109, #4632)
@ -19,7 +20,7 @@ This section is for changes merged to the `major` branch that are not also merge
- `read` has a new `--delimiter` option as a better alternative to the `IFS` variable (#4256). - `read` has a new `--delimiter` option as a better alternative to the `IFS` variable (#4256).
- `set` has a new `--append` and `--prepend` option (#1326). - `set` has a new `--append` and `--prepend` option (#1326).
- `set` has a new `--show` option to show lots of information about variables (#4265). - `set` has a new `--show` option to show lots of information about variables (#4265).
- `complete` now has a `-k` and `--keep-order` option to keep the order of the OPTION_ARGUMENTS (#361). - `complete` now has a `-k` and `--keep-order` option to keep the order of the `OPTION_ARGUMENTS` (#361).
- Local exported (`set -lx`) vars are now visible to functions (#1091). - Local exported (`set -lx`) vars are now visible to functions (#1091).
- `abbr` has been reimplemented to be faster. This means the old `fish_user_abbreviations` variable is ignored (#4048). - `abbr` has been reimplemented to be faster. This means the old `fish_user_abbreviations` variable is ignored (#4048).
- Setting variables is much faster (#4200, #4341). - Setting variables is much faster (#4200, #4341).

View file

@ -17,7 +17,7 @@ The following options are available:
- `-g` or `--global` makes the variables global. - `-g` or `--global` makes the variables global.
- `-i` or `--silent` makes the characters typed obfuscated. This is useful for reading things like passwords or other sensitive information. Note that in bash the short flag is `-s`. We can't use that due to the existing use as an alias for `--shell`. - `-s` or `--silent` masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information.
- `-l` or `--local` makes the variables local. - `-l` or `--local` makes the variables local.
@ -30,7 +30,7 @@ The following options are available:
- `-R RIGHT_PROMPT_CMD` or `--right-prompt=RIGHT_PROMPT_CMD` uses the output of the shell command `RIGHT_PROMPT_CMD` as the right prompt for the interactive mode. There is no default right prompt command. - `-R RIGHT_PROMPT_CMD` or `--right-prompt=RIGHT_PROMPT_CMD` uses the output of the shell command `RIGHT_PROMPT_CMD` as the right prompt for the interactive mode. There is no default right prompt command.
- `-s` or `--shell` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. - `-S` or `--shell` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for `--shell` was `-s`, but it has been changed for compatibility with bash's `-s` short opt for `--silent`.
- `-u` or `--unexport` prevents the variables from being exported to child processes (default behaviour). - `-u` or `--unexport` prevents the variables from being exported to child processes (default behaviour).

View file

@ -7,7 +7,8 @@ complete -c read -s U -l universal -d "Make variable scope universal, i.e. share
complete -c read -s u -l unexport -d "Do not export variable to subprocess" complete -c read -s u -l unexport -d "Do not export variable to subprocess"
complete -c read -s m -l mode-name -d "Name to load/save history under" -r -a "read fish" complete -c read -s m -l mode-name -d "Name to load/save history under" -r -a "read fish"
complete -c read -s c -l command -d "Initial contents of read buffwhen reading interactively" complete -c read -s c -l command -d "Initial contents of read buffwhen reading interactively"
complete -c read -s s -l shell -d "Use syntax highlighting, tab completions and command termination suitable for entering shellscript code" complete -c read -s S -l shell -d "Use syntax highlighting, tab completions and command termination suitable for entering shellscript code"
complete -c read -s s -l silent -d "Secure mode: mask characters at the command line (suitable for passwords)"
complete -c read -s n -l nchars -d "Read the specified number of characters" complete -c read -s n -l nchars -d "Read the specified number of characters"
complete -c read -s a -l array -d "Store the results as an array" complete -c read -s a -l array -d "Store the results as an array"
complete -c read -s R -l right-prompt -d "Set right-hand prompt command" -x complete -c read -s R -l right-prompt -d "Set right-hand prompt command" -x

View file

@ -61,7 +61,7 @@ function funced --description 'Edit function definition'
end end
set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)' set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)'
if read -p $prompt -c "$init" -s cmd if read -p $prompt -c "$init" --shell cmd
echo -n $cmd | fish_indent | read -lz cmd echo -n $cmd | fish_indent | read -lz cmd
eval "$cmd" eval "$cmd"
end end

View file

@ -62,10 +62,10 @@ static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'
{L"right-prompt", required_argument, NULL, 'R'}, {L"right-prompt", required_argument, NULL, 'R'},
{L"command", required_argument, NULL, 'c'}, {L"command", required_argument, NULL, 'c'},
{L"mode-name", required_argument, NULL, 'm'}, {L"mode-name", required_argument, NULL, 'm'},
{L"silent", no_argument, NULL, 'i'}, {L"silent", no_argument, NULL, 's'},
{L"nchars", required_argument, NULL, 'n'}, {L"nchars", required_argument, NULL, 'n'},
{L"delimiter", required_argument, NULL, 'd'}, {L"delimiter", required_argument, NULL, 'd'},
{L"shell", no_argument, NULL, 's'}, {L"shell", no_argument, NULL, 'S'},
{L"array", no_argument, NULL, 'a'}, {L"array", no_argument, NULL, 'a'},
{L"null", no_argument, NULL, 'z'}, {L"null", no_argument, NULL, 'z'},
{L"help", no_argument, NULL, 'h'}, {L"help", no_argument, NULL, 'h'},
@ -147,16 +147,21 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc
opts.delimiter = w.woptarg; opts.delimiter = w.woptarg;
break; break;
} }
case 'i': {
streams.err.append_format(_(L"%ls: usage of -i for --silent is deprecated. Please use -s or --silent instead.\n"),
cmd);
return STATUS_INVALID_ARGS;
}
case 's': { case 's': {
opts.shell = true; opts.silent = true;
break; break;
} }
case 'a': { case 'a': {
opts.array = true; opts.array = true;
break; break;
} }
case L'i': { case L'S': {
opts.silent = true; opts.shell = true;
break; break;
} }
case L'z': { case L'z': {