Fix broken FZF_TMUX switch and update test cases (#203)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 318edc8 · Browse files · 3 files·+26 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+26 added−12 removed
- other:+26 added−12 removed
Provenance
- Commit
06b4f75- Tree
881781e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
318edc8
3 files changed+26 added−12 removed
modified:shell/key-bindings.bash+6 added-2 removed
10 unmodified lines1112131415161718192021226 unmodified lines29303132293334353633373839404142 unmodified lines10 unmodified lines}
if [[ $- =~ i ]]; then
__fzfcmd() { [ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"}
__fzf_select_tmux__() { local height height=${FZF_TMUX_HEIGHT:-40%} if [[ $height =~ %$ ]]; then6 unmodified lines
__fzf_cd__() { local dir dir=$(command find -L ${1:-.} \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m) && printf 'cd %q' "$dir" -o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m) && printf 'cd %q' "$dir"}
__fzf_history__() { HISTTIMEFORMAT= history | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ *[0-9]* *//" HISTTIMEFORMAT= history | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ *[0-9]* *//"}
__use_tmux=0[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=142 unmodified linesmodified:shell/key-bindings.fish+13 added-7 removed
24 unmodified lines25 end26 end27 28 function __fzf_ctrl_t29- __fzf_list | fzf-tmux (__fzf_tmux_height) -m > $TMPDIR/fzf.result29+ __fzf_list | eval (__fzfcmd) -m > $TMPDIR/fzf.result30 and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)31 commandline -f repaint32 rm -f $TMPDIR/fzf.result33 end34 35 function __fzf_ctrl_r36- history | fzf-tmux (__fzf_tmux_height) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result36+ history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result37 and commandline (cat $TMPDIR/fzf.result)38 commandline -f repaint39 rm -f $TMPDIR/fzf.result40 end41 42 function __fzf_alt_c43 # Fish hangs if the command before pipe redirects (2> /dev/null)44- __fzf_list_dir | fzf-tmux (__fzf_tmux_height) +m > $TMPDIR/fzf.result44+ __fzf_list_dir | eval (__fzfcmd) +m > $TMPDIR/fzf.result45 [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]46 and cd (cat $TMPDIR/fzf.result)47 commandline -f repaint48 rm -f $TMPDIR/fzf.result49 end50 51- function __fzf_tmux_height52- if set -q FZF_TMUX_HEIGHT53- echo "-d$FZF_TMUX_HEIGHT"51+ function __fzfcmd52+ set -q FZF_TMUX; or set FZF_TMUX 153+54+ if [ $FZF_TMUX -eq 1 ]55+ if set -q FZF_TMUX_HEIGHT56+ echo "fzf-tmux -d$FZF_TMUX_HEIGHT"57+ else58+ echo "fzf-tmux -d40%"59+ end60 else55- echo "-d40%"61+ echo "fzf"62 end63 end64 65 bind \ct '__fzf_ctrl_t'4 unmodified linesmodified:shell/key-bindings.zsh+7 added-3 removed
3 unmodified lines45678891011121314151617181920214 unmodified lines26272829263031323334353637383539404142437 unmodified lines3 unmodified lines__fsel() { command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ -o -type f -print \ -o -type d -print \ -o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} -m | while read item; do -o -type l -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) -m | while read item; do printf '%q ' "$item" done echo}
__fzfcmd() { [ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"}
if [[ $- =~ i ]]; then
fzf-file-widget() { LBUFFER="${LBUFFER}$(__fsel)"4 unmodified lines
# ALT-C - cd into the selected directoryfzf-cd-widget() { cd "${$(command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m):-.}" -o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m):-.}" zle reset-prompt}zle -N fzf-cd-widgetbindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command linefzf-history-widget() { local selected if selected=$(fc -l 1 | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then if selected=$(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g') LBUFFER=!$num zle expand-history fi7 unmodified lines