From db8ec59ac422b6d81c8ace0519388521f6ebdc6d Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 11:48:09 -0600 Subject: [PATCH 1/6] Change read to use -s/--silent and -S/--shell Closes #4490 --- src/builtin_read.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 13d85fad1..3d80da1a0 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -62,10 +62,10 @@ static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x' {L"right-prompt", required_argument, NULL, 'R'}, {L"command", required_argument, NULL, 'c'}, {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"delimiter", required_argument, NULL, 'd'}, - {L"shell", no_argument, NULL, 's'}, + {L"shell", no_argument, NULL, 'S'}, {L"array", no_argument, NULL, 'a'}, {L"null", no_argument, NULL, 'z'}, {L"help", no_argument, NULL, 'h'}, @@ -148,15 +148,15 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc break; } case 's': { - opts.shell = true; + opts.silent = true; break; } case 'a': { opts.array = true; break; } - case L'i': { - opts.silent = true; + case L'S': { + opts.shell = true; break; } case L'z': { From 86362e72fe1707ff5dca357c5bb6d85358fa5a52 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 11:48:51 -0600 Subject: [PATCH 2/6] Emit deprecation error when read -i is used for --silent --- src/builtin_read.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 3d80da1a0..9b7586f2a 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -147,6 +147,11 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc opts.delimiter = w.woptarg; 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': { opts.silent = true; break; From f8ec1e4a7b07c514894c9b5b1311243e03a84554 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 11:53:19 -0600 Subject: [PATCH 3/6] Document `read -s/--silent and -S/--shell change --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c03bb6e..bd3a47a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,12 @@ This section is for changes merged to the `major` branch that are not also merge ## Deprecations - 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 - `.` command no longer exists -- use `source` (#4294). - `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). - 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) @@ -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). - `set` has a new `--append` and `--prepend` option (#1326). - `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). - `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). From 2a266c4d4869cd1bd69a2539b669c037ef49cb78 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 11:55:12 -0600 Subject: [PATCH 4/6] Update fish's only usage of `read -s` to use `read --shell` instead --- share/functions/funced.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/functions/funced.fish b/share/functions/funced.fish index 706e0ee16..401b85276 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -61,7 +61,7 @@ function funced --description 'Edit function definition' end 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 eval "$cmd" end From eaa5958b7796131b612a228cf0ec1bfbc2f2229f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 11:59:50 -0600 Subject: [PATCH 5/6] Update completions for read builtin Change short option for `--shell` to `-S` per #4490 and add description for -s/--silent --- share/completions/read.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/completions/read.fish b/share/completions/read.fish index 82ef1bbf6..f8d2e0513 100644 --- a/share/completions/read.fish +++ b/share/completions/read.fish @@ -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 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 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 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 From 8b9a13f6ca9b50c31e383fee08fb161534042181 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 12:03:45 -0600 Subject: [PATCH 6/6] Update read builtin documentation to reflect --shell and --silent opt changes --- doc_src/read.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc_src/read.txt b/doc_src/read.txt index 96fee08a2..3d01333ca 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -17,7 +17,7 @@ The following options are available: - `-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. @@ -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. -- `-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).