mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-16 12:43:50 -07:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
04ebaddf5e | ||
|
45e1f1ae57 | ||
|
c1d5f7cef7 | ||
|
df663c4e41 | ||
|
d3742782f3 | ||
|
faff17b2a9 | ||
|
9a3cddc92e | ||
|
bd2763d863 | ||
|
b2bb22d883 | ||
|
ad8ec7f387 | ||
|
cf0ca8578c | ||
|
07aee79bd8 | ||
|
344b57fe33 | ||
|
18a2fbf54a |
68
README.md
68
README.md
@@ -26,8 +26,8 @@ git clone https://github.com/junegunn/fzf.git ~/.fzf
|
|||||||
~/.fzf/install
|
~/.fzf/install
|
||||||
```
|
```
|
||||||
|
|
||||||
The script will add an alias to fzf and auto-completion support to your
|
The script will generate `~/.fzf.bash` and `~/.fzf.zsh` and update your
|
||||||
`.bashrc` and `.zshrc`.
|
`.bashrc` and `.zshrc` to load them.
|
||||||
|
|
||||||
### Manual installation
|
### Manual installation
|
||||||
|
|
||||||
@@ -192,14 +192,6 @@ fda() {
|
|||||||
DIR=$(find ${1:-*} -type d 2> /dev/null | fzf) && cd "$DIR"
|
DIR=$(find ${1:-*} -type d 2> /dev/null | fzf) && cd "$DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
# fsel - Select multiple files in the given path
|
|
||||||
fsel() {
|
|
||||||
find ${1:-*} | fzf -m | while read item; do
|
|
||||||
echo -n "\"$item\" "
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
# fh - repeat history
|
# fh - repeat history
|
||||||
fh() {
|
fh() {
|
||||||
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
||||||
@@ -209,12 +201,23 @@ fh() {
|
|||||||
fkill() {
|
fkill() {
|
||||||
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# (Assuming you don't use the default CTRL-T and CTRL-R)
|
bash key bindings
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Required to refresh the prompt after fzf
|
||||||
|
bind '"\er": redraw-current-line'
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
bind '"\er": redraw-current-line'
|
fsel() {
|
||||||
bind '"\C-t": " \C-u \C-a\C-k$(fzf)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
find ${1:-*} | fzf -m | while read item; do
|
||||||
|
printf '%q ' "$item"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
bind '"\C-t": " \C-u \C-a\C-k$(fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
||||||
|
|
||||||
# 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$(history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
bind '"\C-r": " \C-e\C-u$(history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
||||||
@@ -267,13 +270,13 @@ over time*
|
|||||||
|
|
||||||
### bash
|
### bash
|
||||||
|
|
||||||
Fuzzy completion can be triggered if the word before the cursor ends
|
#### Files and directories
|
||||||
with the trigger sequence which is by default `**`.
|
|
||||||
|
Fuzzy completion for files and directories can be triggered if the word before
|
||||||
|
the cursor ends with the trigger sequence which is by default `**`.
|
||||||
|
|
||||||
- `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`
|
- `COMMAND [DIRECTORY/][FUZZY_PATTERN]**<TAB>`
|
||||||
|
|
||||||
#### Examples
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Files under current directory
|
# Files under current directory
|
||||||
# - You can select multiple items with TAB key
|
# - You can select multiple items with TAB key
|
||||||
@@ -296,6 +299,26 @@ cd **<TAB>
|
|||||||
cd ~/github/fzf**<TAB>
|
cd ~/github/fzf**<TAB>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Process IDs
|
||||||
|
|
||||||
|
Fuzzy completion for PIDs is provided for kill command. In this case
|
||||||
|
there is no trigger sequence, just press tab key after kill command.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Can select multiple processes with <TAB> or <Shift-TAB> keys
|
||||||
|
kill -9 <TAB>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Host names
|
||||||
|
|
||||||
|
For ssh and telnet commands, fuzzy completion for host names is provided. The
|
||||||
|
names are extracted from /etc/hosts file.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ssh <TAB>
|
||||||
|
telnet <TAB>
|
||||||
|
```
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -325,14 +348,17 @@ If you're running Ruby 1.9 or above, you can improve the startup time with
|
|||||||
- `time ruby --disable-gems ~/bin/fzf -h`
|
- `time ruby --disable-gems ~/bin/fzf -h`
|
||||||
- 0.025 sec
|
- 0.025 sec
|
||||||
|
|
||||||
Define fzf alias with the option as follows:
|
You can define fzf function with the option as follows:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
alias fzf='ruby --disable-gems ~/bin/fzf'
|
fzf() {
|
||||||
|
ruby --disable-gems ~/bin/fzf "$@"
|
||||||
|
}
|
||||||
|
export -f fzf
|
||||||
```
|
```
|
||||||
|
|
||||||
This is automatically set up in your .bashrc and .zshrc if you use the bundled
|
However, this is automatically set up in your .bashrc and .zshrc if you use the
|
||||||
[install](https://github.com/junegunn/fzf/blob/master/install) script.
|
bundled [install](https://github.com/junegunn/fzf/blob/master/install) script.
|
||||||
|
|
||||||
### Incorrect display on Ruby 1.8
|
### Incorrect display on Ruby 1.8
|
||||||
|
|
||||||
|
4
fzf
4
fzf
@@ -10,7 +10,7 @@
|
|||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# License: MIT
|
# License: MIT
|
||||||
# Last update: November 24, 2013
|
# Last update: December 5, 2013
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013 Junegunn Choi
|
# Copyright (c) 2013 Junegunn Choi
|
||||||
#
|
#
|
||||||
@@ -446,7 +446,7 @@ class FZF
|
|||||||
C.noecho
|
C.noecho
|
||||||
|
|
||||||
if @color
|
if @color
|
||||||
if C.can_change_color?
|
if C.can_change_color? && ENV['TERM'].to_s =~ /256/
|
||||||
C.init_pair 1, 110, dbg
|
C.init_pair 1, 110, dbg
|
||||||
C.init_pair 2, 108, dbg
|
C.init_pair 2, 108, dbg
|
||||||
C.init_pair 3, 254, 236
|
C.init_pair 3, 254, 236
|
||||||
|
@@ -31,11 +31,10 @@ _fzf_opts_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_generic_completion() {
|
_fzf_generic_completion() {
|
||||||
local cur prev opts base dir leftover matches
|
local cur base dir leftover matches
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**}
|
FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
||||||
if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then
|
if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then
|
||||||
base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}}
|
base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}}
|
||||||
eval base=$base
|
eval base=$base
|
||||||
@@ -46,12 +45,9 @@ _fzf_generic_completion() {
|
|||||||
leftover=${base/#"$dir"}
|
leftover=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ "$dir" = './' ] && dir=''
|
[ "$dir" = './' ] && dir=''
|
||||||
|
tput sc
|
||||||
matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
||||||
if [[ ${item} =~ \ ]]; then
|
printf '%q ' "$item"
|
||||||
echo -n "\"$item\" "
|
|
||||||
else
|
|
||||||
echo -n "$item "
|
|
||||||
fi
|
|
||||||
done)
|
done)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
@@ -59,6 +55,7 @@ _fzf_generic_completion() {
|
|||||||
else
|
else
|
||||||
COMPREPLY=( "$cur" )
|
COMPREPLY=( "$cur" )
|
||||||
fi
|
fi
|
||||||
|
tput rc
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
dir=$(dirname "$dir")
|
dir=$(dirname "$dir")
|
||||||
@@ -85,6 +82,36 @@ _fzf_dir_completion() {
|
|||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fzf_kill_completion() {
|
||||||
|
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
||||||
|
|
||||||
|
local selected
|
||||||
|
tput sc
|
||||||
|
selected=$(ps -ef | sed 1d | fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')
|
||||||
|
tput rc
|
||||||
|
|
||||||
|
if [ -n "$selected" ]; then
|
||||||
|
COMPREPLY=( "$selected" )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_fzf_host_completion() {
|
||||||
|
local cur prev selected
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
[ "$cur" = '-l' -o "$prev" = '-l' ] && return 1
|
||||||
|
|
||||||
|
tput sc
|
||||||
|
selected=$(grep -v '^\s*\(#\|$\)' /etc/hosts | awk '{print $2}' | sort -u | fzf $FZF_COMPLETION_OPTS -q "$cur")
|
||||||
|
tput rc
|
||||||
|
|
||||||
|
if [ -n "$selected" ]; then
|
||||||
|
COMPREPLY=("$selected")
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
complete -F _fzf_opts_completion fzf
|
complete -F _fzf_opts_completion fzf
|
||||||
|
|
||||||
# Directory
|
# Directory
|
||||||
@@ -110,7 +137,11 @@ for cmd in "
|
|||||||
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
||||||
done
|
done
|
||||||
|
|
||||||
bind '"\e\e": complete'
|
# Kill completion
|
||||||
bind '"\er": redraw-current-line'
|
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
|
||||||
bind '"\C-i": "\e\e\er"'
|
|
||||||
|
# Host completion
|
||||||
|
for cmd in "ssh telnet"; do
|
||||||
|
complete -F _fzf_host_completion -o default -o bashdefault $cmd
|
||||||
|
done
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = 'fzf'
|
spec.name = 'fzf'
|
||||||
spec.version = '0.5.0'
|
spec.version = '0.5.1'
|
||||||
spec.authors = ['Junegunn Choi']
|
spec.authors = ['Junegunn Choi']
|
||||||
spec.email = ['junegunn.c@gmail.com']
|
spec.email = ['junegunn.c@gmail.com']
|
||||||
spec.description = %q{Fuzzy finder for your shell}
|
spec.description = %q{Fuzzy finder for your shell}
|
||||||
|
74
install
74
install
@@ -1,11 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd `dirname $BASH_SOURCE`
|
cd `dirname $BASH_SOURCE`
|
||||||
FZF_BASE=`pwd`
|
fzf_base=`pwd`
|
||||||
|
|
||||||
# ruby executable
|
# ruby executable
|
||||||
echo -n "Checking Ruby executable ... "
|
echo -n "Checking Ruby executable ... "
|
||||||
RUBY=`which ruby`
|
ruby=`which ruby`
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ruby executable not found!"
|
echo "ruby executable not found!"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -26,51 +26,61 @@ echo -n "Checking Ruby version ... "
|
|||||||
/usr/bin/env ruby -e 'exit RUBY_VERSION >= "1.9"'
|
/usr/bin/env ruby -e 'exit RUBY_VERSION >= "1.9"'
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo ">= 1.9"
|
echo ">= 1.9"
|
||||||
FZF_ALIAS="alias fzf='$RUBY --disable-gems $FZF_BASE/fzf'"
|
fzf_cmd="$ruby --disable-gems $fzf_base/fzf"
|
||||||
else
|
else
|
||||||
echo "< 1.9"
|
echo "< 1.9"
|
||||||
FZF_ALIAS="alias fzf='$RUBY $FZF_BASE/fzf' # fzf"
|
fzf_cmd="$ruby $fzf_base/fzf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Auto-completion
|
# Auto-completion
|
||||||
read -p "Do you want to add auto-completion support? (y/n) " -n 1 -r
|
read -p "Do you want to add auto-completion support? ([y]/n) " -n 1 -r
|
||||||
echo
|
echo
|
||||||
[[ ! $REPLY =~ ^[Nn]$ ]]
|
[[ ! $REPLY =~ ^[Nn]$ ]]
|
||||||
AUTO_COMPLETION=$?
|
auto_completion=$?
|
||||||
|
|
||||||
|
echo
|
||||||
|
for shell in bash zsh; do
|
||||||
|
echo -n "Generate ~/.fzf.$shell ... "
|
||||||
|
src=~/.fzf.${shell}
|
||||||
|
|
||||||
|
fzf_completion="source $fzf_base/fzf-completion.${shell}"
|
||||||
|
if [ $auto_completion -ne 0 ]; then
|
||||||
|
fzf_completion="# $fzf_completion"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat > $src << EOF
|
||||||
|
unalias fzf 2> /dev/null
|
||||||
|
fzf() {
|
||||||
|
$fzf_cmd "\$@"
|
||||||
|
}
|
||||||
|
export -f fzf > /dev/null
|
||||||
|
$fzf_completion
|
||||||
|
|
||||||
|
EOF
|
||||||
|
echo "OK"
|
||||||
|
done
|
||||||
|
|
||||||
echo
|
echo
|
||||||
for shell in bash zsh; do
|
for shell in bash zsh; do
|
||||||
rc=~/.${shell}rc
|
rc=~/.${shell}rc
|
||||||
|
src="source ~/.fzf.${shell}"
|
||||||
|
|
||||||
echo "Update $rc:"
|
echo "Update $rc:"
|
||||||
|
echo " - $src"
|
||||||
# Install fzf alias
|
if [ $(grep -F "$src" $rc | wc -l) -gt 0 ]; then
|
||||||
echo "- Add fzf alias:"
|
echo " - Not added (already being sourced)"
|
||||||
echo " - $FZF_ALIAS"
|
|
||||||
if [ $(grep "alias fzf=" $rc | wc -l) -gt 0 ]; then
|
|
||||||
echo " - (X) fzf alias already exists"
|
|
||||||
else
|
else
|
||||||
echo $FZF_ALIAS >> $rc
|
echo $src >> $rc
|
||||||
echo " - Added."
|
echo " - Added"
|
||||||
fi
|
|
||||||
|
|
||||||
# Install auto-completion support
|
|
||||||
if [ $AUTO_COMPLETION -eq 0 ]; then
|
|
||||||
FZF_COMPLETION="source $FZF_BASE/fzf-completion.${shell}"
|
|
||||||
echo "- Add auto-completion support"
|
|
||||||
echo " - $FZF_COMPLETION"
|
|
||||||
if [ $(grep "source.*fzf-completion" $rc | wc -l) -gt 0 ]; then
|
|
||||||
echo " - (X) fzf-completion.${shell} already being sourced"
|
|
||||||
else
|
|
||||||
echo $FZF_COMPLETION >> $rc
|
|
||||||
echo " - Added."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Finished. Reload your .bashrc or .zshrc to take effect."
|
cat << EOF
|
||||||
echo " source ~/.bashrc # bash"
|
Finished. Reload your .bashrc or .zshrc to take effect.
|
||||||
echo " source ~/.zshrc # zsh"
|
source ~/.bashrc # bash"
|
||||||
echo
|
source ~/.zshrc # zsh"
|
||||||
echo "To uninstall fzf, simply remove the added lines."
|
|
||||||
|
To uninstall fzf, simply remove the added line.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user