From 472e186c2b84fce115500e357801e170de93736d Mon Sep 17 00:00:00 2001 From: David Adam Date: Sun, 24 Sep 2017 14:07:45 +0800 Subject: [PATCH] Rename FISH_HISTORY to fish_history Work on #4414. --- CHANGELOG.md | 4 ++-- doc_src/history.txt | 4 ++-- doc_src/index.hdr.in | 7 +++++-- doc_src/read.txt | 2 +- src/builtin_read.cpp | 2 +- src/env.cpp | 2 +- src/history.cpp | 4 ++-- tests/histfile.expect | 14 +++++++------- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01aca162a..639035894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,8 +34,8 @@ This section is for changes merged to the `major` branch that are not also merge - Invalid array indexes are now silently ignored (#826, #4127). - `string escape` has a new `--style=xxx` flag where `xxx` can be `script`, `var`, or `url` (#4150). - `string unescape` has been implemented to reverse the effects of `string escape` (#3543). -- The history file can now be specified by setting the `FISH_HISTORY` variable (#102). -- Read history is now controlled by the `FISH_HISTORY` variable rather than the `--mode-name` flag (#1504). +- The history file can now be specified by setting the `fish_history` variable (#102). +- Read history is now controlled by the `fish_history` variable rather than the `--mode-name` flag (#1504). - Implement a `cdh` (change directory using recent history) command to provide a more friendly alternative to prevd/nextd and pushd/popd (#2847). - `command` now supports a `-a` flag to report all directories with the command. This means that `which -a $cmd` is no longer necessary (#2778). - `--init-command`/`-C` added to the command line switches, to allow execution of commands before starting the interactive shell (#4164). diff --git a/doc_src/history.txt b/doc_src/history.txt index 2f6fbac0a..62c096b37 100644 --- a/doc_src/history.txt +++ b/doc_src/history.txt @@ -66,9 +66,9 @@ history delete --prefix "foo" By default interactive commands are logged to `$XDG_DATA_HOME/fish/fish_history` (typically `~/.local/share/fish/fish_history`). -You can set the `FISH_HISTORY` variable to another name for the current shell session. The default value (when the variable is unset) is `fish` which corresponds to `$XDG_DATA_HOME/fish/fish_history`. If you set it to e.g. `fun`, the history would be written to `$XDG_DATA_HOME/fish/fun_history`. An empty string means history will not be stored at all. This is similar to the private session features in web browsers. +You can set the `fish_history` variable to another name for the current shell session. The default value (when the variable is unset) is `fish` which corresponds to `$XDG_DATA_HOME/fish/fish_history`. If you set it to e.g. `fun`, the history would be written to `$XDG_DATA_HOME/fish/fun_history`. An empty string means history will not be stored at all. This is similar to the private session features in web browsers. -You can change `FISH_HISTORY` at any time (by using `set -x FISH_HISTORY "session_name"`) and it will take effect right away. If you set it to `"default"`, it will use the default session name (which is `"fish"`). +You can change `fish_history` at any time (by using `set -x fish_history "session_name"`) and it will take effect right away. If you set it to `"default"`, it will use the default session name (which is `"fish"`). Other shells such as bash and zsh use a variable named `HISTFILE` for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than `fish` or `default` it will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation. diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 19b73dcd7..73993deff 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -852,7 +852,7 @@ The user can change the settings of `fish` by changing the values of certain var - `history`, an array containing the last commands that were entered. -- `FISH_HISTORY`: Name of the history session. It defaults to `fish` (which typically means the history will be saved in `~/.local/share/fish/fish_history`). This variable can be changed by the user. It does not have to be an environment variable. You can change it at will within an interactive fish session to change where subsequent commands are logged. +- `fish_history`: Name of the history session. It defaults to `fish` (which typically means the history will be saved in `~/.local/share/fish/fish_history`). This variable can be changed by the user. It does not have to be an environment variable. You can change it at will within an interactive fish session to change where subsequent commands are logged. - `HOME`, the user's home directory. This variable can be changed by the user. @@ -1137,7 +1137,10 @@ History searches can be aborted by pressing the escape key. Prefixing the commandline with a space will prevent the entire line from being stored in the history. -The command history is stored in the file `~/.local/share/fish/fish_history` (or `$XDG_DATA_HOME/fish/fish_history` if that variable is set) by default. However, you can set the `FISH_HISTORY` environment variable to change the name of the history session (resulting in a `_history` file); both before starting the shell and while the shell is running. +The command history is stored in the file `~/.local/share/fish/fish_history` (or +`$XDG_DATA_HOME/fish/fish_history` if that variable is set) by default. However, you can set the +`fish_history` environment variable to change the name of the history session (resulting in a +`_history` file); both before starting the shell and while the shell is running. Examples: diff --git a/doc_src/read.txt b/doc_src/read.txt index 64a0d01c8..636183363 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -62,7 +62,7 @@ is set to empty and the exit status is set to 122. This limit can be altered wit \subsection read-history Using another read history file -The `read` command supported the `-m` and `--mode-name` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the `FISH_HISTORY` variable to specify a history session ID. That will affect both the `read` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. +The `read` command supported the `-m` and `--mode-name` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the `fish_history` variable to specify a history session ID. That will affect both the `read` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. \subsection read-example Example diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 84d6c4d56..6f75537d9 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -115,7 +115,7 @@ static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high nc } case L'm': { streams.err.append_format(_(L"%ls: flags '--mode-name' / '-m' are now ignored. " - L"Set FISH_HISTORY instead.\n"), + L"Set fish_history instead.\n"), cmd); break; } diff --git a/src/env.cpp b/src/env.cpp index a854621f4..c37c0134c 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -847,7 +847,7 @@ static void setup_var_dispatch_table() { var_dispatch_table.emplace(L"LINES", handle_term_size_change); var_dispatch_table.emplace(L"COLUMNS", handle_term_size_change); var_dispatch_table.emplace(L"FISH_READ_BYTE_LIMIT", handle_read_limit_change); - var_dispatch_table.emplace(L"FISH_HISTORY", handle_fish_history_change); + var_dispatch_table.emplace(L"fish_history", handle_fish_history_change); var_dispatch_table.emplace(L"TZ", handle_tz_change); } diff --git a/src/history.cpp b/src/history.cpp index 255de7eb2..5ee6c9ff3 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -52,7 +52,7 @@ // // Newlines are replaced by \n. Backslashes are replaced by \\. -// This is the history session ID we use by default if the user has not set env var FISH_HISTORY. +// This is the history session ID we use by default if the user has not set env var fish_history. #define DFLT_FISH_HISTORY_SESSION_ID L"fish" // When we rewrite the history, the number of items we keep. @@ -1831,7 +1831,7 @@ void history_sanity_check() { wcstring history_session_id() { wcstring result = DFLT_FISH_HISTORY_SESSION_ID; - const auto var = env_get(L"FISH_HISTORY"); + const auto var = env_get(L"fish_history"); if (var) { wcstring session_id = var->as_string(); if (session_id.empty()) { diff --git a/tests/histfile.expect b/tests/histfile.expect index d023d8e1d..21082c811 100644 --- a/tests/histfile.expect +++ b/tests/histfile.expect @@ -1,12 +1,12 @@ # vim: set filetype=expect: # We're going to use three history files, including the default, to verify -# that the FISH_HISTORY variable works as expected. +# that the fish_history variable works as expected. set default_histfile "../test/data/fish/fish_history" set my_histfile "../test/data/fish/my_history" set env_histfile "../test/data/fish/env_history" # ============= -# Verify that if we spawn fish with no FISH_HISTORY env var it uses the +# Verify that if we spawn fish with no fish_history env var it uses the # default file. # ============= set fish_pid [spawn $fish] @@ -34,7 +34,7 @@ expect_prompt -re "\r\n$hist_line\r\n" { # history file is not written to. set cmd2 "echo $fish_pid my histfile" set hist_line "- cmd: $cmd2" -send "set FISH_HISTORY my\r" +send "set fish_history my\r" expect_prompt send "$cmd2\r" expect_prompt @@ -62,7 +62,7 @@ expect_prompt -re "\r\n$hist_line\r\n" { # Switch back to the default history file. set cmd3 "echo $fish_pid default histfile again" set hist_line "- cmd: $cmd3" -send "set FISH_HISTORY default\r" +send "set fish_history default\r" expect_prompt send "$cmd3\r" expect_prompt @@ -94,15 +94,15 @@ expect_prompt -re "\r\n$hist_line\r\n" { send "exit\r" close $spawn_id -# Set the FISH_HISTORY env var. -set ::env(FISH_HISTORY) env +# Set the fish_history env var. +set ::env(fish_history) env # Spawn a new shell. set prompt_counter 1 set fish_pid [spawn $fish] expect_prompt -# Verify that the new fish shell is using the FISH_HISTORY value for history. +# Verify that the new fish shell is using the fish_history value for history. set cmd4 "echo $fish_pid env histfile" set hist_line "- cmd: $cmd4" send "$cmd4\r"