mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 20:23: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
|
||||
```
|
||||
|
||||
The script will add an alias to fzf and auto-completion support to your
|
||||
`.bashrc` and `.zshrc`.
|
||||
The script will generate `~/.fzf.bash` and `~/.fzf.zsh` and update your
|
||||
`.bashrc` and `.zshrc` to load them.
|
||||
|
||||
### Manual installation
|
||||
|
||||
@@ -192,14 +192,6 @@ fda() {
|
||||
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() {
|
||||
eval $(history | fzf +s | sed 's/ *[0-9]* *//')
|
||||
@@ -209,12 +201,23 @@ fh() {
|
||||
fkill() {
|
||||
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
|
||||
bind '"\er": redraw-current-line'
|
||||
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"'
|
||||
fsel() {
|
||||
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
|
||||
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
|
||||
|
||||
Fuzzy completion can be triggered if the word before the cursor ends
|
||||
with the trigger sequence which is by default `**`.
|
||||
#### Files and directories
|
||||
|
||||
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>`
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
# Files under current directory
|
||||
# - You can select multiple items with TAB key
|
||||
@@ -296,6 +299,26 @@ cd **<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
|
||||
|
||||
```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`
|
||||
- 0.025 sec
|
||||
|
||||
Define fzf alias with the option as follows:
|
||||
You can define fzf function with the option as follows:
|
||||
|
||||
```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
|
||||
[install](https://github.com/junegunn/fzf/blob/master/install) script.
|
||||
However, this is automatically set up in your .bashrc and .zshrc if you use the
|
||||
bundled [install](https://github.com/junegunn/fzf/blob/master/install) script.
|
||||
|
||||
### Incorrect display on Ruby 1.8
|
||||
|
||||
|
4
fzf
4
fzf
@@ -10,7 +10,7 @@
|
||||
# URL: https://github.com/junegunn/fzf
|
||||
# Author: Junegunn Choi
|
||||
# License: MIT
|
||||
# Last update: November 24, 2013
|
||||
# Last update: December 5, 2013
|
||||
#
|
||||
# Copyright (c) 2013 Junegunn Choi
|
||||
#
|
||||
@@ -446,7 +446,7 @@ class FZF
|
||||
C.noecho
|
||||
|
||||
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 2, 108, dbg
|
||||
C.init_pair 3, 254, 236
|
||||
|
@@ -31,11 +31,10 @@ _fzf_opts_completion() {
|
||||
}
|
||||
|
||||
_fzf_generic_completion() {
|
||||
local cur prev opts base dir leftover matches
|
||||
local cur base dir leftover matches
|
||||
COMPREPLY=()
|
||||
FZF_COMPLETION_TRIGGER=${FZF_COMPLETION_TRIGGER:-**}
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
if [[ ${cur} == *"$FZF_COMPLETION_TRIGGER" ]]; then
|
||||
base=${cur:0:${#cur}-${#FZF_COMPLETION_TRIGGER}}
|
||||
eval base=$base
|
||||
@@ -46,12 +45,9 @@ _fzf_generic_completion() {
|
||||
leftover=${base/#"$dir"}
|
||||
leftover=${leftover/#\/}
|
||||
[ "$dir" = './' ] && dir=''
|
||||
tput sc
|
||||
matches=$(find "$dir"* $1 2> /dev/null | fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
||||
if [[ ${item} =~ \ ]]; then
|
||||
echo -n "\"$item\" "
|
||||
else
|
||||
echo -n "$item "
|
||||
fi
|
||||
printf '%q ' "$item"
|
||||
done)
|
||||
matches=${matches% }
|
||||
if [ -n "$matches" ]; then
|
||||
@@ -59,6 +55,7 @@ _fzf_generic_completion() {
|
||||
else
|
||||
COMPREPLY=( "$cur" )
|
||||
fi
|
||||
tput rc
|
||||
return 0
|
||||
fi
|
||||
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
|
||||
|
||||
# Directory
|
||||
@@ -110,7 +137,11 @@ for cmd in "
|
||||
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
||||
done
|
||||
|
||||
bind '"\e\e": complete'
|
||||
bind '"\er": redraw-current-line'
|
||||
bind '"\C-i": "\e\e\er"'
|
||||
# Kill completion
|
||||
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
|
||||
|
||||
# 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
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = 'fzf'
|
||||
spec.version = '0.5.0'
|
||||
spec.version = '0.5.1'
|
||||
spec.authors = ['Junegunn Choi']
|
||||
spec.email = ['junegunn.c@gmail.com']
|
||||
spec.description = %q{Fuzzy finder for your shell}
|
||||
|
74
install
74
install
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd `dirname $BASH_SOURCE`
|
||||
FZF_BASE=`pwd`
|
||||
fzf_base=`pwd`
|
||||
|
||||
# ruby executable
|
||||
echo -n "Checking Ruby executable ... "
|
||||
RUBY=`which ruby`
|
||||
ruby=`which ruby`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ruby executable not found!"
|
||||
exit 1
|
||||
@@ -26,51 +26,61 @@ echo -n "Checking Ruby version ... "
|
||||
/usr/bin/env ruby -e 'exit RUBY_VERSION >= "1.9"'
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ">= 1.9"
|
||||
FZF_ALIAS="alias fzf='$RUBY --disable-gems $FZF_BASE/fzf'"
|
||||
fzf_cmd="$ruby --disable-gems $fzf_base/fzf"
|
||||
else
|
||||
echo "< 1.9"
|
||||
FZF_ALIAS="alias fzf='$RUBY $FZF_BASE/fzf' # fzf"
|
||||
fzf_cmd="$ruby $fzf_base/fzf"
|
||||
fi
|
||||
|
||||
# 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
|
||||
[[ ! $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
|
||||
for shell in bash zsh; do
|
||||
rc=~/.${shell}rc
|
||||
src="source ~/.fzf.${shell}"
|
||||
|
||||
echo "Update $rc:"
|
||||
|
||||
# Install fzf alias
|
||||
echo "- Add fzf alias:"
|
||||
echo " - $FZF_ALIAS"
|
||||
if [ $(grep "alias fzf=" $rc | wc -l) -gt 0 ]; then
|
||||
echo " - (X) fzf alias already exists"
|
||||
echo " - $src"
|
||||
if [ $(grep -F "$src" $rc | wc -l) -gt 0 ]; then
|
||||
echo " - Not added (already being sourced)"
|
||||
else
|
||||
echo $FZF_ALIAS >> $rc
|
||||
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
|
||||
echo $src >> $rc
|
||||
echo " - Added"
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
echo "Finished. Reload your .bashrc or .zshrc to take effect."
|
||||
echo " source ~/.bashrc # bash"
|
||||
echo " source ~/.zshrc # zsh"
|
||||
echo
|
||||
echo "To uninstall fzf, simply remove the added lines."
|
||||
cat << EOF
|
||||
Finished. Reload your .bashrc or .zshrc to take effect.
|
||||
source ~/.bashrc # bash"
|
||||
source ~/.zshrc # zsh"
|
||||
|
||||
To uninstall fzf, simply remove the added line.
|
||||
EOF
|
||||
|
||||
|
Reference in New Issue
Block a user