From 3130ff5b87d129b47c76ab7924d83cdb11f57f23 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Fri, 20 Sep 2019 14:31:53 -0400 Subject: [PATCH] fzf --- zsh/funcs/fzf.funcs | 23 +++++++++++++++++++++++ zsh/zshrc | 11 ++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 zsh/funcs/fzf.funcs diff --git a/zsh/funcs/fzf.funcs b/zsh/funcs/fzf.funcs new file mode 100644 index 0000000..7944d7b --- /dev/null +++ b/zsh/funcs/fzf.funcs @@ -0,0 +1,23 @@ +# from the fzf examples wiki +bind '"\C-r": "\C-x1\e^\er"' +bind -x '"\C-x1": __fzf_history'; + +__fzf_history () +{ +__ehc $(history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "!$1"') +} + +__ehc() +{ +if + [[ -n $1 ]] +then + bind '"\er": redraw-current-line' + bind '"\e^": magic-space' + READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${1}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}} + READLINE_POINT=$(( READLINE_POINT + ${#1} )) +else + bind '"\er":' + bind '"\e^":' +fi +} diff --git a/zsh/zshrc b/zsh/zshrc index 9cfee68..9cc1aed 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -43,7 +43,6 @@ source $HOME/.antigen/antigen.zsh antigen use oh-my-zsh antigen bundle git -antigen bundle command-not-found antigen bundle vi-mode antigen bundle zsh-users/zsh-syntax-highlighting antigen bundle zsh-users/zsh-completions @@ -155,6 +154,16 @@ else touch $HOME/.zshsrc fi +function fzf_hist() { + local sed_cmd + if [[ $(uname -s) == "Darwin" ]]; then + sed_cmd='sed -E' + else + sed_cmd='sed -r' + fi + print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | $($sed_cmd 's/ *[0-9]*\*? *//') | ${sed_cmd} 's/\\/\\\\/g') +} + export PATH="$PATH:$HOME/.anyenv/bin" eval "$(anyenv init -)" export PATH="$(yarn global bin):$PATH"