summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-05-18 11:01:30 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-05-18 11:01:30 +0900
commit05da892cd2ada76400a719ac8ed95d357871f759 (patch)
treec264ee4ea4cb09772abf227c45542ac4d7e88c38 /README.md
parentf6b1a6278f7cee8d74ba198ba937cc787143dcfc (diff)
On writing fzf-tmux combo
Diffstat (limited to 'README.md')
-rw-r--r--README.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/README.md b/README.md
index a642da58..4477464b 100644
--- a/README.md
+++ b/README.md
@@ -487,6 +487,39 @@ fzf() {
}
```
+### Using fzf with tmux splits
+
+It isn't too hard to write your own fzf-tmux combo like the default
+CTRL-T key binding. (Or is it?)
+
+```sh
+# This is a helper function that splits the current pane to start the given
+# command ($1) and sends its output back to the original pane with any number of
+# optional keys (shift; $*).
+fzf_tmux_helper() {
+ [ -n "$TMUX_PANE" ] || return
+ local cmd=$1
+ shift
+ tmux split-window -p 40 \
+ "bash -c \"\$(tmux send-keys -t $TMUX_PANE \"\$(source ~/.fzf.bash; $cmd)\" $*)\""
+}
+
+# This is the function we are going to run in the split pane.
+# - "find" to list the directories
+# - "sed" will escape spaces in the paths.
+# - "paste" will join the selected paths into a single line
+fzf_tmux_dir() {
+ fzf_tmux_helper \
+ 'find * -path "*/\.*" -prune -o -type d -print 2> /dev/null |
+ fzf --multi |
+ sed "s/ /\\\\ /g" |
+ paste -sd" " -' Space
+}
+
+# Bind CTRL-X-CTRL-D to fzf_tmux_dir
+bind '"\C-x\C-d": "$(fzf_tmux_dir)\e\C-e"'
+```
+
### Fish shell
It's [a known bug of fish](https://github.com/fish-shell/fish-shell/issues/1362)