forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Bash-it#1764 from cornfeedhobo/history-plugins
refactor all history modifications into discrete plugins
- Loading branch information
Showing
5 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'search history using the prefix already entered' | ||
|
||
# enter a few characters and press UpArrow/DownArrow | ||
# to search backwards/forwards through the history | ||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then | ||
bind '"\e[A":history-search-backward' | ||
bind '"\e[B":history-search-forward' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'search history using the substring already entered' | ||
|
||
# enter a few characters and press UpArrow/DownArrow | ||
# to search backwards/forwards through the history | ||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then | ||
bind '"\e[A":history-substring-search-backward' | ||
bind '"\e[B":history-substring-search-forward' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
# shellcheck shell=bash | ||
cite about-plugin | ||
about-plugin 'history manipulation' | ||
# enter a few characters and press UpArrow/DownArrow | ||
# to search backwards/forwards through the history | ||
if [[ ${SHELLOPTS} =~ (vi|emacs) ]] | ||
then | ||
bind '"[A":history-search-backward' | ||
bind '"[B":history-search-forward' | ||
fi | ||
about-plugin 'improve history handling with sane defaults' | ||
|
||
# append to bash_history if Terminal.app quits | ||
shopt -s histappend | ||
|
||
# erase duplicates; alternative option: export HISTCONTROL=ignoredups | ||
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} | ||
|
||
# resize history to 100x the default (500) | ||
export HISTSIZE=${HISTSIZE:-50000} | ||
|
||
top-history() { | ||
about 'print the name and count of the most commonly run tools' | ||
|
||
if [[ -n $HISTTIMEFORMAT ]]; then | ||
# To parse history we need a predictable format, which HISTTIMEFORMAT | ||
# gets in the way of. So we unset it and set a trap to guarantee the | ||
# user's environment returns to normal even if the pipeline below fails. | ||
# shellcheck disable=SC2064 | ||
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN | ||
unset HISTTIMEFORMAT | ||
fi | ||
|
||
history \ | ||
| awk '{ | ||
a[$2]++ | ||
}END{ | ||
for(i in a) | ||
printf("%s\t%s\n", a[i], i) | ||
}' \ | ||
| sort --reverse --numeric-sort \ | ||
| head \ | ||
| column \ | ||
--table \ | ||
--table-columns 'Command Count,Command Name' \ | ||
--output-separator ' | ' | ||
} |