Skip to content

WIP: Allow user to prevent commands from being saved in history

Michael Aaron Murphy requested to merge BafDyce:histignore into master

Created by: BafDyce

Commands that should NOT be saved in the history can be defined via the HISTORY_IGNORE environment variable (array). Currently, the following options are supported:

  • "all": No commands will be saved until this option is removed again
  • "whitespace": ignores commands with a leading whitespace character
  • "no_such_command": ignores commands with exit status NO_SUCH_COMMAND
  • "regex:xxx": where xxx is a regex (https://doc.rust-lang.org/regex), ignores all commands that match this regex

Examples:

# echo @HISTORY_IGNORE

# let HISTORY_IGNORE = [ all ] # saved
# let HISTORY_IGNORE = [ whitespace ] # saved
#  true # ignored
#  let HISTORY_IGNORE = [  ] # saved
#  let HISTORY_IGNORE = [ whitespace ] # ignored
# history
echo @HISTORY_IGNORE
let HISTORY_IGNORE = [ all ] # saved
let HISTORY_IGNORE = [ whitespace ] # saved
 let HISTORY_IGNORE = [  ] # saved


# let HISTORY_IGNORE = [ no_such_command ]
# true # saved
#  true # saved
# false # saved
# trulse # ignored


# let HISTORY_IGNORE = [ 'regex:.*' ] # behaves like 'all'
# true # ignored
#  true # ignored
# false # ignored
# trulse # ignored

Solution: I implemented it in a way that is open for future extensions, unlike bashs implementation ;)

Drawbacks We need to keep the compiled regexes in a vector, so we have a small heap-usage there. However, currently there is nothing we can do about that.

TODOs:

  • unit & integration tests

Fixes: #503 (closed) #502 (closed) (partly, see https://github.com/redox-os/ion/issues/503#issuecomment-323079748)

State: WIP

Other: Also open to discussion if you think I could implement something differently, etc.

Merge request reports