diff --git a/README.md b/README.md index a642da5..4477464 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)