about summary refs log tree commit diff stats
path: root/bash/history.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/history.bash')
-rw-r--r--bash/history.bash38
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
35PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-:}" 35PROMPT_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
39histfunc() { # 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
54funcsave() { # 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
65if [[ "\${BASH_SOURCE[0]}" == "\$0" ]]; then
66 [[ "\$DEBUG" ]] && set -x
67 "$1" "\$@"
68fi
69EOF
70 chmod +x "$2"
71}