[shell] Add FZF_ALT_C_COMMAND for ALT-C (#408)
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 15659ac · Browse files · 4 files·+29 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+29 added−9 removed
- tests:+16 added−0 removed
- other:+13 added−9 removed
Provenance
- Commit
e99731e- Tree
91705da- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
15659ac
4 files changed+29 added−9 removed
modified:shell/key-bindings.bash+5 added-4 removed
12344567819 unmodified lines28293031323334323334353637383958 unmodified lines# Key bindings# ------------__fzf_select__() { local cmd="${FZF_CTRL_T_COMMAND:-"command \\find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \ local cmd="${FZF_CTRL_T_COMMAND:-"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-"}" eval "$cmd" | fzf -m | while read item; do19 unmodified lines tmux split-window $height "cd $(printf %q "$PWD"); FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fzf_select__)\"'"}
__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- | $(__fzfcmd) +m) && printf 'cd %q' "$dir" local cmd dir cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3-"}" dir=$(eval "$cmd" | $(__fzfcmd) +m) && printf 'cd %q' "$dir"}
__fzf_history__() ( local line58 unmodified linesmodified:shell/key-bindings.fish+4 added-2 removed
31 unmodified lines32 rm -f $TMPDIR/fzf.result33 end34 35 function __fzf_alt_c36+ set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "37+ command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \38+ -o -type d -print 2> /dev/null | sed 1d | cut -b3-"39 # Fish hangs if the command before pipe redirects (2> /dev/null)37- command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) \38- -prune -o -type d -print 2> /dev/null | sed 1d | cut -b3- | eval (__fzfcmd) +m > $TMPDIR/fzf.result40+ eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m > $TMPDIR/fzf.result"41 [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]42 and cd (cat $TMPDIR/fzf.result)43 commandline -f repaint44 rm -f $TMPDIR/fzf.result27 unmodified linesmodified:shell/key-bindings.zsh+4 added-3 removed
2 unmodified lines34567789101114 unmodified lines2627282930313031323334353618 unmodified lines2 unmodified linesif [[ $- == *i* ]]; then
# CTRL-T - Paste the selected file path(s) into the command line__fsel() { local cmd="${FZF_CTRL_T_COMMAND:-"command \\find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \ local cmd="${FZF_CTRL_T_COMMAND:-"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-"}" eval "$cmd" | $(__fzfcmd) -m | while read item; do14 unmodified linesbindkey '^T' fzf-file-widget
# 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- | $(__fzfcmd) +m):-.}" local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3-"}" cd "${$(eval "$cmd" | $(__fzfcmd) +m):-.}" zle reset-prompt}zle -N fzf-cd-widgetbindkey '\ec' fzf-cd-widget18 unmodified linesmodified:test/test_go.rb+16 added
979 unmodified lines980 tmux.send_keys :pwd, :Enter981 tmux.until { |lines| lines[-1].end_with?(expected) }982 end983 984+ def test_alt_c_command985+ set_var 'FZF_ALT_C_COMMAND', 'echo /tmp'986+987+ tmux.prepare988+ tmux.send_keys 'cd /', :Enter989+990+ tmux.prepare991+ tmux.send_keys :Escape, :c, pane: 0992+ lines = tmux.until(1) { |lines| lines.item_count == 1 }993+ tmux.send_keys :Enter, pane: 1994+995+ tmux.prepare996+ tmux.send_keys :pwd, :Enter997+ tmux.until { |lines| lines[-1].end_with? '/tmp' }998+ end999+1000 def test_ctrl_r1001 tmux.prepare1002 tmux.send_keys 'echo 1st', :Enter; tmux.prepare1003 tmux.send_keys 'echo 2nd', :Enter; tmux.prepare171 unmodified lines