Add ALT-C keybinding for bash

This commit is contained in:
Junegunn Choi 2014-03-13 14:29:27 +09:00
parent 8a3e8c2d81
commit 2296013174
2 changed files with 12 additions and 9 deletions

View File

@ -162,20 +162,13 @@ Key bindings for command line
The install script will setup the following key bindings. The install script will setup the following key bindings.
### bash ### 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
The source code can be found in `~/.fzf.bash`.
### zsh
- `CTRL-T` - Paste the selected file path(s) into the command line - `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-R` - Paste the selected command from history into the command line
- `ALT-C` - cd into the selected directory - `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 Auto-completion
--------------- ---------------

10
install
View File

@ -110,6 +110,10 @@ __fsel() {
echo 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 if [ -z "$(set -o | grep '^vi.*on')" ]; then
# Required to refresh the prompt after fzf # Required to refresh the prompt after fzf
bind '"\er": redraw-current-line' 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 # 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"' 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 else
bind '"\C-x\C-e": shell-expand-line' bind '"\C-x\C-e": shell-expand-line'
bind '"\C-x\C-r": redraw-current-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 # 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"' 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
fi fi