mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-13 22:03:47 -05:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a2d9ad947 | ||
|
|
90b0cd44ac | ||
|
|
698e8008df | ||
|
|
1de4cc3ba8 | ||
|
|
0d66ad23c6 | ||
|
|
7f7741099b | ||
|
|
5a72dc6922 | ||
|
|
80ed02e72e | ||
|
|
8fb31e1b4d | ||
|
|
148f21415a | ||
|
|
1c31e07d34 | ||
|
|
55d566b72f | ||
|
|
60336c7423 | ||
|
|
7ae877bd3a | ||
|
|
c601fc6437 | ||
|
|
e5fec408c4 |
@@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.10.4
|
||||||
|
------
|
||||||
|
|
||||||
|
- Fixed to remove ANSI code from output when `--with-nth` is set
|
||||||
|
|
||||||
0.10.3
|
0.10.3
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|||||||
77
README.md
77
README.md
@@ -254,6 +254,9 @@ export FZF_COMPLETION_OPTS='+c -x'
|
|||||||
Usage as Vim plugin
|
Usage as Vim plugin
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
This repository only enables basic integration with Vim. If you're looking for
|
||||||
|
more, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
||||||
|
|
||||||
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
||||||
|
|
||||||
#### `:FZF[!]`
|
#### `:FZF[!]`
|
||||||
@@ -286,10 +289,8 @@ customization.
|
|||||||
|
|
||||||
#### `fzf#run([options])`
|
#### `fzf#run([options])`
|
||||||
|
|
||||||
For more advanced uses, you can call `fzf#run()` function which returns the list
|
For more advanced uses, you can use `fzf#run()` function with the following
|
||||||
of the selected items.
|
options.
|
||||||
|
|
||||||
`fzf#run()` may take an options-dictionary:
|
|
||||||
|
|
||||||
| Option name | Type | Description |
|
| Option name | Type | Description |
|
||||||
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
||||||
@@ -305,65 +306,7 @@ of the selected items.
|
|||||||
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
|
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
|
||||||
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |
|
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |
|
||||||
|
|
||||||
_However on Neovim `fzf#run` is asynchronous and does not return values so you
|
Examples can be found on [the wiki
|
||||||
should use `sink` or `sink*` to process the output from fzf._
|
|
||||||
|
|
||||||
##### Examples
|
|
||||||
|
|
||||||
If `sink` option is not given, `fzf#run` will simply return the list.
|
|
||||||
|
|
||||||
```vim
|
|
||||||
let items = fzf#run({ 'options': '-m +c', 'dir': '~', 'source': 'ls' })
|
|
||||||
```
|
|
||||||
|
|
||||||
But if `sink` is given as a string, the command will be executed for each
|
|
||||||
selected item.
|
|
||||||
|
|
||||||
```vim
|
|
||||||
" Each selected item will be opened in a new tab
|
|
||||||
let items = fzf#run({ 'sink': 'tabe', 'options': '-m +c', 'dir': '~', 'source': 'ls' })
|
|
||||||
```
|
|
||||||
|
|
||||||
We can also use a Vim list as the source as follows:
|
|
||||||
|
|
||||||
```vim
|
|
||||||
" Choose a color scheme with fzf
|
|
||||||
nnoremap <silent> <Leader>C :call fzf#run({
|
|
||||||
\ 'source':
|
|
||||||
\ map(split(globpath(&rtp, "colors/*.vim"), "\n"),
|
|
||||||
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
|
||||||
\ 'sink': 'colo',
|
|
||||||
\ 'options': '+m',
|
|
||||||
\ 'left': 20,
|
|
||||||
\ 'launcher': 'xterm -geometry 20x30 -e bash -ic %s'
|
|
||||||
\ })<CR>
|
|
||||||
```
|
|
||||||
|
|
||||||
`sink` option can be a function reference. The following example creates a
|
|
||||||
handy mapping that selects an open buffer.
|
|
||||||
|
|
||||||
```vim
|
|
||||||
" List of buffers
|
|
||||||
function! s:buflist()
|
|
||||||
redir => ls
|
|
||||||
silent ls
|
|
||||||
redir END
|
|
||||||
return split(ls, '\n')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:bufopen(e)
|
|
||||||
execute 'buffer' matchstr(a:e, '^[ 0-9]*')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
nnoremap <silent> <Leader><Enter> :call fzf#run({
|
|
||||||
\ 'source': reverse(<sid>buflist()),
|
|
||||||
\ 'sink': function('<sid>bufopen'),
|
|
||||||
\ 'options': '+m',
|
|
||||||
\ 'down': len(<sid>buflist()) + 2
|
|
||||||
\ })<CR>
|
|
||||||
```
|
|
||||||
|
|
||||||
More examples can be found on [the wiki
|
|
||||||
page](https://github.com/junegunn/fzf/wiki/Examples-(vim)).
|
page](https://github.com/junegunn/fzf/wiki/Examples-(vim)).
|
||||||
|
|
||||||
Tips
|
Tips
|
||||||
@@ -425,14 +368,6 @@ of fzf to a temporary file.
|
|||||||
fzf > $TMPDIR/fzf.result; and vim (cat $TMPDIR/fzf.result)
|
fzf > $TMPDIR/fzf.result; and vim (cat $TMPDIR/fzf.result)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Handling UTF-8 NFD paths on OSX
|
|
||||||
|
|
||||||
Use iconv to convert NFD paths to NFC:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
find . | iconv -f utf-8-mac -t utf8//ignore | fzf
|
|
||||||
```
|
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|||||||
30
install
30
install
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
[[ "$@" =~ --pre ]] && version=0.10.3 pre=1 ||
|
[[ "$@" =~ --pre ]] && version=0.10.4 pre=1 ||
|
||||||
version=0.10.3 pre=0
|
version=0.10.4 pre=0
|
||||||
|
|
||||||
cd $(dirname $BASH_SOURCE)
|
cd $(dirname $BASH_SOURCE)
|
||||||
fzf_base=$(pwd)
|
fzf_base=$(pwd)
|
||||||
@@ -21,16 +21,21 @@ ask() {
|
|||||||
|
|
||||||
check_binary() {
|
check_binary() {
|
||||||
echo -n " - Checking fzf executable ... "
|
echo -n " - Checking fzf executable ... "
|
||||||
local output=$("$fzf_base"/bin/fzf --version 2>&1)
|
local output
|
||||||
if [ "$version" = "$output" ]; then
|
output=$("$fzf_base"/bin/fzf --version 2>&1)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error: $output"
|
||||||
|
binary_error="Invalid binary"
|
||||||
|
elif [ "$version" != "$output" ]; then
|
||||||
|
echo "$output != $version"
|
||||||
|
binary_error="Invalid version"
|
||||||
|
else
|
||||||
echo "$output"
|
echo "$output"
|
||||||
binary_error=""
|
binary_error=""
|
||||||
else
|
return 0
|
||||||
echo "$output != $version"
|
|
||||||
rm -f "$fzf_base"/bin/fzf
|
|
||||||
binary_error="Invalid binary"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
rm -f "$fzf_base"/bin/fzf
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
symlink() {
|
symlink() {
|
||||||
@@ -75,7 +80,12 @@ download() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x $1 && symlink $1 && check_binary
|
chmod +x $1 && symlink $1 || return 1
|
||||||
|
if [[ $1 =~ linux_amd64$ ]]; then
|
||||||
|
check_binary || download $1-static
|
||||||
|
else
|
||||||
|
check_binary
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Try to download binary executable
|
# Try to download binary executable
|
||||||
|
|||||||
@@ -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 "Aug 2015" "fzf 0.10.3" "fzf - a command-line fuzzy finder"
|
.TH fzf 1 "Aug 2015" "fzf 0.10.4" "fzf - a command-line fuzzy finder"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf - a command-line fuzzy finder
|
fzf - a command-line fuzzy finder
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function! s:shellesc(arg)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:escape(path)
|
function! s:escape(path)
|
||||||
return escape(a:path, ' %#\')
|
return escape(a:path, ' %#''"\')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Upgrade legacy options
|
" Upgrade legacy options
|
||||||
@@ -164,7 +164,13 @@ function! s:fzf_tmux(dict)
|
|||||||
let size = ''
|
let size = ''
|
||||||
for o in ['up', 'down', 'left', 'right']
|
for o in ['up', 'down', 'left', 'right']
|
||||||
if s:present(a:dict, o)
|
if s:present(a:dict, o)
|
||||||
let size = '-'.o[0].(a:dict[o] == 1 ? '' : a:dict[o])
|
let spec = a:dict[o]
|
||||||
|
if (o == 'up' || o == 'down') && spec[0] == '~'
|
||||||
|
let size = '-'.o[0].s:calc_size(&lines, spec[1:], a:dict)
|
||||||
|
else
|
||||||
|
" Legacy boolean option
|
||||||
|
let size = '-'.o[0].(spec == 1 ? '' : spec)
|
||||||
|
endif
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@@ -218,7 +224,7 @@ function! s:execute(dict, command, temps)
|
|||||||
else
|
else
|
||||||
let command = a:command
|
let command = a:command
|
||||||
endif
|
endif
|
||||||
execute 'silent !'.command
|
execute 'silent !'.escape(command, '%#')
|
||||||
redraw!
|
redraw!
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
" Do not print error message on exit status 1
|
" Do not print error message on exit status 1
|
||||||
@@ -244,12 +250,21 @@ function! s:execute_tmux(dict, command, temps)
|
|||||||
return s:callback(a:dict, a:temps)
|
return s:callback(a:dict, a:temps)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:calc_size(max, val)
|
function! s:calc_size(max, val, dict)
|
||||||
if a:val =~ '%$'
|
if a:val =~ '%$'
|
||||||
return a:max * str2nr(a:val[:-2]) / 100
|
let size = a:max * str2nr(a:val[:-2]) / 100
|
||||||
else
|
else
|
||||||
return min([a:max, a:val])
|
let size = min([a:max, str2nr(a:val)])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let srcsz = -1
|
||||||
|
if type(get(a:dict, 'source', 0)) == type([])
|
||||||
|
let srcsz = len(a:dict.source)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS
|
||||||
|
let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2
|
||||||
|
return srcsz >= 0 ? min([srcsz + margin, size]) : size
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:getpos()
|
function! s:getpos()
|
||||||
@@ -268,7 +283,11 @@ function! s:split(dict)
|
|||||||
let val = get(a:dict, dir, '')
|
let val = get(a:dict, dir, '')
|
||||||
if !empty(val)
|
if !empty(val)
|
||||||
let [cmd, resz, max] = triple
|
let [cmd, resz, max] = triple
|
||||||
let sz = s:calc_size(max, val)
|
if (dir == 'up' || dir == 'down') && val[0] == '~'
|
||||||
|
let sz = s:calc_size(max, val[1:], a:dict)
|
||||||
|
else
|
||||||
|
let sz = s:calc_size(max, val, {})
|
||||||
|
endif
|
||||||
execute cmd sz.'new'
|
execute cmd sz.'new'
|
||||||
execute resz sz
|
execute resz sz
|
||||||
return
|
return
|
||||||
@@ -358,7 +377,7 @@ endfunction
|
|||||||
|
|
||||||
let s:default_action = {
|
let s:default_action = {
|
||||||
\ 'ctrl-m': 'e',
|
\ 'ctrl-m': 'e',
|
||||||
\ 'ctrl-t': 'tabedit',
|
\ 'ctrl-t': 'tab split',
|
||||||
\ 'ctrl-x': 'split',
|
\ 'ctrl-x': 'split',
|
||||||
\ 'ctrl-v': 'vsplit' }
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
@@ -384,7 +403,7 @@ function! s:cmd(bang, ...) abort
|
|||||||
let args = extend(['--expect='.join(keys(s:action), ',')], a:000)
|
let args = extend(['--expect='.join(keys(s:action), ',')], a:000)
|
||||||
let opts = {}
|
let opts = {}
|
||||||
if len(args) > 0 && isdirectory(expand(args[-1]))
|
if len(args) > 0 && isdirectory(expand(args[-1]))
|
||||||
let opts.dir = remove(args, -1)
|
let opts.dir = substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g')
|
||||||
endif
|
endif
|
||||||
if !a:bang
|
if !a:bang
|
||||||
let opts.down = get(g:, 'fzf_height', get(g:, 'fzf_tmux_height', s:default_height))
|
let opts.down = get(g:, 'fzf_height', get(g:, 'fzf_tmux_height', s:default_height))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ FROM base/archlinux:2014.07.03
|
|||||||
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
||||||
|
|
||||||
# apt-get
|
# apt-get
|
||||||
|
RUN pacman-key --populate archlinux && pacman-key --refresh-keys
|
||||||
RUN pacman-db-upgrade && pacman -Syu --noconfirm base-devel git
|
RUN pacman-db-upgrade && pacman -Syu --noconfirm base-devel git
|
||||||
|
|
||||||
# Install Go 1.4
|
# Install Go 1.4
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
|||||||
|
|
||||||
# apt-get
|
# apt-get
|
||||||
RUN apt-get update && apt-get -y upgrade && \
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
apt-get install -y --force-yes git curl build-essential libncurses-dev
|
apt-get install -y --force-yes git curl build-essential libncurses-dev libgpm-dev
|
||||||
|
|
||||||
# Install Go 1.4
|
# Install Go 1.4
|
||||||
RUN cd / && curl \
|
RUN cd / && curl \
|
||||||
|
|||||||
65
src/Makefile
65
src/Makefile
@@ -5,8 +5,19 @@ 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)
|
||||||
@@ -16,21 +27,24 @@ endif
|
|||||||
SOURCES := $(wildcard *.go */*.go)
|
SOURCES := $(wildcard *.go */*.go)
|
||||||
BINDIR := ../bin
|
BINDIR := ../bin
|
||||||
|
|
||||||
BINARY32 := fzf-$(GOOS)_386
|
BINARY32 := fzf-$(GOOS)_386$(SUFFIX)
|
||||||
BINARY64 := fzf-$(GOOS)_amd64
|
BINARY64 := fzf-$(GOOS)_amd64$(SUFFIX)
|
||||||
VERSION = $(shell fzf/$(BINARY64) --version)
|
VERSION = $(shell fzf/$(BINARY64) --version)
|
||||||
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386
|
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386$(SUFFIX)
|
||||||
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64
|
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64$(SUFFIX)
|
||||||
|
|
||||||
all: release
|
all: release
|
||||||
|
|
||||||
release: build
|
release: build
|
||||||
cd fzf && \
|
-cd fzf && cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32)
|
||||||
cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32) && \
|
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
||||||
cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
rm -f $(RELEASE32) $(RELEASE64)
|
||||||
rm $(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
|
||||||
@@ -42,13 +56,13 @@ uninstall:
|
|||||||
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY64)
|
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY64)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd fzf && rm -f $(BINARY32) $(BINARY64) $(RELEASE32).tgz $(RELEASE64).tgz
|
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 -o $(BINARY32)
|
||||||
|
|
||||||
fzf/$(BINARY64): $(SOURCES)
|
fzf/$(BINARY64): $(SOURCES)
|
||||||
cd fzf && go build -o $(BINARY64)
|
cd fzf && go build $(LDFLAGS) -o $(BINARY64)
|
||||||
|
|
||||||
$(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
$(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
||||||
cp -f fzf/$(BINARY64) $(BINDIR)
|
cp -f fzf/$(BINARY64) $(BINDIR)
|
||||||
@@ -57,18 +71,27 @@ $(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
|||||||
$(BINDIR):
|
$(BINDIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
# Linux distribution to build fzf on
|
docker-arch:
|
||||||
DISTRO := arch
|
docker build -t junegunn/arch-sandbox - < Dockerfile.arch
|
||||||
|
|
||||||
docker:
|
docker-ubuntu:
|
||||||
docker build -t junegunn/$(DISTRO)-sandbox - < Dockerfile.$(DISTRO)
|
docker build -t junegunn/ubuntu-sandbox - < Dockerfile.ubuntu
|
||||||
|
|
||||||
linux: docker
|
arch: docker-arch
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$(DISTRO)-sandbox \
|
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
||||||
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make'
|
|
||||||
|
|
||||||
$(DISTRO): docker
|
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$(DISTRO)-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'
|
||||||
|
|
||||||
.PHONY: all build release test install uninstall clean docker linux $(DISTRO)
|
ubuntu: docker-ubuntu
|
||||||
|
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
||||||
|
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
||||||
|
|
||||||
|
linux: docker-arch
|
||||||
|
docker run -i -t -v $(GOPATH):/go junegunn/arch-sandbox \
|
||||||
|
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make'
|
||||||
|
|
||||||
|
linux-static: docker-ubuntu
|
||||||
|
docker run -i -t -v $(GOPATH):/go junegunn/ubuntu-sandbox \
|
||||||
|
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make STATIC=1'
|
||||||
|
|
||||||
|
.PHONY: all build release test install uninstall clean docker \
|
||||||
|
linux linux-static arch ubuntu docker-arch docker-ubuntu
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Current version
|
// Current version
|
||||||
version = "0.10.3"
|
version = "0.10.4"
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ func Run(opts *Options) {
|
|||||||
chunks: snapshot,
|
chunks: snapshot,
|
||||||
pattern: pattern})
|
pattern: pattern})
|
||||||
for i := 0; i < merger.Length(); i++ {
|
for i := 0; i < merger.Length(); i++ {
|
||||||
fmt.Println(merger.Get(i).AsString())
|
fmt.Println(merger.Get(i).AsString(opts.Ansi))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -250,7 +250,7 @@ func Run(opts *Options) {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
fmt.Println(val.Get(i).AsString())
|
fmt.Println(val.Get(i).AsString(opts.Ansi))
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/item.go
16
src/item.go
@@ -94,17 +94,21 @@ func (item *Item) Rank(cache bool) Rank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AsString returns the original string
|
// AsString returns the original string
|
||||||
func (item *Item) AsString() string {
|
func (item *Item) AsString(stripAnsi bool) string {
|
||||||
return *item.StringPtr()
|
return *item.StringPtr(stripAnsi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringPtr returns the pointer to the original string
|
// StringPtr returns the pointer to the original string
|
||||||
func (item *Item) StringPtr() *string {
|
func (item *Item) StringPtr(stripAnsi bool) *string {
|
||||||
runes := item.text
|
|
||||||
if item.origText != nil {
|
if item.origText != nil {
|
||||||
runes = *item.origText
|
if stripAnsi {
|
||||||
|
trimmed, _, _ := extractColor(string(*item.origText), nil)
|
||||||
|
return &trimmed
|
||||||
|
}
|
||||||
|
orig := string(*item.origText)
|
||||||
|
return &orig
|
||||||
}
|
}
|
||||||
str := string(runes)
|
str := string(item.text)
|
||||||
return &str
|
return &str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ type Terminal struct {
|
|||||||
history *History
|
history *History
|
||||||
cycle bool
|
cycle bool
|
||||||
header []string
|
header []string
|
||||||
|
ansi bool
|
||||||
margin [4]string
|
margin [4]string
|
||||||
marginInt [4]int
|
marginInt [4]int
|
||||||
count int
|
count int
|
||||||
@@ -207,6 +208,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
marginInt: [4]int{0, 0, 0, 0},
|
marginInt: [4]int{0, 0, 0, 0},
|
||||||
cycle: opts.Cycle,
|
cycle: opts.Cycle,
|
||||||
header: opts.Header,
|
header: opts.Header,
|
||||||
|
ansi: opts.Ansi,
|
||||||
reading: true,
|
reading: true,
|
||||||
merger: EmptyMerger,
|
merger: EmptyMerger,
|
||||||
selected: make(map[uint32]selectedItem),
|
selected: make(map[uint32]selectedItem),
|
||||||
@@ -288,7 +290,7 @@ func (t *Terminal) output() {
|
|||||||
if len(t.selected) == 0 {
|
if len(t.selected) == 0 {
|
||||||
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())
|
fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sels := make([]selectedItem, 0, len(t.selected))
|
sels := make([]selectedItem, 0, len(t.selected))
|
||||||
@@ -805,7 +807,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
selectItem := func(item *Item) bool {
|
selectItem := func(item *Item) bool {
|
||||||
if _, found := t.selected[item.index]; !found {
|
if _, found := t.selected[item.index]; !found {
|
||||||
t.selected[item.index] = selectedItem{time.Now(), item.StringPtr()}
|
t.selected[item.index] = selectedItem{time.Now(), item.StringPtr(t.ansi)}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -843,7 +845,7 @@ func (t *Terminal) Loop() {
|
|||||||
case actExecute:
|
case actExecute:
|
||||||
if t.cy >= 0 && t.cy < t.merger.Length() {
|
if t.cy >= 0 && t.cy < t.merger.Length() {
|
||||||
item := t.merger.Get(t.cy)
|
item := t.merger.Get(t.cy)
|
||||||
executeCommand(t.execmap[mapkey], item.AsString())
|
executeCommand(t.execmap[mapkey], item.AsString(t.ansi))
|
||||||
}
|
}
|
||||||
case actInvalid:
|
case actInvalid:
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
|
|||||||
@@ -774,6 +774,22 @@ class TestGoFZF < TestBase
|
|||||||
tmux.until { |lines| lines.any? { |l| l.include? 'Invalid $TERM: xxx' } }
|
tmux.until { |lines| lines.any? { |l| l.include? 'Invalid $TERM: xxx' } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_with_nth
|
||||||
|
writelines tempname, ['hello world ', 'byebye']
|
||||||
|
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_with_nth_ansi
|
||||||
|
writelines tempname, ["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye']
|
||||||
|
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi`.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_with_nth_no_ansi
|
||||||
|
src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "
|
||||||
|
writelines tempname, [src, 'byebye']
|
||||||
|
assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp
|
||||||
|
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