From 938151a834c1858ffdd6091cbcb42688a3784b6b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 26 Jun 2015 01:00:58 +0900 Subject: [PATCH] [shell] Add FZF_CTRL_T_COMMAND for CTRL-T Close #40 --- README.md | 5 +++-- shell/key-bindings.bash | 7 ++++--- shell/key-bindings.fish | 6 ++++-- shell/key-bindings.zsh | 5 +++-- test/test_go.rb | 21 +++++++++++++++++++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d460279..3dc58e5 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,9 @@ Key bindings for command line The install script will setup the following key bindings for bash, zsh, and fish. -- `CTRL-T` - Paste the selected file path(s) into the command line -- `CTRL-R` - Paste the selected command from history into the command line +- `CTRL-T` - Paste the selected files and directories onto the command line + - Set `FZF_CTRL_T_COMMAND` to override the default command +- `CTRL-R` - Paste the selected command from history onto the command line - Sort is disabled by default to respect chronological ordering - Press `CTRL-R` again to toggle sort - `ALT-C` - cd into the selected directory diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index ee79cc3..c04dc44 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -1,10 +1,11 @@ # Key bindings # ------------ __fzf_select__() { - 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- | fzf -m | while read item; do + -o -type l -print 2> /dev/null | sed 1d | cut -b3-"}" + eval "$cmd" | fzf -m | while read item; do printf '%q ' "$item" done echo @@ -24,7 +25,7 @@ __fzf_select_tmux__() { else height="-l $height" fi - tmux split-window $height "cd $(printf %q "$PWD");bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fzf_select__)\"'" + 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__() { diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index b86a4ef..c79d0fd 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -14,10 +14,12 @@ function fzf_key_bindings end function __fzf_ctrl_t - command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ + set -q FZF_CTRL_T_COMMAND; or set -l 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 (__fzfcmd) -m > $TMPDIR/fzf.result + -o -type l -print 2> /dev/null | sed 1d | cut -b3-" + eval $FZF_CTRL_T_COMMAND | eval (__fzfcmd) -m > $TMPDIR/fzf.result and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) commandline -f repaint rm -f $TMPDIR/fzf.result diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index 642a35e..735aa50 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -4,10 +4,11 @@ if [[ $- =~ i ]]; then # CTRL-T - Paste the selected file path(s) into the command line __fsel() { - 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- | $(__fzfcmd) -m | while read item; do + -o -type l -print 2> /dev/null | sed 1d | cut -b3-"}" + eval "$cmd" | $(__fzfcmd) -m | while read item; do printf '%q ' "$item" done echo diff --git a/test/test_go.rb b/test/test_go.rb index 7bef8e6..05966d4 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -148,6 +148,7 @@ class TestBase < Minitest::Test def setup ENV.delete 'FZF_DEFAULT_OPTS' + ENV.delete 'FZF_CTRL_T_COMMAND' ENV.delete 'FZF_DEFAULT_COMMAND' end @@ -651,6 +652,12 @@ module TestShell @tmux.kill end + def set_var name, val + tmux.prepare + tmux.send_keys "export #{name}='#{val}'", :Enter + tmux.prepare + end + def test_ctrl_t tmux.prepare tmux.send_keys 'C-t', pane: 0 @@ -670,6 +677,14 @@ module TestShell tmux.send_keys 'C-c', 'C-d' end + def test_ctrl_t_command + set_var "FZF_CTRL_T_COMMAND", "seq 100" + tmux.send_keys 'C-t', pane: 0 + lines = tmux.until(1) { |lines| lines.item_count == 100 } + tmux.send_keys :BTab, :BTab, :BTab, :Enter, pane: 1 + tmux.until(0) { |lines| lines[-1].include? '1 2 3' } + end + def test_alt_c tmux.prepare tmux.send_keys :Escape, :c, pane: 0 @@ -842,6 +857,12 @@ class TestFish < TestBase tmux.until { |lines| lines.empty? } end + def set_var name, val + tmux.prepare + tmux.send_keys "set -l #{name} '#{val}'", :Enter + tmux.prepare + end + def setup super @tmux = Tmux.new :fish