# Bash history settings # I don't export any variables in this file because history settings # really only apply in an interactive session. # XDG compliance HISTFILE="$XDG_DATA_HOME/bash/history" mkdir -p "$XDG_DATA_HOME/bash" # Don't truncate history HISTFILESIZE=-1 # numeric values less than zero => don't truncate HISTSIZE=100000 # ideally, I wouldn't truncate at all, but after a while shell # startup might be affected. # Append the history to HISTFILE. shopt -s histappend # History editing with readline shopt -s histreedit # allow re-editing of a failed history substitution shopt -s histverify # verify a history expansion before running it # Save command invocation time to HISTFILE, and format it thusly HISTTIMEFORMAT="%F %T " # Erase all duplicates before saving the current line HISTCONTROL=erasedups # Don't save some commands to history # "'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of # '&' is identical to 'ignoredups', and a pattern of '[ ]*' is # identical to 'ignorespace'." -- info (bash)Bash Variables HISTIGNORE='&:[ ]*' # Other commands to ignore HISTIGNORE="$HISTIGNORE:ls:exit:cd:p" # Automatically append to HISTFILE on every command PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-:}" ## Make a new function from a history item: WIP # In particular, the arguments of this function could be better imo histfunc() { # histfunc NAME QUERY local name="$1" local query="$2" local -a cands while read -r cmd; do cands=( "${cands[@]}" "$cmd" ) done < <(grep -E "$query" "$HISTFILE" | sort | uniq) if (( "${#cands[@]}" == 1 )); then funcbody="${cands[0]}" else select funcbody in "${cands[@]}"; do break; done fi eval "$name() { $funcbody; }" } funcsave() { # funcsave FUNC FILENAME (( $# == 2 )) || { echo "Wrong number of arguments (need 2)" >&2 return 1 } cat < "$2" #!/usr/bin/env bash # saved with 'funcsave' $(type "$1" | sed 1d) if [[ "\${BASH_SOURCE[0]}" == "\$0" ]]; then [[ "\$DEBUG" ]] && set -x "$1" "\$@" fi EOF chmod +x "$2" }