summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-04-22 22:20:15 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-04-22 22:20:15 +0200
commit817743df402d5a610da7a23002245075a701a123 (patch)
treec54f0d1f57575af2e911c6600256ff826f87329f
parent858074705893f1fe0a00e7c6c453f42b22a8ced1 (diff)
downloaddotfiles-817743df402d5a610da7a23002245075a701a123.tar.gz
dotfiles-817743df402d5a610da7a23002245075a701a123.tar.xz
zshrc: Add fzf support for history
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--.zshrc43
1 files changed, 39 insertions, 4 deletions
diff --git a/.zshrc b/.zshrc
index c7dd720..48c45ba 100644
--- a/.zshrc
+++ b/.zshrc
@@ -194,6 +194,36 @@ globalias() {
zle -N globalias
bindkey ",," globalias
+# Source: https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh
+__fzf_use_tmux__() {
+ [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
+}
+
+__fzfcmd() {
+ __fzf_use_tmux__ &&
+ echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-95%}" || echo "fzf"
+}
+
+# CTRL-R - Paste the selected command from history into the command line
+# Changed to work with my personal history fetcher
+fzf-history-widget() {
+ local selected num
+ setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
+ selected=( $(cat-history-notime |
+ FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-95%} $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
+ local ret=$?
+ if [ -n "$selected" ]; then
+ zle kill-buffer
+ BUFFER="$selected"
+ fi
+ zle redisplay
+ typeset -f zle-line-init >/dev/null && zle zle-line-init
+ return $ret
+}
+zle -N fzf-history-widget
+bindkey '^R' fzf-history-widget
+
+
# }}}
# Variables {{{
#export CDPATH=.:$HOME
@@ -358,12 +388,17 @@ cget() {
curl -fJOL --compressed "$@"
}
-hgrep() {
- mpgrep <$HISTFILE "$@" | less
+cat-history() {
+ local histfiles=($(ls -t1 "$HISTORYDIRECTORY"/*))
+ cat "${histfiles[@]}"
}
-hless() {
- less $HISTFILE
+cat-history-notime() {
+ cat-history "$@" | sed 's/^: [0-9]\+:0;//'
+}
+
+hgrep() {
+ cat-history | mpgrep "$@" | less
}
# }}}