mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-14 14:23:47 -05:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1da065e50e | ||
|
|
86bc9d506f | ||
|
|
eee45a9578 | ||
|
|
659f49a09a | ||
|
|
8fa9e85980 | ||
|
|
92a75c9563 | ||
|
|
7c7a30c472 | ||
|
|
ea271cd4e2 | ||
|
|
6a38d07a4c | ||
|
|
c4e5ee63bb | ||
|
|
862da2c0b1 | ||
|
|
545370d2b3 | ||
|
|
59220c63a6 | ||
|
|
86306dd45a | ||
|
|
98d2bfa0db | ||
|
|
aec48f159b | ||
|
|
ad7e433a7d | ||
|
|
5a60aa5050 | ||
|
|
ebea470875 | ||
|
|
d980e00961 | ||
|
|
987799f8fb | ||
|
|
d2f3604c1d | ||
|
|
72cc558fdc | ||
|
|
6bc3fe6e67 | ||
|
|
9398878048 | ||
|
|
ca19762e58 | ||
|
|
8764be07e2 | ||
|
|
2022a3ad96 | ||
|
|
65d9d416b4 | ||
|
|
fa2f9f1f21 |
@@ -4,7 +4,7 @@ rvm:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
- sudo apt-get update
|
- sudo apt-get update
|
||||||
- sudo apt-get install -y libncurses-dev lib32ncurses5-dev
|
- sudo apt-get install -y libncurses-dev lib32ncurses5-dev libgpm-dev
|
||||||
- sudo add-apt-repository -y ppa:pi-rho/dev
|
- sudo add-apt-repository -y ppa:pi-rho/dev
|
||||||
- sudo apt-add-repository -y ppa:fish-shell/release-2
|
- sudo apt-add-repository -y ppa:fish-shell/release-2
|
||||||
- sudo apt-get update
|
- sudo apt-get update
|
||||||
|
|||||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,6 +1,27 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.10.7
|
||||||
|
------
|
||||||
|
|
||||||
|
- Fixed unserialized interrupt handling during execute action which often
|
||||||
|
caused invalid memory access and crash
|
||||||
|
- Changed `--tiebreak=length` (default) to use trimmed length when `--nth` is
|
||||||
|
used
|
||||||
|
|
||||||
|
0.10.6
|
||||||
|
------
|
||||||
|
|
||||||
|
- Replaced `--header-file` with `--header` option
|
||||||
|
- `--header` and `--header-lines` can be used together
|
||||||
|
- Changed exit status
|
||||||
|
- 0: Okay
|
||||||
|
- 1: No match
|
||||||
|
- 2: Error
|
||||||
|
- 130: Interrupted
|
||||||
|
- 64-bit linux binary is statically-linked with ncurses to avoid
|
||||||
|
compatibility issues.
|
||||||
|
|
||||||
0.10.5
|
0.10.5
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf.png" height="170" alt="fzf - a command-line fuzzy finder"> [](https://travis-ci.org/junegunn/fzf) <a href="http://flattr.com/thing/3115381/junegunnfzf-on-GitHub" target="_blank"><img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a>
|
<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf.png" height="170" alt="fzf - a command-line fuzzy finder"> [](https://travis-ci.org/junegunn/fzf)
|
||||||
===
|
===
|
||||||
|
|
||||||
fzf is a general-purpose command-line fuzzy finder.
|
fzf is a general-purpose command-line fuzzy finder.
|
||||||
|
|||||||
12
bin/fzf-tmux
12
bin/fzf-tmux
@@ -91,10 +91,10 @@ set -e
|
|||||||
|
|
||||||
# Clean up named pipes on exit
|
# Clean up named pipes on exit
|
||||||
id=$RANDOM
|
id=$RANDOM
|
||||||
argsf=/tmp/fzf-args-$id
|
argsf="${TMPDIR:-/tmp}/fzf-args-$id"
|
||||||
fifo1=/tmp/fzf-fifo1-$id
|
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
|
||||||
fifo2=/tmp/fzf-fifo2-$id
|
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
||||||
fifo3=/tmp/fzf-fifo3-$id
|
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f $argsf $fifo1 $fifo2 $fifo3
|
rm -f $argsf $fifo1 $fifo2 $fifo3
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ trap cleanup EXIT SIGINT SIGTERM
|
|||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
>&2 echo "$1"
|
>&2 echo "$1"
|
||||||
exit 1
|
exit 2
|
||||||
}
|
}
|
||||||
fzf="$(which fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
fzf="$(which fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
||||||
[ -x "$fzf" ] || fail "fzf executable not found"
|
[ -x "$fzf" ] || fail "fzf executable not found"
|
||||||
@@ -134,5 +134,5 @@ else
|
|||||||
cat <&0 > $fifo1 &
|
cat <&0 > $fifo1 &
|
||||||
fi
|
fi
|
||||||
cat $fifo2
|
cat $fifo2
|
||||||
[ "$(cat $fifo3)" = '0' ]
|
exit "$(cat $fifo3)"
|
||||||
|
|
||||||
|
|||||||
19
install
19
install
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
[[ "$@" =~ --pre ]] && version=0.10.5 pre=1 ||
|
[[ "$@" =~ --pre ]] && version=0.10.7 pre=1 ||
|
||||||
version=0.10.5 pre=0
|
version=0.10.7 pre=0
|
||||||
|
|
||||||
cd $(dirname $BASH_SOURCE)
|
cd $(dirname $BASH_SOURCE)
|
||||||
fzf_base=$(pwd)
|
fzf_base=$(pwd)
|
||||||
@@ -80,12 +80,7 @@ download() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x $1 && symlink $1 || return 1
|
chmod +x $1 && symlink $1 && check_binary
|
||||||
if [[ $1 =~ linux_amd64$ ]]; then
|
|
||||||
check_binary || download $1-static
|
|
||||||
else
|
|
||||||
check_binary
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Try to download binary executable
|
# Try to download binary executable
|
||||||
@@ -190,7 +185,7 @@ for shell in bash zsh; do
|
|||||||
echo -n "Generate ~/.fzf.$shell ... "
|
echo -n "Generate ~/.fzf.$shell ... "
|
||||||
src=~/.fzf.${shell}
|
src=~/.fzf.${shell}
|
||||||
|
|
||||||
fzf_completion="[[ \$- =~ i ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
|
fzf_completion="[[ \$- == *i* ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
|
||||||
if [ $auto_completion -ne 0 ]; then
|
if [ $auto_completion -ne 0 ]; then
|
||||||
fzf_completion="# $fzf_completion"
|
fzf_completion="# $fzf_completion"
|
||||||
fi
|
fi
|
||||||
@@ -203,13 +198,13 @@ for shell in bash zsh; do
|
|||||||
cat > $src << EOF
|
cat > $src << EOF
|
||||||
# Setup fzf
|
# Setup fzf
|
||||||
# ---------
|
# ---------
|
||||||
if [[ ! "\$PATH" =~ "$fzf_base/bin" ]]; then
|
if [[ ! "\$PATH" == *$fzf_base/bin* ]]; then
|
||||||
export PATH="\$PATH:$fzf_base/bin"
|
export PATH="\$PATH:$fzf_base/bin"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Man path
|
# Man path
|
||||||
# --------
|
# --------
|
||||||
if [[ ! "\$MANPATH" =~ "$fzf_base/man" && -d "$fzf_base/man" ]]; then
|
if [[ ! "\$MANPATH" == *$fzf_base/man* && -d "$fzf_base/man" ]]; then
|
||||||
export MANPATH="\$MANPATH:$fzf_base/man"
|
export MANPATH="\$MANPATH:$fzf_base/man"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -250,6 +245,7 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
append_line() {
|
append_line() {
|
||||||
|
set -e
|
||||||
echo "Update $2:"
|
echo "Update $2:"
|
||||||
echo " - $1"
|
echo " - $1"
|
||||||
[ -f "$2" ] || touch "$2"
|
[ -f "$2" ] || touch "$2"
|
||||||
@@ -266,6 +262,7 @@ append_line() {
|
|||||||
echo " + Added"
|
echo " + Added"
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
|
set +e
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf 1 "Sep 2015" "fzf 0.10.5" "fzf - a command-line fuzzy finder"
|
.TH fzf 1 "Oct 2015" "fzf 0.10.7" "fzf - a command-line fuzzy finder"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf - a command-line fuzzy finder
|
fzf - a command-line fuzzy finder
|
||||||
@@ -285,11 +285,11 @@ When enabled, \fBCTRL-N\fR and \fBCTRL-P\fR are automatically remapped to
|
|||||||
Maximum number of entries in the history file (default: 1000). The file is
|
Maximum number of entries in the history file (default: 1000). The file is
|
||||||
automatically truncated when the number of the lines exceeds the value.
|
automatically truncated when the number of the lines exceeds the value.
|
||||||
.TP
|
.TP
|
||||||
.BI "--header-file=" "FILE"
|
.BI "--header=" "STR"
|
||||||
The content of the file will be printed as the sticky header. The lines in the
|
The given string will be printed as the sticky header. The lines are displayed
|
||||||
file are displayed in order from top to bottom regardless of \fB--reverse\fR,
|
in the given order from top to bottom regardless of \fB--reverse\fR option, and
|
||||||
and are not affected by \fB--with-nth\fR. ANSI color codes are processed even
|
are not affected by \fB--with-nth\fR. ANSI color codes are processed even when
|
||||||
when \fB--ansi\fR is not set.
|
\fB--ansi\fR is not set.
|
||||||
.TP
|
.TP
|
||||||
.BI "--header-lines=" "N"
|
.BI "--header-lines=" "N"
|
||||||
The first N lines of the input are treated as the sticky header. When
|
The first N lines of the input are treated as the sticky header. When
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ function! s:fzf_exec()
|
|||||||
\ input('fzf executable not found. Download binary? (y/n) ') =~? '^y'
|
\ input('fzf executable not found. Download binary? (y/n) ') =~? '^y'
|
||||||
redraw
|
redraw
|
||||||
echo
|
echo
|
||||||
echohl WarningMsg
|
call s:warn('Downloading fzf binary. Please wait ...')
|
||||||
echo 'Downloading fzf binary. Please wait ...'
|
|
||||||
echohl None
|
|
||||||
let s:installed = 1
|
let s:installed = 1
|
||||||
call system(s:install.' --bin')
|
call system(s:install.' --bin')
|
||||||
return s:fzf_exec()
|
return s:fzf_exec()
|
||||||
@@ -98,14 +96,24 @@ function! s:upgrade(dict)
|
|||||||
return copy
|
return copy
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:error(msg)
|
||||||
|
echohl ErrorMsg
|
||||||
|
echom a:msg
|
||||||
|
echohl None
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:warn(msg)
|
||||||
|
echohl WarningMsg
|
||||||
|
echom a:msg
|
||||||
|
echohl None
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
try
|
try
|
||||||
let oshell = &shell
|
let oshell = &shell
|
||||||
set shell=sh
|
set shell=sh
|
||||||
if has('nvim') && bufexists('term://*:FZF')
|
if has('nvim') && bufexists('term://*:FZF')
|
||||||
echohl WarningMsg
|
call s:warn('FZF is already running!')
|
||||||
echomsg 'FZF is already running!'
|
|
||||||
echohl None
|
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
let dict = exists('a:1') ? s:upgrade(a:1) : {}
|
let dict = exists('a:1') ? s:upgrade(a:1) : {}
|
||||||
@@ -205,7 +213,7 @@ endfunction
|
|||||||
function! s:xterm_launcher()
|
function! s:xterm_launcher()
|
||||||
let fmt = 'xterm -T "[fzf]" -bg "\%s" -fg "\%s" -geometry %dx%d+%d+%d -e bash -ic %%s'
|
let fmt = 'xterm -T "[fzf]" -bg "\%s" -fg "\%s" -geometry %dx%d+%d+%d -e bash -ic %%s'
|
||||||
if has('gui_macvim')
|
if has('gui_macvim')
|
||||||
let fmt .= '; osascript -e "tell application \"MacVim\" to activate"'
|
let fmt .= '&& osascript -e "tell application \"MacVim\" to activate"'
|
||||||
endif
|
endif
|
||||||
return printf(fmt,
|
return printf(fmt,
|
||||||
\ synIDattr(hlID("Normal"), "bg"), synIDattr(hlID("Normal"), "fg"),
|
\ synIDattr(hlID("Normal"), "bg"), synIDattr(hlID("Normal"), "fg"),
|
||||||
@@ -214,6 +222,19 @@ endfunction
|
|||||||
unlet! s:launcher
|
unlet! s:launcher
|
||||||
let s:launcher = function('s:xterm_launcher')
|
let s:launcher = function('s:xterm_launcher')
|
||||||
|
|
||||||
|
function! s:exit_handler(code, command, ...)
|
||||||
|
if a:code == 130
|
||||||
|
return 0
|
||||||
|
elseif a:code > 1
|
||||||
|
call s:error('Error running ' . a:command)
|
||||||
|
if !empty(a:000)
|
||||||
|
sleep
|
||||||
|
endif
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:execute(dict, command, temps)
|
function! s:execute(dict, command, temps)
|
||||||
call s:pushd(a:dict)
|
call s:pushd(a:dict)
|
||||||
silent! !clear 2> /dev/null
|
silent! !clear 2> /dev/null
|
||||||
@@ -227,16 +248,7 @@ function! s:execute(dict, command, temps)
|
|||||||
endif
|
endif
|
||||||
execute 'silent !'.command
|
execute 'silent !'.command
|
||||||
redraw!
|
redraw!
|
||||||
if v:shell_error
|
return s:exit_handler(v:shell_error, command) ? s:callback(a:dict, a:temps) : []
|
||||||
" Do not print error message on exit status 1
|
|
||||||
if v:shell_error > 1
|
|
||||||
echohl ErrorMsg
|
|
||||||
echo 'Error running ' . command
|
|
||||||
endif
|
|
||||||
return []
|
|
||||||
else
|
|
||||||
return s:callback(a:dict, a:temps)
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute_tmux(dict, command, temps)
|
function! s:execute_tmux(dict, command, temps)
|
||||||
@@ -248,7 +260,7 @@ function! s:execute_tmux(dict, command, temps)
|
|||||||
|
|
||||||
call system(command)
|
call system(command)
|
||||||
redraw!
|
redraw!
|
||||||
return s:callback(a:dict, a:temps)
|
return s:exit_handler(v:shell_error, command) ? s:callback(a:dict, a:temps) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:calc_size(max, val, dict)
|
function! s:calc_size(max, val, dict)
|
||||||
@@ -309,6 +321,7 @@ function! s:execute_term(dict, command, temps)
|
|||||||
call s:pushd(a:dict)
|
call s:pushd(a:dict)
|
||||||
|
|
||||||
let fzf = { 'buf': bufnr('%'), 'dict': a:dict, 'temps': a:temps, 'name': 'FZF' }
|
let fzf = { 'buf': bufnr('%'), 'dict': a:dict, 'temps': a:temps, 'name': 'FZF' }
|
||||||
|
let s:command = a:command
|
||||||
function! fzf.on_exit(id, code)
|
function! fzf.on_exit(id, code)
|
||||||
let pos = s:getpos()
|
let pos = s:getpos()
|
||||||
let inplace = pos == s:ppos " {'window': 'enew'}
|
let inplace = pos == s:ppos " {'window': 'enew'}
|
||||||
@@ -322,9 +335,13 @@ function! s:execute_term(dict, command, temps)
|
|||||||
wincmd p
|
wincmd p
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !s:exit_handler(a:code, s:command, 1)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
call s:pushd(self.dict)
|
call s:pushd(self.dict)
|
||||||
try
|
try
|
||||||
redraw!
|
|
||||||
call s:callback(self.dict, self.temps)
|
call s:callback(self.dict, self.temps)
|
||||||
|
|
||||||
if inplace && bufnr('') == self.buf
|
if inplace && bufnr('') == self.buf
|
||||||
@@ -388,6 +405,12 @@ function! s:cmd_callback(lines) abort
|
|||||||
endif
|
endif
|
||||||
let key = remove(a:lines, 0)
|
let key = remove(a:lines, 0)
|
||||||
let cmd = get(s:action, key, 'e')
|
let cmd = get(s:action, key, 'e')
|
||||||
|
if len(a:lines) > 1
|
||||||
|
augroup fzf_swap
|
||||||
|
autocmd SwapExists * let v:swapchoice='o'
|
||||||
|
\| call s:warn('fzf: E325: swap file exists: '.expand('<afile>'))
|
||||||
|
augroup END
|
||||||
|
endif
|
||||||
try
|
try
|
||||||
let autochdir = &autochdir
|
let autochdir = &autochdir
|
||||||
set noautochdir
|
set noautochdir
|
||||||
@@ -396,6 +419,7 @@ function! s:cmd_callback(lines) abort
|
|||||||
endfor
|
endfor
|
||||||
finally
|
finally
|
||||||
let &autochdir = autochdir
|
let &autochdir = autochdir
|
||||||
|
silent! autocmd! fzf_swap
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ _fzf_opts_completion() {
|
|||||||
--cycle
|
--cycle
|
||||||
--history
|
--history
|
||||||
--history-size
|
--history-size
|
||||||
--header-file
|
--header
|
||||||
--header-lines
|
--header-lines
|
||||||
--margin"
|
--margin"
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ _fzf_opts_completion() {
|
|||||||
COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--history|--header-file)
|
--history)
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@@ -94,7 +94,7 @@ _fzf_handle_dynamic_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local cur base dir leftover matches trigger cmd fzf
|
local cur base dir leftover matches trigger cmd fzf
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
||||||
@@ -135,20 +135,29 @@ _fzf_path_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_list_completion() {
|
_fzf_feed_fifo() (
|
||||||
local cur selected trigger cmd src fzf
|
rm -f "$fifo"
|
||||||
|
mkfifo "$fifo"
|
||||||
|
cat <&0 > "$fifo" &
|
||||||
|
)
|
||||||
|
|
||||||
|
_fzf_complete() {
|
||||||
|
local fifo cur selected trigger cmd fzf
|
||||||
|
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
read -r src
|
|
||||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ ${cur} == *"$trigger" ]]; then
|
if [[ ${cur} == *"$trigger" ]]; then
|
||||||
cur=${cur:0:${#cur}-${#trigger}}
|
cur=${cur:0:${#cur}-${#trigger}}
|
||||||
|
|
||||||
|
_fzf_feed_fifo "$fifo"
|
||||||
tput sc
|
tput sc
|
||||||
selected=$(eval "$src | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')
|
selected=$(eval "cat '$fifo' | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')
|
||||||
selected=${selected% }
|
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
||||||
tput rc
|
tput rc
|
||||||
|
rm -f "$fifo"
|
||||||
|
|
||||||
if [ -n "$selected" ]; then
|
if [ -n "$selected" ]; then
|
||||||
COMPREPLY=("$selected")
|
COMPREPLY=("$selected")
|
||||||
@@ -160,25 +169,25 @@ _fzf_list_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_all_completion() {
|
_fzf_path_completion() {
|
||||||
_fzf_path_completion \
|
__fzf_generic_path_completion \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
||||||
"-m" "" "$@"
|
"-m" "" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_file_completion() {
|
_fzf_file_completion() {
|
||||||
_fzf_path_completion \
|
__fzf_generic_path_completion \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \
|
"-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \
|
||||||
"-m" "" "$@"
|
"-m" "" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_dir_completion() {
|
_fzf_dir_completion() {
|
||||||
_fzf_path_completion \
|
__fzf_generic_path_completion \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
||||||
"" "/" "$@"
|
"" "/" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_kill_completion() {
|
_fzf_complete_kill() {
|
||||||
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
||||||
|
|
||||||
local selected fzf
|
local selected fzf
|
||||||
@@ -193,28 +202,37 @@ _fzf_kill_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_telnet_completion() {
|
_fzf_complete_telnet() {
|
||||||
_fzf_list_completion '+m' "$@" << "EOF"
|
_fzf_complete '+m' "$@" < <(
|
||||||
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u
|
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' |
|
||||||
EOF
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_ssh_completion() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_list_completion '+m' "$@" << "EOF"
|
_fzf_complete '+m' "$@" < <(
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') <(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') | awk '{if (length($2) > 0) {print $2}}' | sort -u
|
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
||||||
EOF
|
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
||||||
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_env_var_completion() {
|
_fzf_complete_unset() {
|
||||||
_fzf_list_completion '-m' "$@" << "EOF"
|
_fzf_complete '-m' "$@" < <(
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
EOF
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_alias_completion() {
|
_fzf_complete_export() {
|
||||||
_fzf_list_completion '-m' "$@" << "EOF"
|
_fzf_complete '-m' "$@" < <(
|
||||||
alias | sed 's/=.*//' | sed 's/.* //'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
EOF
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
_fzf_complete_unalias() {
|
||||||
|
_fzf_complete '-m' "$@" < <(
|
||||||
|
alias | sed 's/=.*//' | sed 's/.* //'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# fzf options
|
# fzf options
|
||||||
@@ -257,19 +275,19 @@ done
|
|||||||
|
|
||||||
# Anything
|
# Anything
|
||||||
for cmd in $a_cmds; do
|
for cmd in $a_cmds; do
|
||||||
complete -F _fzf_all_completion -o default -o bashdefault $cmd
|
complete -F _fzf_path_completion -o default -o bashdefault $cmd
|
||||||
done
|
done
|
||||||
|
|
||||||
# Kill completion
|
# Kill completion
|
||||||
complete -F _fzf_kill_completion -o nospace -o default -o bashdefault kill
|
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
|
||||||
|
|
||||||
# Host completion
|
# Host completion
|
||||||
complete -F _fzf_ssh_completion -o default -o bashdefault ssh
|
complete -F _fzf_complete_ssh -o default -o bashdefault ssh
|
||||||
complete -F _fzf_telnet_completion -o default -o bashdefault telnet
|
complete -F _fzf_complete_telnet -o default -o bashdefault telnet
|
||||||
|
|
||||||
# Environment variables / Aliases
|
# Environment variables / Aliases
|
||||||
complete -F _fzf_env_var_completion -o default -o bashdefault unset
|
complete -F _fzf_complete_unset -o default -o bashdefault unset
|
||||||
complete -F _fzf_env_var_completion -o default -o bashdefault export
|
complete -F _fzf_complete_export -o default -o bashdefault export
|
||||||
complete -F _fzf_alias_completion -o default -o bashdefault unalias
|
complete -F _fzf_complete_unalias -o default -o bashdefault unalias
|
||||||
|
|
||||||
unset cmd d_cmds f_cmds a_cmds x_cmds
|
unset cmd d_cmds f_cmds a_cmds x_cmds
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
||||||
# - $FZF_COMPLETION_OPTS (default: empty)
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
||||||
|
|
||||||
_fzf_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local base lbuf find_opts fzf_opts suffix tail fzf dir leftover matches nnm
|
local base lbuf find_opts fzf_opts suffix tail fzf dir leftover matches nnm
|
||||||
|
# (Q) flag removes a quoting level: "foo\ bar" => "foo bar"
|
||||||
base=${(Q)1}
|
base=${(Q)1}
|
||||||
lbuf=$2
|
lbuf=$2
|
||||||
find_opts=$3
|
find_opts=$3
|
||||||
@@ -47,55 +48,71 @@ _fzf_path_completion() {
|
|||||||
[ -n "$nnm" ] && unsetopt nonomatch
|
[ -n "$nnm" ] && unsetopt nonomatch
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_all_completion() {
|
_fzf_path_completion() {
|
||||||
_fzf_path_completion "$1" "$2" \
|
__fzf_generic_path_completion "$1" "$2" \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
||||||
"-m" "" " "
|
"-m" "" " "
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_dir_completion() {
|
_fzf_dir_completion() {
|
||||||
_fzf_path_completion "$1" "$2" \
|
__fzf_generic_path_completion "$1" "$2" \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
||||||
"" "/" ""
|
"" "/" ""
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_list_completion() {
|
_fzf_feed_fifo() (
|
||||||
local prefix lbuf fzf_opts src fzf matches
|
rm -f "$fifo"
|
||||||
prefix=$1
|
mkfifo "$fifo"
|
||||||
|
cat <&0 > "$fifo" &
|
||||||
|
)
|
||||||
|
|
||||||
|
_fzf_complete() {
|
||||||
|
local fifo fzf_opts lbuf fzf matches
|
||||||
|
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
||||||
|
fzf_opts=$1
|
||||||
lbuf=$2
|
lbuf=$2
|
||||||
fzf_opts=$3
|
|
||||||
read -r src
|
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
|
|
||||||
matches=$(eval "$src" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "$prefix")
|
_fzf_feed_fifo "$fifo"
|
||||||
|
matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | tr '\n' ' ')
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
LBUFFER="$lbuf$matches "
|
LBUFFER="$lbuf$matches"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle redisplay
|
||||||
|
rm -f "$fifo"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_telnet_completion() {
|
_fzf_complete_telnet() {
|
||||||
_fzf_list_completion "$1" "$2" '+m' << "EOF"
|
_fzf_complete '+m' "$@" < <(
|
||||||
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' | awk '{if (length($2) > 0) {print $2}}' | sort -u
|
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' |
|
||||||
EOF
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_ssh_completion() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_list_completion "$1" "$2" '+m' << "EOF"
|
_fzf_complete '+m' "$@" < <(
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') <(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') | awk '{if (length($2) > 0) {print $2}}' | sort -u
|
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
||||||
EOF
|
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
||||||
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_env_var_completion() {
|
_fzf_complete_export() {
|
||||||
_fzf_list_completion "$1" "$2" '+m' << "EOF"
|
_fzf_complete '-m' "$@" < <(
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
EOF
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_alias_completion() {
|
_fzf_complete_unset() {
|
||||||
_fzf_list_completion "$1" "$2" '+m' << "EOF"
|
_fzf_complete '-m' "$@" < <(
|
||||||
alias | sed 's/=.*//'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
EOF
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
_fzf_complete_unalias() {
|
||||||
|
_fzf_complete '+m' "$@" < <(
|
||||||
|
alias | sed 's/=.*//'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fzf-completion() {
|
fzf-completion() {
|
||||||
@@ -135,18 +152,12 @@ fzf-completion() {
|
|||||||
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
||||||
[ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}}
|
[ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}}
|
||||||
|
|
||||||
if [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then
|
if eval "type _fzf_complete_${cmd} > /dev/null"; then
|
||||||
_fzf_dir_completion "$prefix" $lbuf
|
eval "prefix=\"$prefix\" _fzf_complete_${cmd} \"$lbuf\""
|
||||||
elif [ $cmd = telnet ]; then
|
elif [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then
|
||||||
_fzf_telnet_completion "$prefix" $lbuf
|
_fzf_dir_completion "$prefix" "$lbuf"
|
||||||
elif [ $cmd = ssh ]; then
|
|
||||||
_fzf_ssh_completion "$prefix" $lbuf
|
|
||||||
elif [ $cmd = unset -o $cmd = export ]; then
|
|
||||||
_fzf_env_var_completion "$prefix" $lbuf
|
|
||||||
elif [ $cmd = unalias ]; then
|
|
||||||
_fzf_alias_completion "$prefix" $lbuf
|
|
||||||
else
|
else
|
||||||
_fzf_all_completion "$prefix" $lbuf
|
_fzf_path_completion "$prefix" "$lbuf"
|
||||||
fi
|
fi
|
||||||
# Fall back to default completion
|
# Fall back to default completion
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
if [[ $- =~ i ]]; then
|
if [[ $- == *i* ]]; then
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path(s) into the command line
|
# CTRL-T - Paste the selected file path(s) into the command line
|
||||||
__fsel() {
|
__fsel() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
FROM centos:centos7
|
FROM centos:centos6
|
||||||
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
||||||
|
|
||||||
# yum
|
# yum
|
||||||
RUN yum install -y git gcc make tar ncurses-devel
|
RUN yum install -y git gcc make tar glibc-devel glibc-devel.i686 \
|
||||||
|
ncurses-devel ncurses-static ncurses-devel.i686 \
|
||||||
|
gpm-devel gpm-static libgcc.i686
|
||||||
|
|
||||||
# Install Go 1.4
|
# Install Go 1.4
|
||||||
RUN cd / && curl \
|
RUN cd / && curl \
|
||||||
@@ -13,6 +15,9 @@ ENV GOPATH /go
|
|||||||
ENV GOROOT /go1.4
|
ENV GOROOT /go1.4
|
||||||
ENV PATH /go1.4/bin:$PATH
|
ENV PATH /go1.4/bin:$PATH
|
||||||
|
|
||||||
|
# For i386 build
|
||||||
|
RUN cd $GOROOT/src && GOARCH=386 ./make.bash
|
||||||
|
|
||||||
# Volume
|
# Volume
|
||||||
VOLUME /go
|
VOLUME /go
|
||||||
|
|
||||||
|
|||||||
44
src/Makefile
44
src/Makefile
@@ -5,19 +5,8 @@ endif
|
|||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
GOOS := darwin
|
GOOS := darwin
|
||||||
LDFLAGS :=
|
|
||||||
ifdef STATIC
|
|
||||||
$(error Static linking not possible on OS X)
|
|
||||||
endif
|
|
||||||
else ifeq ($(UNAME_S),Linux)
|
else ifeq ($(UNAME_S),Linux)
|
||||||
GOOS := linux
|
GOOS := linux
|
||||||
ifdef STATIC
|
|
||||||
SUFFIX := -static
|
|
||||||
LDFLAGS := --ldflags '-extldflags "-static -ltinfo -lgpm"'
|
|
||||||
else
|
|
||||||
SUFFIX :=
|
|
||||||
LDFLAGS :=
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(shell uname -m),x86_64)
|
ifneq ($(shell uname -m),x86_64)
|
||||||
@@ -27,11 +16,11 @@ endif
|
|||||||
SOURCES := $(wildcard *.go */*.go)
|
SOURCES := $(wildcard *.go */*.go)
|
||||||
BINDIR := ../bin
|
BINDIR := ../bin
|
||||||
|
|
||||||
BINARY32 := fzf-$(GOOS)_386$(SUFFIX)
|
BINARY32 := fzf-$(GOOS)_386
|
||||||
BINARY64 := fzf-$(GOOS)_amd64$(SUFFIX)
|
BINARY64 := fzf-$(GOOS)_amd64
|
||||||
VERSION = $(shell fzf/$(BINARY64) --version)
|
VERSION = $(shell fzf/$(BINARY64) --version)
|
||||||
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386$(SUFFIX)
|
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386
|
||||||
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64$(SUFFIX)
|
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64
|
||||||
|
|
||||||
all: release
|
all: release
|
||||||
|
|
||||||
@@ -40,11 +29,7 @@ release: build
|
|||||||
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
||||||
rm -f $(RELEASE32) $(RELEASE64)
|
rm -f $(RELEASE32) $(RELEASE64)
|
||||||
|
|
||||||
ifndef STATIC
|
|
||||||
build: test fzf/$(BINARY32) fzf/$(BINARY64)
|
build: test fzf/$(BINARY32) fzf/$(BINARY64)
|
||||||
else
|
|
||||||
build: test fzf/$(BINARY64)
|
|
||||||
endif
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go get
|
go get
|
||||||
@@ -59,10 +44,10 @@ clean:
|
|||||||
cd fzf && rm -f fzf-*
|
cd fzf && rm -f fzf-*
|
||||||
|
|
||||||
fzf/$(BINARY32): $(SOURCES)
|
fzf/$(BINARY32): $(SOURCES)
|
||||||
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -o $(BINARY32)
|
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -a -o $(BINARY32)
|
||||||
|
|
||||||
fzf/$(BINARY64): $(SOURCES)
|
fzf/$(BINARY64): $(SOURCES)
|
||||||
cd fzf && go build $(LDFLAGS) -o $(BINARY64)
|
cd fzf && go build -a -tags "$(TAGS)" -o $(BINARY64)
|
||||||
|
|
||||||
$(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
$(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
||||||
cp -f fzf/$(BINARY64) $(BINDIR)
|
cp -f fzf/$(BINARY64) $(BINDIR)
|
||||||
@@ -77,6 +62,9 @@ docker-arch:
|
|||||||
docker-ubuntu:
|
docker-ubuntu:
|
||||||
docker build -t junegunn/ubuntu-sandbox - < Dockerfile.ubuntu
|
docker build -t junegunn/ubuntu-sandbox - < Dockerfile.ubuntu
|
||||||
|
|
||||||
|
docker-centos:
|
||||||
|
docker build -t junegunn/centos-sandbox - < Dockerfile.centos
|
||||||
|
|
||||||
arch: docker-arch
|
arch: docker-arch
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
||||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
||||||
@@ -85,13 +73,13 @@ ubuntu: docker-ubuntu
|
|||||||
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
||||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
||||||
|
|
||||||
linux: docker-arch
|
centos: docker-centos
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/arch-sandbox \
|
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
||||||
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make'
|
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
||||||
|
|
||||||
linux-static: docker-ubuntu
|
linux: docker-centos
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/ubuntu-sandbox \
|
docker run -i -t -v $(GOPATH):/go junegunn/centos-sandbox \
|
||||||
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make STATIC=1'
|
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make TAGS=static'
|
||||||
|
|
||||||
.PHONY: all build release test install uninstall clean docker \
|
.PHONY: all build release test install uninstall clean docker \
|
||||||
linux linux-static arch ubuntu docker-arch docker-ubuntu
|
linux arch ubuntu centos docker-arch docker-ubuntu docker-centos
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Current version
|
// Current version
|
||||||
version = "0.10.5"
|
version = "0.10.7"
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||||
@@ -47,3 +47,10 @@ const (
|
|||||||
EvtHeader
|
EvtHeader
|
||||||
EvtClose
|
EvtClose
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
exitOk = 0
|
||||||
|
exitNoMatch = 1
|
||||||
|
exitError = 2
|
||||||
|
exitInterrupt = 130
|
||||||
|
)
|
||||||
|
|||||||
17
src/core.go
17
src/core.go
@@ -56,7 +56,7 @@ func Run(opts *Options) {
|
|||||||
|
|
||||||
if opts.Version {
|
if opts.Version {
|
||||||
fmt.Println(version)
|
fmt.Println(version)
|
||||||
os.Exit(0)
|
os.Exit(exitOk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event channel
|
// Event channel
|
||||||
@@ -156,12 +156,14 @@ func Run(opts *Options) {
|
|||||||
|
|
||||||
pattern := patternBuilder([]rune(*opts.Filter))
|
pattern := patternBuilder([]rune(*opts.Filter))
|
||||||
|
|
||||||
|
found := false
|
||||||
if streamingFilter {
|
if streamingFilter {
|
||||||
reader := Reader{
|
reader := Reader{
|
||||||
func(runes []byte) bool {
|
func(runes []byte) bool {
|
||||||
item := chunkList.trans(runes, 0)
|
item := chunkList.trans(runes, 0)
|
||||||
if item != nil && pattern.MatchItem(item) {
|
if item != nil && pattern.MatchItem(item) {
|
||||||
fmt.Println(string(item.text))
|
fmt.Println(string(item.text))
|
||||||
|
found = true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}, eventBox, opts.ReadZero}
|
}, eventBox, opts.ReadZero}
|
||||||
@@ -176,9 +178,13 @@ func Run(opts *Options) {
|
|||||||
pattern: pattern})
|
pattern: pattern})
|
||||||
for i := 0; i < merger.Length(); i++ {
|
for i := 0; i < merger.Length(); i++ {
|
||||||
fmt.Println(merger.Get(i).AsString(opts.Ansi))
|
fmt.Println(merger.Get(i).AsString(opts.Ansi))
|
||||||
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
if found {
|
||||||
|
os.Exit(exitOk)
|
||||||
|
}
|
||||||
|
os.Exit(exitNoMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronous search
|
// Synchronous search
|
||||||
@@ -232,7 +238,7 @@ func Run(opts *Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case EvtHeader:
|
case EvtHeader:
|
||||||
terminal.UpdateHeader(value.([]string), opts.HeaderLines)
|
terminal.UpdateHeader(value.([]string))
|
||||||
|
|
||||||
case EvtSearchFin:
|
case EvtSearchFin:
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
@@ -253,7 +259,10 @@ func Run(opts *Options) {
|
|||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
fmt.Println(val.Get(i).AsString(opts.Ansi))
|
fmt.Println(val.Get(i).AsString(opts.Ansi))
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
if count > 0 {
|
||||||
|
os.Exit(exitOk)
|
||||||
|
}
|
||||||
|
os.Exit(exitNoMatch)
|
||||||
}
|
}
|
||||||
deferred = false
|
deferred = false
|
||||||
terminal.startChan <- true
|
terminal.startChan <- true
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package curses
|
|||||||
/*
|
/*
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#cgo LDFLAGS: -lncurses
|
#cgo !static LDFLAGS: -lncurses
|
||||||
|
#cgo static LDFLAGS: -l:libncurses.a -l:libtinfo.a -l:libgpm.a -ldl
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -261,7 +261,7 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
|
|||||||
_screen = C.newterm(nil, C.stderr, C.stdin)
|
_screen = C.newterm(nil, C.stderr, C.stdin)
|
||||||
if _screen == nil {
|
if _screen == nil {
|
||||||
fmt.Println("Invalid $TERM: " + os.Getenv("TERM"))
|
fmt.Println("Invalid $TERM: " + os.Getenv("TERM"))
|
||||||
os.Exit(1)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
C.set_term(_screen)
|
C.set_term(_screen)
|
||||||
if mouse {
|
if mouse {
|
||||||
@@ -270,14 +270,6 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
|
|||||||
C.noecho()
|
C.noecho()
|
||||||
C.raw() // stty dsusp undef
|
C.raw() // stty dsusp undef
|
||||||
|
|
||||||
intChan := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(intChan, os.Interrupt, os.Kill)
|
|
||||||
go func() {
|
|
||||||
<-intChan
|
|
||||||
Close()
|
|
||||||
os.Exit(1)
|
|
||||||
}()
|
|
||||||
|
|
||||||
if theme != nil {
|
if theme != nil {
|
||||||
C.start_color()
|
C.start_color()
|
||||||
initPairs(theme, black)
|
initPairs(theme, black)
|
||||||
|
|||||||
19
src/item.go
19
src/item.go
@@ -6,8 +6,8 @@ import (
|
|||||||
"github.com/junegunn/fzf/src/curses"
|
"github.com/junegunn/fzf/src/curses"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Offset holds two 32-bit integers denoting the offsets of a matched substring
|
// Offset holds three 32-bit integers denoting the offsets of a matched substring
|
||||||
type Offset [2]int32
|
type Offset [3]int32
|
||||||
|
|
||||||
type colorOffset struct {
|
type colorOffset struct {
|
||||||
offset [2]int32
|
offset [2]int32
|
||||||
@@ -43,10 +43,13 @@ func (item *Item) Rank(cache bool) Rank {
|
|||||||
}
|
}
|
||||||
matchlen := 0
|
matchlen := 0
|
||||||
prevEnd := 0
|
prevEnd := 0
|
||||||
|
lenSum := 0
|
||||||
minBegin := math.MaxUint16
|
minBegin := math.MaxUint16
|
||||||
for _, offset := range item.offsets {
|
for _, offset := range item.offsets {
|
||||||
begin := int(offset[0])
|
begin := int(offset[0])
|
||||||
end := int(offset[1])
|
end := int(offset[1])
|
||||||
|
trimLen := int(offset[2])
|
||||||
|
lenSum += trimLen
|
||||||
if prevEnd > begin {
|
if prevEnd > begin {
|
||||||
begin = prevEnd
|
begin = prevEnd
|
||||||
}
|
}
|
||||||
@@ -65,10 +68,7 @@ func (item *Item) Rank(cache bool) Rank {
|
|||||||
case byLength:
|
case byLength:
|
||||||
// It is guaranteed that .transformed in not null in normal execution
|
// It is guaranteed that .transformed in not null in normal execution
|
||||||
if item.transformed != nil {
|
if item.transformed != nil {
|
||||||
lenSum := 0
|
// If offsets is empty, lenSum will be 0, but we don't care
|
||||||
for _, token := range item.transformed {
|
|
||||||
lenSum += len(token.text)
|
|
||||||
}
|
|
||||||
tiebreak = uint16(lenSum)
|
tiebreak = uint16(lenSum)
|
||||||
} else {
|
} else {
|
||||||
tiebreak = uint16(len(item.text))
|
tiebreak = uint16(len(item.text))
|
||||||
@@ -116,7 +116,8 @@ func (item *Item) colorOffsets(color int, bold bool, current bool) []colorOffset
|
|||||||
if len(item.colors) == 0 {
|
if len(item.colors) == 0 {
|
||||||
var offsets []colorOffset
|
var offsets []colorOffset
|
||||||
for _, off := range item.offsets {
|
for _, off := range item.offsets {
|
||||||
offsets = append(offsets, colorOffset{offset: off, color: color, bold: bold})
|
|
||||||
|
offsets = append(offsets, colorOffset{offset: [2]int32{off[0], off[1]}, color: color, bold: bold})
|
||||||
}
|
}
|
||||||
return offsets
|
return offsets
|
||||||
}
|
}
|
||||||
@@ -160,7 +161,7 @@ func (item *Item) colorOffsets(color int, bold bool, current bool) []colorOffset
|
|||||||
if curr != 0 && idx > start {
|
if curr != 0 && idx > start {
|
||||||
if curr == -1 {
|
if curr == -1 {
|
||||||
offsets = append(offsets, colorOffset{
|
offsets = append(offsets, colorOffset{
|
||||||
offset: Offset{int32(start), int32(idx)}, color: color, bold: bold})
|
offset: [2]int32{int32(start), int32(idx)}, color: color, bold: bold})
|
||||||
} else {
|
} else {
|
||||||
ansi := item.colors[curr-1]
|
ansi := item.colors[curr-1]
|
||||||
fg := ansi.color.fg
|
fg := ansi.color.fg
|
||||||
@@ -180,7 +181,7 @@ func (item *Item) colorOffsets(color int, bold bool, current bool) []colorOffset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
offsets = append(offsets, colorOffset{
|
offsets = append(offsets, colorOffset{
|
||||||
offset: Offset{int32(start), int32(idx)},
|
offset: [2]int32{int32(start), int32(idx)},
|
||||||
color: curses.PairFor(fg, bg),
|
color: curses.PairFor(fg, bg),
|
||||||
bold: ansi.color.bold || bold})
|
bold: ansi.color.bold || bold})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -45,7 +44,7 @@ const usage = `usage: fzf [options]
|
|||||||
--bind=KEYBINDS Custom key bindings. Refer to the man page.
|
--bind=KEYBINDS Custom key bindings. Refer to the man page.
|
||||||
--history=FILE History file
|
--history=FILE History file
|
||||||
--history-size=N Maximum number of history entries (default: 1000)
|
--history-size=N Maximum number of history entries (default: 1000)
|
||||||
--header-file=FILE The file whose content to be printed as header
|
--header=STR String to print as header
|
||||||
--header-lines=N The first N lines of the input are treated as header
|
--header-lines=N The first N lines of the input are treated as header
|
||||||
|
|
||||||
Scripting
|
Scripting
|
||||||
@@ -180,14 +179,14 @@ func defaultOptions() *Options {
|
|||||||
Version: false}
|
Version: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
func help(ok int) {
|
func help(code int) {
|
||||||
os.Stderr.WriteString(usage)
|
os.Stderr.WriteString(usage)
|
||||||
os.Exit(ok)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorExit(msg string) {
|
func errorExit(msg string) {
|
||||||
os.Stderr.WriteString(msg + "\n")
|
os.Stderr.WriteString(msg + "\n")
|
||||||
os.Exit(1)
|
os.Exit(exitError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func optString(arg string, prefixes ...string) (bool, string) {
|
func optString(arg string, prefixes ...string) (bool, string) {
|
||||||
@@ -604,12 +603,8 @@ func checkToggleSort(keymap map[int]actionType, str string) map[int]actionType {
|
|||||||
return keymap
|
return keymap
|
||||||
}
|
}
|
||||||
|
|
||||||
func readHeaderFile(filename string) []string {
|
func strLines(str string) []string {
|
||||||
content, err := ioutil.ReadFile(filename)
|
return strings.Split(strings.TrimSuffix(str, "\n"), "\n")
|
||||||
if err != nil {
|
|
||||||
errorExit("failed to read header file: " + filename)
|
|
||||||
}
|
|
||||||
return strings.Split(strings.TrimSuffix(string(content), "\n"), "\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMargin(margin string) [4]string {
|
func parseMargin(margin string) [4]string {
|
||||||
@@ -682,7 +677,7 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
arg := allArgs[i]
|
arg := allArgs[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
case "-h", "--help":
|
case "-h", "--help":
|
||||||
help(0)
|
help(exitOk)
|
||||||
case "-x", "--extended":
|
case "-x", "--extended":
|
||||||
opts.Mode = ModeExtended
|
opts.Mode = ModeExtended
|
||||||
case "-e", "--extended-exact":
|
case "-e", "--extended-exact":
|
||||||
@@ -793,16 +788,13 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
setHistory(nextString(allArgs, &i, "history file path required"))
|
setHistory(nextString(allArgs, &i, "history file path required"))
|
||||||
case "--history-size":
|
case "--history-size":
|
||||||
setHistoryMax(nextInt(allArgs, &i, "history max size required"))
|
setHistoryMax(nextInt(allArgs, &i, "history max size required"))
|
||||||
case "--no-header-file":
|
case "--no-header":
|
||||||
opts.Header = []string{}
|
opts.Header = []string{}
|
||||||
case "--no-header-lines":
|
case "--no-header-lines":
|
||||||
opts.HeaderLines = 0
|
opts.HeaderLines = 0
|
||||||
case "--header-file":
|
case "--header":
|
||||||
opts.Header = readHeaderFile(
|
opts.Header = strLines(nextString(allArgs, &i, "header string required"))
|
||||||
nextString(allArgs, &i, "header file name required"))
|
|
||||||
opts.HeaderLines = 0
|
|
||||||
case "--header-lines":
|
case "--header-lines":
|
||||||
opts.Header = []string{}
|
|
||||||
opts.HeaderLines = atoi(
|
opts.HeaderLines = atoi(
|
||||||
nextString(allArgs, &i, "number of header lines required"))
|
nextString(allArgs, &i, "number of header lines required"))
|
||||||
case "--no-margin":
|
case "--no-margin":
|
||||||
@@ -843,11 +835,9 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
setHistory(value)
|
setHistory(value)
|
||||||
} else if match, value := optString(arg, "--history-size="); match {
|
} else if match, value := optString(arg, "--history-size="); match {
|
||||||
setHistoryMax(atoi(value))
|
setHistoryMax(atoi(value))
|
||||||
} else if match, value := optString(arg, "--header-file="); match {
|
} else if match, value := optString(arg, "--header="); match {
|
||||||
opts.Header = readHeaderFile(value)
|
opts.Header = strLines(value)
|
||||||
opts.HeaderLines = 0
|
|
||||||
} else if match, value := optString(arg, "--header-lines="); match {
|
} else if match, value := optString(arg, "--header-lines="); match {
|
||||||
opts.Header = []string{}
|
|
||||||
opts.HeaderLines = atoi(value)
|
opts.HeaderLines = atoi(value)
|
||||||
} else if match, value := optString(arg, "--margin="); match {
|
} else if match, value := optString(arg, "--margin="); match {
|
||||||
opts.Margin = parseMargin(value)
|
opts.Margin = parseMargin(value)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/algo"
|
"github.com/junegunn/fzf/src/algo"
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fuzzy
|
// fuzzy
|
||||||
@@ -251,9 +252,9 @@ func (p *Pattern) matchChunk(chunk *Chunk) []*Item {
|
|||||||
matches := []*Item{}
|
matches := []*Item{}
|
||||||
if p.mode == ModeFuzzy {
|
if p.mode == ModeFuzzy {
|
||||||
for _, item := range *chunk {
|
for _, item := range *chunk {
|
||||||
if sidx, eidx := p.fuzzyMatch(item); sidx >= 0 {
|
if sidx, eidx, tlen := p.fuzzyMatch(item); sidx >= 0 {
|
||||||
matches = append(matches,
|
matches = append(matches,
|
||||||
dupItem(item, []Offset{Offset{int32(sidx), int32(eidx)}}))
|
dupItem(item, []Offset{Offset{int32(sidx), int32(eidx), int32(tlen)}}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -269,7 +270,7 @@ func (p *Pattern) matchChunk(chunk *Chunk) []*Item {
|
|||||||
// MatchItem returns true if the Item is a match
|
// MatchItem returns true if the Item is a match
|
||||||
func (p *Pattern) MatchItem(item *Item) bool {
|
func (p *Pattern) MatchItem(item *Item) bool {
|
||||||
if p.mode == ModeFuzzy {
|
if p.mode == ModeFuzzy {
|
||||||
sidx, _ := p.fuzzyMatch(item)
|
sidx, _, _ := p.fuzzyMatch(item)
|
||||||
return sidx >= 0
|
return sidx >= 0
|
||||||
}
|
}
|
||||||
offsets := p.extendedMatch(item)
|
offsets := p.extendedMatch(item)
|
||||||
@@ -288,7 +289,7 @@ func dupItem(item *Item, offsets []Offset) *Item {
|
|||||||
rank: Rank{0, 0, item.index}}
|
rank: Rank{0, 0, item.index}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) fuzzyMatch(item *Item) (int, int) {
|
func (p *Pattern) fuzzyMatch(item *Item) (int, int, int) {
|
||||||
input := p.prepareInput(item)
|
input := p.prepareInput(item)
|
||||||
return p.iter(algo.FuzzyMatch, input, p.caseSensitive, p.forward, p.text)
|
return p.iter(algo.FuzzyMatch, input, p.caseSensitive, p.forward, p.text)
|
||||||
}
|
}
|
||||||
@@ -298,13 +299,13 @@ func (p *Pattern) extendedMatch(item *Item) []Offset {
|
|||||||
offsets := []Offset{}
|
offsets := []Offset{}
|
||||||
for _, term := range p.terms {
|
for _, term := range p.terms {
|
||||||
pfun := p.procFun[term.typ]
|
pfun := p.procFun[term.typ]
|
||||||
if sidx, eidx := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {
|
if sidx, eidx, tlen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {
|
||||||
if term.inv {
|
if term.inv {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
offsets = append(offsets, Offset{int32(sidx), int32(eidx)})
|
offsets = append(offsets, Offset{int32(sidx), int32(eidx), int32(tlen)})
|
||||||
} else if term.inv {
|
} else if term.inv {
|
||||||
offsets = append(offsets, Offset{0, 0})
|
offsets = append(offsets, Offset{0, 0, 0})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return offsets
|
return offsets
|
||||||
@@ -320,19 +321,19 @@ func (p *Pattern) prepareInput(item *Item) []Token {
|
|||||||
tokens := Tokenize(item.text, p.delimiter)
|
tokens := Tokenize(item.text, p.delimiter)
|
||||||
ret = Transform(tokens, p.nth)
|
ret = Transform(tokens, p.nth)
|
||||||
} else {
|
} else {
|
||||||
ret = []Token{Token{text: item.text, prefixLength: 0}}
|
ret = []Token{Token{text: item.text, prefixLength: 0, trimLength: util.TrimLen(item.text)}}
|
||||||
}
|
}
|
||||||
item.transformed = ret
|
item.transformed = ret
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) (int, int),
|
func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) (int, int),
|
||||||
tokens []Token, caseSensitive bool, forward bool, pattern []rune) (int, int) {
|
tokens []Token, caseSensitive bool, forward bool, pattern []rune) (int, int, int) {
|
||||||
for _, part := range tokens {
|
for _, part := range tokens {
|
||||||
prefixLength := part.prefixLength
|
prefixLength := part.prefixLength
|
||||||
if sidx, eidx := pfun(caseSensitive, forward, part.text, pattern); sidx >= 0 {
|
if sidx, eidx := pfun(caseSensitive, forward, part.text, pattern); sidx >= 0 {
|
||||||
return sidx + prefixLength, eidx + prefixLength
|
return sidx + prefixLength, eidx + prefixLength, part.trimLength
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1, -1
|
return -1, -1, -1 // math.MaxUint16
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ type Terminal struct {
|
|||||||
history *History
|
history *History
|
||||||
cycle bool
|
cycle bool
|
||||||
header []string
|
header []string
|
||||||
|
header0 []string
|
||||||
ansi bool
|
ansi bool
|
||||||
margin [4]string
|
margin [4]string
|
||||||
marginInt [4]int
|
marginInt [4]int
|
||||||
@@ -185,6 +186,12 @@ func defaultKeymap() map[int]actionType {
|
|||||||
// NewTerminal returns new Terminal object
|
// NewTerminal returns new Terminal object
|
||||||
func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||||
input := []rune(opts.Query)
|
input := []rune(opts.Query)
|
||||||
|
var header []string
|
||||||
|
if opts.Reverse {
|
||||||
|
header = opts.Header
|
||||||
|
} else {
|
||||||
|
header = reverseStringArray(opts.Header)
|
||||||
|
}
|
||||||
return &Terminal{
|
return &Terminal{
|
||||||
inlineInfo: opts.InlineInfo,
|
inlineInfo: opts.InlineInfo,
|
||||||
prompt: opts.Prompt,
|
prompt: opts.Prompt,
|
||||||
@@ -207,7 +214,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
margin: opts.Margin,
|
margin: opts.Margin,
|
||||||
marginInt: [4]int{0, 0, 0, 0},
|
marginInt: [4]int{0, 0, 0, 0},
|
||||||
cycle: opts.Cycle,
|
cycle: opts.Cycle,
|
||||||
header: opts.Header,
|
header: header,
|
||||||
|
header0: header,
|
||||||
ansi: opts.Ansi,
|
ansi: opts.Ansi,
|
||||||
reading: true,
|
reading: true,
|
||||||
merger: EmptyMerger,
|
merger: EmptyMerger,
|
||||||
@@ -241,18 +249,19 @@ func (t *Terminal) UpdateCount(cnt int, final bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateHeader updates the header
|
func reverseStringArray(input []string) []string {
|
||||||
func (t *Terminal) UpdateHeader(header []string, lines int) {
|
size := len(input)
|
||||||
t.mutex.Lock()
|
reversed := make([]string, size)
|
||||||
t.header = make([]string, lines)
|
for idx, str := range input {
|
||||||
copy(t.header, header)
|
reversed[size-idx-1] = str
|
||||||
if !t.reverse {
|
|
||||||
reversed := make([]string, lines)
|
|
||||||
for idx, str := range t.header {
|
|
||||||
reversed[lines-idx-1] = str
|
|
||||||
}
|
|
||||||
t.header = reversed
|
|
||||||
}
|
}
|
||||||
|
return reversed
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateHeader updates the header
|
||||||
|
func (t *Terminal) UpdateHeader(header []string) {
|
||||||
|
t.mutex.Lock()
|
||||||
|
t.header = append(append([]string{}, t.header0...), header...)
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
t.reqBox.Set(reqHeader, nil)
|
t.reqBox.Set(reqHeader, nil)
|
||||||
}
|
}
|
||||||
@@ -280,17 +289,19 @@ func (t *Terminal) UpdateList(merger *Merger) {
|
|||||||
t.reqBox.Set(reqList, nil)
|
t.reqBox.Set(reqList, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) output() {
|
func (t *Terminal) output() bool {
|
||||||
if t.printQuery {
|
if t.printQuery {
|
||||||
fmt.Println(string(t.input))
|
fmt.Println(string(t.input))
|
||||||
}
|
}
|
||||||
if len(t.expect) > 0 {
|
if len(t.expect) > 0 {
|
||||||
fmt.Println(t.pressed)
|
fmt.Println(t.pressed)
|
||||||
}
|
}
|
||||||
if len(t.selected) == 0 {
|
found := len(t.selected) > 0
|
||||||
|
if !found {
|
||||||
cnt := t.merger.Length()
|
cnt := t.merger.Length()
|
||||||
if cnt > 0 && cnt > t.cy {
|
if cnt > 0 && cnt > t.cy {
|
||||||
fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
|
fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
|
||||||
|
found = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sels := make([]selectedItem, 0, len(t.selected))
|
sels := make([]selectedItem, 0, len(t.selected))
|
||||||
@@ -302,6 +313,7 @@ func (t *Terminal) output() {
|
|||||||
fmt.Println(*sel.text)
|
fmt.Println(*sel.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
func runeWidth(r rune, prefixWidth int) int {
|
func runeWidth(r rune, prefixWidth int) int {
|
||||||
@@ -433,9 +445,6 @@ func (t *Terminal) printHeader() {
|
|||||||
max := t.maxHeight()
|
max := t.maxHeight()
|
||||||
var state *ansiState
|
var state *ansiState
|
||||||
for idx, lineStr := range t.header {
|
for idx, lineStr := range t.header {
|
||||||
if !t.reverse {
|
|
||||||
idx = len(t.header) - idx - 1
|
|
||||||
}
|
|
||||||
line := idx + 2
|
line := idx + 2
|
||||||
if t.inlineInfo {
|
if t.inlineInfo {
|
||||||
line--
|
line--
|
||||||
@@ -718,6 +727,13 @@ func (t *Terminal) Loop() {
|
|||||||
t.reqBox.Set(reqRefresh, nil)
|
t.reqBox.Set(reqRefresh, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
intChan := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(intChan, os.Interrupt, os.Kill)
|
||||||
|
go func() {
|
||||||
|
<-intChan
|
||||||
|
t.reqBox.Set(reqQuit, nil)
|
||||||
|
}()
|
||||||
|
|
||||||
resizeChan := make(chan os.Signal, 1)
|
resizeChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(resizeChan, syscall.SIGWINCH)
|
signal.Notify(resizeChan, syscall.SIGWINCH)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -743,7 +759,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit := func(code int) {
|
exit := func(code int) {
|
||||||
if code == 0 && t.history != nil {
|
if code <= exitNoMatch && t.history != nil {
|
||||||
t.history.append(string(t.input))
|
t.history.append(string(t.input))
|
||||||
}
|
}
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
@@ -776,11 +792,13 @@ func (t *Terminal) Loop() {
|
|||||||
t.printAll()
|
t.printAll()
|
||||||
case reqClose:
|
case reqClose:
|
||||||
C.Close()
|
C.Close()
|
||||||
t.output()
|
if t.output() {
|
||||||
exit(0)
|
exit(exitOk)
|
||||||
|
}
|
||||||
|
exit(exitNoMatch)
|
||||||
case reqQuit:
|
case reqQuit:
|
||||||
C.Close()
|
C.Close()
|
||||||
exit(1)
|
exit(exitInterrupt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.placeCursor()
|
t.placeCursor()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Range struct {
|
|||||||
type Token struct {
|
type Token struct {
|
||||||
text []rune
|
text []rune
|
||||||
prefixLength int
|
prefixLength int
|
||||||
|
trimLength int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delimiter for tokenizing the input
|
// Delimiter for tokenizing the input
|
||||||
@@ -81,7 +82,7 @@ func withPrefixLengths(tokens [][]rune, begin int) []Token {
|
|||||||
for idx, token := range tokens {
|
for idx, token := range tokens {
|
||||||
// Need to define a new local variable instead of the reused token to take
|
// Need to define a new local variable instead of the reused token to take
|
||||||
// the pointer to it
|
// the pointer to it
|
||||||
ret[idx] = Token{text: token, prefixLength: prefixLength}
|
ret[idx] = Token{token, prefixLength, util.TrimLen(token)}
|
||||||
prefixLength += len(token)
|
prefixLength += len(token)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
@@ -233,7 +234,7 @@ func Transform(tokens []Token, withNth []Range) []Token {
|
|||||||
} else {
|
} else {
|
||||||
prefixLength = 0
|
prefixLength = 0
|
||||||
}
|
}
|
||||||
transTokens[idx] = Token{part, prefixLength}
|
transTokens[idx] = Token{part, prefixLength, util.TrimLen(part)}
|
||||||
}
|
}
|
||||||
return transTokens
|
return transTokens
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,22 +44,22 @@ func TestTokenize(t *testing.T) {
|
|||||||
// AWK-style
|
// AWK-style
|
||||||
input := " abc: def: ghi "
|
input := " abc: def: ghi "
|
||||||
tokens := Tokenize([]rune(input), Delimiter{})
|
tokens := Tokenize([]rune(input), Delimiter{})
|
||||||
if string(tokens[0].text) != "abc: " || tokens[0].prefixLength != 2 {
|
if string(tokens[0].text) != "abc: " || tokens[0].prefixLength != 2 || tokens[0].trimLength != 4 {
|
||||||
t.Errorf("%s", tokens)
|
t.Errorf("%s", tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With delimiter
|
// With delimiter
|
||||||
tokens = Tokenize([]rune(input), delimiterRegexp(":"))
|
tokens = Tokenize([]rune(input), delimiterRegexp(":"))
|
||||||
if string(tokens[0].text) != " abc:" || tokens[0].prefixLength != 0 {
|
if string(tokens[0].text) != " abc:" || tokens[0].prefixLength != 0 || tokens[0].trimLength != 4 {
|
||||||
t.Errorf("%s", tokens)
|
t.Errorf("%s", tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With delimiter regex
|
// With delimiter regex
|
||||||
tokens = Tokenize([]rune(input), delimiterRegexp("\\s+"))
|
tokens = Tokenize([]rune(input), delimiterRegexp("\\s+"))
|
||||||
if string(tokens[0].text) != " " || tokens[0].prefixLength != 0 ||
|
if string(tokens[0].text) != " " || tokens[0].prefixLength != 0 || tokens[0].trimLength != 0 ||
|
||||||
string(tokens[1].text) != "abc: " || tokens[1].prefixLength != 2 ||
|
string(tokens[1].text) != "abc: " || tokens[1].prefixLength != 2 || tokens[1].trimLength != 4 ||
|
||||||
string(tokens[2].text) != "def: " || tokens[2].prefixLength != 8 ||
|
string(tokens[2].text) != "def: " || tokens[2].prefixLength != 8 || tokens[2].trimLength != 4 ||
|
||||||
string(tokens[3].text) != "ghi " || tokens[3].prefixLength != 14 {
|
string(tokens[3].text) != "ghi " || tokens[3].prefixLength != 14 || tokens[3].trimLength != 3 {
|
||||||
t.Errorf("%s", tokens)
|
t.Errorf("%s", tokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func IsTty() bool {
|
|||||||
return int(C.isatty(C.int(os.Stdin.Fd()))) != 0
|
return int(C.isatty(C.int(os.Stdin.Fd()))) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TrimRight returns rune array with trailing white spaces cut off
|
||||||
func TrimRight(runes []rune) []rune {
|
func TrimRight(runes []rune) []rune {
|
||||||
var i int
|
var i int
|
||||||
for i = len(runes) - 1; i >= 0; i-- {
|
for i = len(runes) - 1; i >= 0; i-- {
|
||||||
@@ -86,6 +87,7 @@ func TrimRight(runes []rune) []rune {
|
|||||||
return runes[0 : i+1]
|
return runes[0 : i+1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BytesToRunes converts byte array into rune array
|
||||||
func BytesToRunes(bytea []byte) []rune {
|
func BytesToRunes(bytea []byte) []rune {
|
||||||
runes := make([]rune, 0, len(bytea))
|
runes := make([]rune, 0, len(bytea))
|
||||||
for i := 0; i < len(bytea); {
|
for i := 0; i < len(bytea); {
|
||||||
@@ -100,3 +102,27 @@ func BytesToRunes(bytea []byte) []rune {
|
|||||||
}
|
}
|
||||||
return runes
|
return runes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TrimLen returns the length of trimmed rune array
|
||||||
|
func TrimLen(runes []rune) int {
|
||||||
|
var i int
|
||||||
|
for i = len(runes) - 1; i >= 0; i-- {
|
||||||
|
char := runes[i]
|
||||||
|
if char != ' ' && char != '\t' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Completely empty
|
||||||
|
if i < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var j int
|
||||||
|
for j = 0; j < len(runes); j++ {
|
||||||
|
char := runes[j]
|
||||||
|
if char != ' ' && char != '\t' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i - j + 1
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,3 +20,23 @@ func TestContrain(t *testing.T) {
|
|||||||
t.Error("Expected", 3)
|
t.Error("Expected", 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTrimLen(t *testing.T) {
|
||||||
|
check := func(str string, exp int) {
|
||||||
|
trimmed := TrimLen([]rune(str))
|
||||||
|
if trimmed != exp {
|
||||||
|
t.Errorf("Invalid TrimLen result for '%s': %d (expected %d)",
|
||||||
|
str, trimmed, exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
check("hello", 5)
|
||||||
|
check("hello ", 5)
|
||||||
|
check("hello ", 5)
|
||||||
|
check(" hello", 5)
|
||||||
|
check(" hello", 5)
|
||||||
|
check(" hello ", 5)
|
||||||
|
check(" hello ", 5)
|
||||||
|
check("h o", 5)
|
||||||
|
check(" h o ", 5)
|
||||||
|
check(" ", 0)
|
||||||
|
}
|
||||||
|
|||||||
121
test/test_go.rb
121
test/test_go.rb
@@ -527,6 +527,53 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal output, `cat #{tempname} | #{FZF} -fh -n2 -d:`.split($/)
|
assert_equal output, `cat #{tempname} | #{FZF} -fh -n2 -d:`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_tiebreak_length_with_nth_trim_length
|
||||||
|
input = [
|
||||||
|
"apple juice bottle 1",
|
||||||
|
"apple ui bottle 2",
|
||||||
|
"app ice bottle 3",
|
||||||
|
"app ic bottle 4",
|
||||||
|
]
|
||||||
|
writelines tempname, input
|
||||||
|
|
||||||
|
# len(1)
|
||||||
|
output = [
|
||||||
|
"app ice bottle 3",
|
||||||
|
"app ic bottle 4",
|
||||||
|
"apple juice bottle 1",
|
||||||
|
"apple ui bottle 2",
|
||||||
|
]
|
||||||
|
assert_equal output, `cat #{tempname} | #{FZF} -fa -n1`.split($/)
|
||||||
|
|
||||||
|
# len(1 ~ 2)
|
||||||
|
output = [
|
||||||
|
"apple ui bottle 2",
|
||||||
|
"app ic bottle 4",
|
||||||
|
"apple juice bottle 1",
|
||||||
|
"app ice bottle 3",
|
||||||
|
]
|
||||||
|
assert_equal output, `cat #{tempname} | #{FZF} -fai -n1..2`.split($/)
|
||||||
|
|
||||||
|
# len(1) + len(2)
|
||||||
|
output = [
|
||||||
|
"app ic bottle 4",
|
||||||
|
"app ice bottle 3",
|
||||||
|
"apple ui bottle 2",
|
||||||
|
"apple juice bottle 1",
|
||||||
|
]
|
||||||
|
assert_equal output, `cat #{tempname} | #{FZF} -x -f"a i" -n1,2`.split($/)
|
||||||
|
|
||||||
|
# len(2)
|
||||||
|
output = [
|
||||||
|
"apple ui bottle 2",
|
||||||
|
"app ic bottle 4",
|
||||||
|
"app ice bottle 3",
|
||||||
|
"apple juice bottle 1",
|
||||||
|
]
|
||||||
|
assert_equal output, `cat #{tempname} | #{FZF} -fi -n2`.split($/)
|
||||||
|
assert_equal output, `cat #{tempname} | #{FZF} -fi -n2,1..2`.split($/)
|
||||||
|
end
|
||||||
|
|
||||||
def test_tiebreak_end_backward_scan
|
def test_tiebreak_end_backward_scan
|
||||||
input = %w[
|
input = %w[
|
||||||
foobar-fb
|
foobar-fb
|
||||||
@@ -737,8 +784,8 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal '6', readonce.chomp
|
assert_equal '6', readonce.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header_file
|
def test_header
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header-file <(head -5 #{__FILE__})"}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[-2].include?('100/100') &&
|
lines[-2].include?('100/100') &&
|
||||||
@@ -746,8 +793,8 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header_file_reverse
|
def test_header_reverse
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header-file=<(head -5 #{__FILE__}) --reverse"}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{__FILE__})\\\" --reverse"}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[1].include?('100/100') &&
|
lines[1].include?('100/100') &&
|
||||||
@@ -755,6 +802,26 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_header_and_header_lines
|
||||||
|
tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
||||||
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
|
tmux.until do |lines|
|
||||||
|
lines[-2].include?('90/90') &&
|
||||||
|
lines[-7...-2].map(&:strip) == header &&
|
||||||
|
lines[-17...-7].map(&:strip) == (1..10).map(&:to_s).reverse
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_header_and_header_lines_reverse
|
||||||
|
tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
||||||
|
header = File.readlines(__FILE__).take(5).map(&:strip)
|
||||||
|
tmux.until do |lines|
|
||||||
|
lines[1].include?('90/90') &&
|
||||||
|
lines[2...7].map(&:strip) == header &&
|
||||||
|
lines[7...17].map(&:strip) == (1..10).map(&:to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_canel
|
def test_canel
|
||||||
tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
|
tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
|
||||||
tmux.until { |lines| lines[-2].include?('10/10') }
|
tmux.until { |lines| lines[-2].include?('10/10') }
|
||||||
@@ -780,11 +847,6 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_term
|
|
||||||
tmux.send_keys "TERM=xxx fzf", :Enter
|
|
||||||
tmux.until { |lines| lines.any? { |l| l.include? 'Invalid $TERM: xxx' } }
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_nth
|
def test_with_nth
|
||||||
writelines tempname, ['hello world ', 'byebye']
|
writelines tempname, ['hello world ', 'byebye']
|
||||||
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
||||||
@@ -801,6 +863,47 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp
|
assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_exit_0_exit_code
|
||||||
|
`echo foo | #{FZF} -q bar -0`
|
||||||
|
assert_equal 1, $?.exitstatus
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_term
|
||||||
|
lines = `TERM=xxx #{FZF}`
|
||||||
|
assert_equal 2, $?.exitstatus
|
||||||
|
assert lines.include?('Invalid $TERM: xxx')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invalid_option
|
||||||
|
lines = `#{FZF} --foobar 2>&1`
|
||||||
|
assert_equal 2, $?.exitstatus
|
||||||
|
assert lines.include?('unknown option: --foobar'), lines
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_filter_exitstatus
|
||||||
|
# filter / streaming filter
|
||||||
|
["", "--no-sort"].each do |opts|
|
||||||
|
assert `echo foo | #{FZF} -f foo #{opts}`.include?('foo')
|
||||||
|
assert_equal 0, $?.exitstatus
|
||||||
|
|
||||||
|
assert `echo foo | #{FZF} -f bar #{opts}`.empty?
|
||||||
|
assert_equal 1, $?.exitstatus
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_exitstatus_empty
|
||||||
|
{ '99' => '0', '999' => '1' }.each do |query, status|
|
||||||
|
tmux.send_keys "seq 100 | #{FZF} -q #{query}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2] =~ %r{ [10]/100} }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
|
||||||
|
tmux.send_keys 'echo --\$?--'
|
||||||
|
tmux.until { |lines| lines.last.include? "echo --$?--" }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines.last.include? "--#{status}--" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def writelines path, lines
|
def writelines path, lines
|
||||||
File.unlink path while File.exists? path
|
File.unlink path while File.exists? path
|
||||||
|
|||||||
Reference in New Issue
Block a user