From ad746c2032c713fd6c57bcc8e601ab43704e1fa9 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 25 Jun 2019 10:05:15 +0200 Subject: zshrc: Add fzf file selection Signed-off-by: Florian Pritz --- .zshrc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.zshrc b/.zshrc index 1626f3c..358e8ae 100644 --- a/.zshrc +++ b/.zshrc @@ -209,6 +209,8 @@ globalias() { zle -N globalias bindkey ",," globalias +FZF_TMUX_HEIGHT='95%' + # 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 ] @@ -239,6 +241,30 @@ zle -N fzf-history-widget bindkey '^R' fzf-history-widget +__fsel() { + local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ + -o -type f -print \ + -o -type d -print \ + -o -type l -print 2> /dev/null | cut -b3-"}" + setopt localoptions pipefail 2> /dev/null + eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do + echo -n "${(q)item} " + done + local ret=$? + echo + return $ret +} + +fzf-file-widget() { + LBUFFER="${LBUFFER}$(__fsel)" + local ret=$? + zle reset-prompt + return $ret +} + +zle -N fzf-file-widget +bindkey '^T' fzf-file-widget + # }}} # Variables {{{ #export CDPATH=.:$HOME -- cgit v1.2.3-24-g4f1b