mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:47:44 +00:00
Shell+LibLine: Support HISTCONTROL environment variable
This is implemented in Line::Editor meaning not only the Shell will respect it, but also js, Debugger etc. Possible values are "ignorespace", "ignoredups" and "ignoreboth", as documented in Shell-vars(7), for now. The default value for the anon user (set in .shellrc) is "ignoreboth".
This commit is contained in:
parent
4a4b1b1131
commit
d412fbdcf3
3 changed files with 21 additions and 1 deletions
|
@ -3,3 +3,5 @@
|
|||
# IFS controls what $(...) (inline evaluate) would split its captured
|
||||
# string with. the default is \x0a (i.e. newline).
|
||||
IFS="\x0a"
|
||||
|
||||
export HISTCONTROL="ignoreboth"
|
||||
|
|
|
@ -17,6 +17,17 @@ The value of this variable is used to join lists or split strings into lists, it
|
|||
|
||||
2. History
|
||||
|
||||
`HISTCONTROL` (environment)
|
||||
|
||||
The value of this variable is used to determine which entries are kept in the Shell's history, both regarding the current active session and when writing the history to disk on exit.
|
||||
|
||||
- `ignorespace`: Entries starting with one or more space characters are ignored
|
||||
- `ignoredups`: Consecutive duplicate entries are ignored
|
||||
- `ignoreboth`: The behaviour of `ignorespace` and `ignoredups` is combined
|
||||
- If the variable is unset (this is the default) or has any other value than the above, no entries will be excluded from history.
|
||||
|
||||
Note: This variable is respected by every program using `Line::Editor`, e.g. [`js`(1)](../man1/js.md).
|
||||
|
||||
`HISTFILE` (environment)
|
||||
|
||||
The value of this variable is used as the Shell's history file path, both for reading history at startup and writing history on exit.
|
||||
|
|
|
@ -208,6 +208,13 @@ void Editor::add_to_history(const String& line)
|
|||
{
|
||||
if (line.is_empty())
|
||||
return;
|
||||
String histcontrol = getenv("HISTCONTROL");
|
||||
auto ignoredups = histcontrol == "ignoredups" || histcontrol == "ignoreboth";
|
||||
auto ignorespace = histcontrol == "ignorespace" || histcontrol == "ignoreboth";
|
||||
if (ignoredups && !m_history.is_empty() && line == m_history.last())
|
||||
return;
|
||||
if (ignorespace && line.starts_with(' '))
|
||||
return;
|
||||
if ((m_history.size() + 1) > m_history_capacity)
|
||||
m_history.take_first();
|
||||
m_history.append(line);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue