diff options
author | Case Duckworth | 2023-01-30 12:24:02 -0600 |
---|---|---|
committer | Case Duckworth | 2023-01-30 12:24:02 -0600 |
commit | ff41d9acc805099f27f1cf060ca9db72d2fdb74f (patch) | |
tree | f3831f08979bd1395fc4c737ade866e13700df3b /bash/history.bash | |
parent | meh. (diff) | |
download | etc-ff41d9acc805099f27f1cf060ca9db72d2fdb74f.tar.gz etc-ff41d9acc805099f27f1cf060ca9db72d2fdb74f.zip |
Bash!
Diffstat (limited to 'bash/history.bash')
-rw-r--r-- | bash/history.bash | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/bash/history.bash b/bash/history.bash index 95edf9d..d2bdceb 100644 --- a/bash/history.bash +++ b/bash/history.bash | |||
@@ -1,5 +1,5 @@ | |||
1 | # Bash history settings | 1 | # Bash history settings |
2 | # I don't export any variables in this file because history settings | 2 | # I don't export any variables in this file because history settings |
3 | # really only apply in an interactive session. | 3 | # really only apply in an interactive session. |
4 | 4 | ||
5 | # XDG compliance | 5 | # XDG compliance |
@@ -33,3 +33,39 @@ HISTIGNORE="$HISTIGNORE:ls:exit:cd" | |||
33 | 33 | ||
34 | # Automatically append to HISTFILE on every command | 34 | # Automatically append to HISTFILE on every command |
35 | PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-:}" | 35 | PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-:}" |
36 | |||
37 | ## Make a new function from a history item: WIP | ||
38 | # In particular, the arguments of this function could be better imo | ||
39 | histfunc() { # histfunc NAME QUERY | ||
40 | local name="$1" | ||
41 | local query="$2" | ||
42 | local -a cands | ||
43 | while read -r cmd; do | ||
44 | cands=( "${cands[@]}" "$cmd" ) | ||
45 | done < <(grep -E "$query" "$HISTFILE" | sort | uniq) | ||
46 | if (( "${#cands[@]}" == 1 )); then | ||
47 | funcbody="${cands[0]}" | ||
48 | else | ||
49 | select funcbody in "${cands[@]}"; do break; done | ||
50 | fi | ||
51 | eval "$name() { $funcbody; }" | ||
52 | } | ||
53 | |||
54 | funcsave() { # funcsave FUNC FILENAME | ||
55 | (( $# == 2 )) || { | ||
56 | echo "Wrong number of arguments (need 2)" >&2 | ||
57 | return 1 | ||
58 | } | ||
59 | cat <<EOF > "$2" | ||
60 | #!/usr/bin/env bash | ||
61 | # saved with 'funcsave' | ||
62 | |||
63 | $(type "$1" | sed 1d) | ||
64 | |||
65 | if [[ "\${BASH_SOURCE[0]}" == "\$0" ]]; then | ||
66 | [[ "\$DEBUG" ]] && set -x | ||
67 | "$1" "\$@" | ||
68 | fi | ||
69 | EOF | ||
70 | chmod +x "$2" | ||
71 | } | ||