From 229601317433ee3ca94abdd09232a4b3db2d812c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 13 Mar 2014 14:29:27 +0900 Subject: [PATCH] Add ALT-C keybinding for bash --- README.md | 11 ++--------- install | 10 ++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1a8249a..eb435eb 100644 --- a/README.md +++ b/README.md @@ -162,20 +162,13 @@ Key bindings for command line The install script will setup the following key bindings. -### bash - -- `CTRL-T` - Paste the selected file path(s) into the command line -- `CTRL-R` - Paste the selected command from history into the command line - -The source code can be found in `~/.fzf.bash`. - -### zsh +### bash/zsh - `CTRL-T` - Paste the selected file path(s) into the command line - `CTRL-R` - Paste the selected command from history into the command line - `ALT-C` - cd into the selected directory -The source code can be found in `~/.fzf.zsh`. +The source code can be found in `~/.fzf.bash` and in `~/.fzf.zsh`. Auto-completion --------------- diff --git a/install b/install index d362bf0..f85f6d3 100755 --- a/install +++ b/install @@ -110,6 +110,10 @@ __fsel() { echo } +__fcd() { + DIR=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf) && printf 'cd %q' "$DIR" +} + if [ -z "$(set -o | grep '^vi.*on')" ]; then # Required to refresh the prompt after fzf bind '"\er": redraw-current-line' @@ -119,6 +123,9 @@ if [ -z "$(set -o | grep '^vi.*on')" ]; then # CTRL-R - Paste the selected command from history into the command line bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"' + + # ALT-C - cd into the selected directory + bind '"\ec": " \C-e\C-u$(__fcd)\e\C-e\er\C-m"' else bind '"\C-x\C-e": shell-expand-line' bind '"\C-x\C-r": redraw-current-line' @@ -129,6 +136,9 @@ else # CTRL-R - Paste the selected command from history into the command line bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"' + + # ALT-C - cd into the selected directory + bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"' fi fi