diff options
54 files changed, 1962 insertions, 1292 deletions
diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml index 752c58c6..6cdac790 100644 --- a/.github/workflows/typos.yml +++ b/.github/workflows/typos.yml @@ -7,4 +7,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: crate-ci/typos@v1.19.0 + - uses: crate-ci/typos@v1.21.0 diff --git a/.goreleaser.yml b/.goreleaser.yml index 1ac56108..cf130d75 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -12,6 +12,8 @@ builds: - darwin goarch: - amd64 + flags: + - -trimpath ldflags: - "-s -w -X main.version={{ .Version }} -X main.revision={{ .ShortCommit }}" hooks: @@ -19,7 +21,7 @@ builds: sh -c ' cat > /tmp/fzf-gon-amd64.hcl << EOF source = ["./dist/fzf-macos_darwin_amd64_v1/fzf"] - bundle_id = "kr.junegunn.fzf" + bundle_id = "junegunn.fzf" sign { application_identity = "Developer ID Application: Junegunn Choi (Y254DRW44Z)" } @@ -36,6 +38,8 @@ builds: - darwin goarch: - arm64 + flags: + - -trimpath ldflags: - "-s -w -X main.version={{ .Version }} -X main.revision={{ .ShortCommit }}" hooks: @@ -43,7 +47,7 @@ builds: sh -c ' cat > /tmp/fzf-gon-arm64.hcl << EOF source = ["./dist/fzf-macos-arm_darwin_arm64/fzf"] - bundle_id = "kr.junegunn.fzf" + bundle_id = "junegunn.fzf" sign { application_identity = "Developer ID Application: Junegunn Choi (Y254DRW44Z)" } @@ -71,6 +75,8 @@ builds: - 5 - 6 - 7 + flags: + - -trimpath ldflags: - "-s -w -X main.version={{ .Version }} -X main.revision={{ .ShortCommit }}" ignore: diff --git a/CHANGELOG.md b/CHANGELOG.md index df2db318..8a094afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,69 @@ CHANGELOG ========= +0.52.1 +------ +- Fixed a critical bug in the Windows version + - Windows users are strongly encouraged to upgrade to this version + +0.52.0 +------ +- Added `--highlight-line` to highlight the whole current line (à la `set cursorline` of Vim) +- Added color names for selected lines: `selected-fg`, `selected-bg`, and `selected-hl` + ```sh + fzf --border --multi --info inline-right --layout reverse --marker ▏ --pointer ▌ --prompt '▌ ' \ + --highlight-line --color gutter:-1,selected-bg:238,selected-fg:146,current-fg:189 + ``` +- Added `click-header` event that is triggered when the header section is clicked. When the event is triggered, `$FZF_CLICK_HEADER_COLUMN` and `$FZF_CLICK_HEADER_LINE` are set. + ```sh + fd --type f | + fzf --header $'[Files] [Directories]' --header-first \ + --bind 'click-header:transform: + (( FZF_CLICK_HEADER_COLUMN <= 7 )) && echo "reload(fd --type f)" + (( FZF_CLICK_HEADER_COLUMN >= 9 )) && echo "reload(fd --type d)" + ' + ``` +- Add `$FZF_COMPLETION_{DIR,PATH}_OPTS` for separately customizing the behavior of fuzzy completion + ```sh + # Set --walker options without 'follow' not to follow symbolic links + FZF_COMPLETION_PATH_OPTS="--walker=file,dir,hidden" + FZF_COMPLETION_DIR_OPTS="--walker=dir,hidden" + ``` +- Fixed Windows argument escaping +- Bug fixes and improvements +- The code was heavily refactored to allow using fzf as a library in Go programs. The API is still experimental and subject to change. + - https://gist.github.com/junegunn/193990b65be48a38aac6ac49d5669170 + +0.51.0 +------ +- Added a new environment variable `$FZF_POS` exported to the child processes. It's the vertical position of the cursor in the list starting from 1. + ```sh + # Toggle selection to the top or to the bottom + seq 30 | fzf --multi --bind 'load:pos(10)' \ + --bind 'shift-up:transform:for _ in $(seq $FZF_POS $FZF_MATCH_COUNT); do echo -n +toggle+up; done' \ + --bind 'shift-down:transform:for _ in $(seq 1 $FZF_POS); do echo -n +toggle+down; done' + ``` +- Added `--with-shell` option to start child processes with a custom shell command and flags + ```sh + gem list | fzf --with-shell 'ruby -e' \ + --preview 'pp Gem::Specification.find_by_name({1})' \ + --bind 'ctrl-o:execute-silent: + spec = Gem::Specification.find_by_name({1}) + [spec.homepage, *spec.metadata.filter { _1.end_with?("uri") }.values].uniq.each do + system "open", _1 + end + ' + ``` +- Added `change-multi` action for dynamically changing `--multi` option + - `change-multi` - enable multi-select mode with no limit + - `change-multi(NUM)` - enable multi-select mode with a limit + - `change-multi(0)` - disable multi-select mode +- Windows improvements + - `become` action is now supported on Windows + - Unlike in *nix, this does not use `execve(2)`. Instead it spawns a new process and waits for it to finish, so the exact behavior may differ. + - Fixed argument escaping for Windows cmd.exe. No redundant escaping of backslashes. +- Bug fixes and improvements + 0.50.0 ------ - Search performance optimization. You can observe 50%+ improvement in some scenarios. @@ -1,6 +1,6 @@ -FROM --platform=linux/amd64 ubuntu:22.04 +FROM ubuntu:24.04 RUN apt-get update -y && apt install -y git make golang zsh fish ruby tmux -RUN gem install --no-document -v 5.14.2 minitest +RUN gem install --no-document -v 5.22.3 minitest RUN echo '. /usr/share/bash-completion/completions/git' >> ~/.bashrc RUN echo '. ~/.bashrc' >> ~/.bash_profile @@ -1,6 +1,6 @@ SHELL := bash GO ?= go -GOOS ?= $(word 1, $(subst /, " ", $(word 4, $(shell go version)))) +GOOS ?= $(shell $(GO) env GOOS) MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST))) ROOT_DIR := $(shell dirname $(MAKEFILE)) @@ -25,7 +25,7 @@ endif ifeq ($(REVISION),) $(error Not on git repository; cannot determine $$FZF_REVISION) endif -BUILD_FLAGS := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" +BUILD_FLAGS := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" -trimpath BINARY32 := fzf-$(GOOS)_386 BINARY64 := fzf-$(GOOS)_amd64 @@ -79,7 +79,6 @@ all: target/$(BINARY) test: $(SOURCES) [ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1) SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \ - github.com/junegunn/fzf \ github.com/junegunn/fzf/src \ github.com/junegunn/fzf/src/algo \ github.com/junegunn/fzf/src/tui \ @@ -174,12 +173,12 @@ bin/fzf: target/$(BINARY) | bin cp -f target/$(BINARY) bin/fzf docker: - docker build -t fzf-arch . - docker run -it fzf-arch tmux + docker build -t fzf-ubuntu . + docker run -it fzf-ubuntu tmux docker-test: - docker build -t fzf-arch . - docker run -it fzf-arch + docker build -t fzf-ubuntu . + docker run -it fzf-ubuntu update: $(GO) get -u @@ -44,7 +44,7 @@ I would like to thank all the sponsors of this project who make it possible for If you'd like to sponsor this project, please visit https://github.com/sponsors/junegunn. -<!-- sponsors --><a href="https://github.com/miyanokomiya"><img src="https://github.com/miyanokomiya.png" width="60px" alt="miyanokomiya" /></a><a href="https://github.com/jonhoo"><img src="https://github.com/jonhoo.png" width="60px" alt="Jon Gjengset" /></a><a href="https://github.com/AceofSpades5757"><img src="https://github.com/AceofSpades5757.png" width="60px" alt="Kyle L. Davis" /></a><a href="https://github.com/Frederick888"><img src="https://github.com/Frederick888.png" width="60px" alt="Frederick Zhang" /></a><a href="https://github.com/moritzdietz"><img src="https://github.com/moritzdietz.png" width="60px" alt="Moritz Dietz" /></a><a href="https://github.com/mikker"><img src="https://github.com/mikker.png" width="60px" alt="Mikkel Malmberg" /></a><a href="https://github.com/pldubouilh"><img src="https://github.com/pldubouilh.png" width="60px" alt="Pierre Dubouilh" /></a><a href="https://github.com/rcorre"><img src="https://github.com/rcorre.png" width="60px" alt="Ryan Roden-Corrent" /></a><a href="https://github.com/blissdev"><img src="https://github.com/blissdev.png" width="60px" alt="Jordan Arentsen" /></a><a href="https://github.com/mislav"><img src="https://github.com/mislav.png" width="60px" alt="Mislav Marohnić" /></a><a href="https://github.com/aexvir"><img src="https://github.com/aexvir.png" width="60px" alt="Alex Viscreanu" /></a><a href="https://github.com/dbalatero"><img src="https://github.com/dbalatero.png" width="60px" alt="David Balatero" /></a><a href="https://github.com/comatory"><img src="https://github.com/comatory.png" width="60px" alt="Ondrej Synacek" /></a><a href="https://github.com/moobar"><img src="https://github.com/moobar.png" width="60px" alt="" /></a><a href="https://github.com/majjoha"><img src="https://github.com/majjoha.png" width="60px" alt="Mathias Jean Johansen" /></a><a href="https://github.com/benelan"><img src="https://github.com/benelan.png" width="60px" alt="Ben Elan" /></a><a href="https://github.com/pawelduda"><img src="https://github.com/pawelduda.png" width="60px" alt="Paweł Duda" /></a><a href="https://github.com/slezica"><img src="https://github.com/slezica.png" width="60px" alt="Santiago Lezica" /></a><a href="https://github.com/pbwn"><img src="https://github.com/pbwn.png" width="60px" alt="" /></a><a href="https://github.com/timgluz"><img src="https://github.com/timgluz.png" width="60px" alt="Timo Sulg" /></a><a href="https://github.com/pyrho"><img src="https://github.com/pyrho.png" width="60px" alt="Damien Rajon" /></a><a href="https://github.com/ArtBIT"><img src="https://github.com/ArtBIT.png" width="60px" alt="ArtBIT" /></a><a href="https://github.com/da-moon"><img src="https://github.com/da-moon.png" width="60px" alt="" /></a><a href="https://github.com/hovissimo"><img src="https://github.com/hovissimo.png" width="60px" alt="Hovis" /></a><a href="https://github.com/dariusjonda"><img src="https://github.com/dariusjonda.png" width="60px" alt="Darius Jonda" /></a><a href="https://github.com/cristiand391"><img src="https://github.com/cristiand391.png" width="60px" alt="Cristian Dominguez" /></a><a href="https://github.com/eliangcs"><img src="https://github.com/eliangcs.png" width="60px" alt="Chang-Hung Liang" /></a><a href="https://github.com/asphaltbuffet"><img src="https://github.com/asphaltbuffet.png" width="60px" alt="Ben Lechlitner" /></a><a href="https://github.com/yash1th"><img src="https://github.com/yash1th.png" width="60px" alt="yash" /></a><a href="https://github.com/looshch"><img src="https://github.com/looshch.png" width="60px" alt="george looshch" /></a><a href="https://github.com/kg8m"><img src="https://github.com/kg8m.png" width="60px" alt="Takumi KAGIYAMA" /></a><a href="https://github.com/polm"><img src="https://github.com/polm.png" width="60px" alt="Paul O'Leary McCann" /></a><a href="https://github.com/rbeeger"><img src="https://github.com/rbeeger.png" width="60px" alt="Robert Beeger" /></a><a href="https://github.com/veebch"><img src="https://github.com/veebch.png" width="60px" alt="VEEB Projects" /></a><a href="https://github.com/khuedoan"><img src="https://github.com/khuedoan.png" width="60px" alt="Khue Doan" /></a><a href="https://github.com/yowayb"><img src="https://github.com/yowayb.png" width="60px" alt="Yoway Buorn" /></a><a href="https://github.com/scalisi"><img src="https://github.com/scalisi.png" width="60px" alt="Josh Scalisi" /></a><a href="https://github.com/alecbcs"><img src="https://github.com/alecbcs.png" width="60px" alt="Alec Scott" /></a><a href="https://github.com/thnxdev"><img src="https://github.com/thnxdev.png" width="60px" alt="thanks.dev" /></a><a href="https://github.com/artursapek"><img src="https://github.com/artursapek.png" width="60px" alt="Artur Sapek" /></a><a href="https://github.com/ramnes"><img src="https://github.com/ramnes.png" width="60px" alt="Guillaume Gelin" /></a><a href="https://github.com/jyc"><img src="https://github.com/jyc.png" width="60px" alt="" /></a><a href="https://github.com/mrcnski"><img src="https://github.com/mrcnski.png" width="60px" alt="Marcin S." /></a><a href="https://github.com/roblevy"><img src="https://github.com/roblevy.png" width="60px" alt="Rob Levy" /></a><a href="https://github.com/glozow"><img src="https://github.com/glozow.png" width="60px" alt="Gloria Zhao" /></a><a href="https://github.com/wjt"><img src="https://github.com/wjt.png" width="60px" alt="Will Thompson" /></a><a href="https://github.com/mauricelam"><img src="https://github.com/mauricelam.png" width="60px" alt="Maurice Lam" /></a><a href="https://github.com/toupeira"><img src="https://github.com/toupeira.png" width="60px" alt="Markus Koller" /></a><a href="https://github.com/rkpatel33"><img src="https://github.com/rkpatel33.png" width="60px" alt="" /></a><a href="https://github.com/jamesob"><img src="https://github.com/jamesob.png" width="60px" alt="James O'Beirne" /></a><a href="https://github.com/joshuatz"><img src="https://github.com/joshuatz.png" width="60px" alt="Joshua Tzucker" /></a><!-- sponsors --> +<!-- sponsors --><a href="https://github.com/miyanokomiya"><img src="https://github.com/miyanokomiya.png" width="60px" alt="miyanokomiya" /></a><a href="https://github.com/jonhoo"><img src="https://github.com/jonhoo.png" width="60px" alt="Jon Gjengset" /></a><a href="https://github.com/AceofSpades5757"><img src="https://github.com/AceofSpades5757.png" width="60px" alt="Kyle L. Davis" /></a><a href="https://github.com/Frederick888"><img src="https://github.com/Frederick888.png" width="60px" alt="Frederick Zhang" /></a><a href="https://github.com/moritzdietz"><img src="https://github.com/moritzdietz.png" width="60px" alt="Moritz Dietz" /></a><a href="https://github.com/mikker"><img src="https://github.com/mikker.png" width="60px" alt="Mikkel Malmberg" /></a><a href="https://github.com/pldubouilh"><img src="https://github.com/pldubouilh.png" width="60px" alt="Pierre Dubouilh" /></a><a href="https://github.com/rcorre"><img src="https://github.com/rcorre.png" width="60px" alt="Ryan Roden-Corrent" /></a><a href="https://github.com/blissdev"><img src="https://github.com/blissdev.png" width="60px" alt="Jordan Arentsen" /></a><a href="https://github.com/mislav"><img src="https://github.com/mislav.png" width="60px" alt="Mislav Marohnić" /></a><a href="https://github.com/aexvir"><img src="https://github.com/aexvir.png" width="60px" alt="Alex Viscreanu" /></a><a href="https://github.com/dbalatero"><img src="https://github.com/dbalatero.png" width="60px" alt="David Balatero" /></a><a href="https://github.com/comatory"><img src="https://github.com/comatory.png" width="60px" alt="Ondrej Synacek" /></a><a href="https://github.com/moobar"><img src="https://github.com/moobar.png" width="60px" alt="" /></a><a href="https://github.com/majjoha"><img src="https://github.com/majjoha.png" width="60px" alt="Mathias Jean Johansen" /></a><a href="https://github.com/benelan"><img src="https://github.com/benelan.png" width="60px" alt="Ben Elan" /></a><a href="https://github.com/pawelduda"><img src="https://github.com/pawelduda.png" width="60px" alt="Paweł Duda" /></a><a href="https://github.com/slezica"><img src="https://github.com/slezica.png" width="60px" alt="Santiago Lezica" /></a><a href="https://github.com/pbwn"><img src="https://github.com/pbwn.png" width="60px" alt="" /></a><a href="https://github.com/timgluz"><img src="https://github.com/timgluz.png" width="60px" alt="Timo Sulg" /></a><a href="https://github.com/pyrho"><img src="https://github.com/pyrho.png" width="60px" alt="Damien Rajon" /></a><a href="https://github.com/ArtBIT"><img src="https://github.com/ArtBIT.png" width="60px" alt="ArtBIT" /></a><a href="https://github.com/da-moon"><img src="https://github.com/da-moon.png" width="60px" alt="" /></a><a href="https://github.com/hovissimo"><img src="https://github.com/hovissimo.png" width="60px" alt="Hovis" /></a><a href="https://github.com/dariusjonda"><img src="https://github.com/dariusjonda.png" width="60px" alt="Darius Jonda" /></a><a href="https://github.com/cristiand391"><img src="https://github.com/cristiand391.png" width="60px" alt="Cristian Dominguez" /></a><a href="https://github.com/eliangcs"><img src="https://github.com/eliangcs.png" width="60px" alt="Chang-Hung Liang" /></a><a href="https://github.com/asphaltbuffet"><img src="https://github.com/asphaltbuffet.png" width="60px" alt="Ben Lechlitner" /></a><a href="https://github.com/yash1th"><img src="https://github.com/yash1th.png" width="60px" alt="yash" /></a><a href="https://github.com/looshch"><img src="https://github.com/looshch.png" width="60px" alt="george looshch" /></a><a href="https://github.com/kg8m"><img src="https://github.com/kg8m.png" width="60px" alt="Takumi KAGIYAMA" /></a><a href="https://github.com/polm"><img src="https://github.com/polm.png" width="60px" alt="Paul O'Leary McCann" /></a><a href="https://github.com/rbeeger"><img src="https://github.com/rbeeger.png" width="60px" alt="Robert Beeger" /></a><a href="https://github.com/veebch"><img src="https://github.com/veebch.png" width="60px" alt="VEEB Projects" /></a><a href="https://github.com/khuedoan"><img src="https://github.com/khuedoan.png" width="60px" alt="Khue Doan" /></a><a href="https://github.com/yowayb"><img src="https://github.com/yowayb.png" width="60px" alt="Yoway Buorn" /></a><a href="https://github.com/scalisi"><img src="https://github.com/scalisi.png" width="60px" alt="Josh Scalisi" /></a><a href="https://github.com/alecbcs"><img src="https://github.com/alecbcs.png" width="60px" alt="Alec Scott" /></a><a href="https://github.com/thnxdev"><img src="https://github.com/thnxdev.png" width="60px" alt="thanks.dev" /></a><a href="https://github.com/artursapek"><img src="https://github.com/artursapek.png" width="60px" alt="Artur Sapek" /></a><a href="https://github.com/ramnes"><img src="https://github.com/ramnes.png" width="60px" alt="Guillaume Gelin" /></a><a href="https://github.com/jyc"><img src="https://github.com/jyc.png" width="60px" alt="" /></a><a href="https://github.com/mrcnski"><img src="https://github.com/mrcnski.png" width="60px" alt="Marcin S." /></a><a href="https://github.com/roblevy"><img src="https://github.com/roblevy.png" width="60px" alt="Rob Levy" /></a><a href="https://github.com/glozow"><img src="https://github.com/glozow.png" width="60px" alt="Gloria Zhao" /></a><a href="https://github.com/wjt"><img src="https://github.com/wjt.png" width="60px" alt="Will Thompson" /></a><a href="https://github.com/toupeira"><img src="https://github.com/toupeira.png" width="60px" alt="Markus Koller" /></a><a href="https://github.com/rkpatel33"><img src="https://github.com/rkpatel33.png" width="60px" alt="" /></a><a href="https://github.com/jamesob"><img src="https://github.com/jamesob.png" width="60px" alt="James O'Beirne" /></a><a href="https://github.com/jlebray"><img src="https://github.com/jlebray.png" width="60px" alt="Johan Le Bray" /></a><a href="https://github.com/cskeeters"><img src="https://github.com/cskeeters.png" width="60px" alt="Chad Skeeters" /></a><a href="https://github.com/Konfekt"><img src="https://github.com/Konfekt.png" width="60px" alt="Enno" /></a><a href="https://github.com/joclement"><img src="https://github.com/joclement.png" width="60px" alt="Joris Clement" /></a><a href="https://github.com/mattiklock"><img src="https://github.com/mattiklock.png" width="60px" alt="Matti Klock" /></a><!-- sponsors --> Table of Contents ----------------- @@ -204,7 +204,7 @@ Add the following line to your shell configuration file. * zsh ```sh # Set up fzf key bindings and fuzzy completion - eval "$(fzf --zsh)" + source <(fzf --zsh) ``` * fish ```fish @@ -226,7 +226,7 @@ Add the following line to your shell configuration file. > For example, to disable ALT-C binding: > > * bash: `FZF_ALT_C_COMMAND= eval "$(fzf --bash)"` -> * zsh: `FZF_ALT_C_COMMAND= eval "$(fzf --zsh)"` +> * zsh: `FZF_ALT_C_COMMAND= source <(fzf --zsh)` > * fish: `fzf --fish | FZF_ALT_C_COMMAND= source` > > Setting the variables after sourcing the script will have no effect. @@ -6,8 +6,8 @@ require ( github.com/mattn/go-isatty v0.0.20 github.com/mattn/go-shellwords v1.0.12 github.com/rivo/uniseg v0.4.7 - golang.org/x/sys v0.19.0 - golang.org/x/term v0.19.0 + golang.org/x/sys v0.20.0 + golang.org/x/term v0.20.0 ) require ( @@ -36,14 +36,14 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -2,7 +2,7 @@ set -u -version=0.50.0 +version=0.52.1 auto_completion= key_bindings= update_config=2 @@ -115,7 +115,7 @@ link_fzf_in_path() { try_curl() { command -v curl > /dev/null && if [[ $1 =~ tar.gz$ ]]; then - curl -fL $1 | tar -xzf - + curl -fL $1 | tar --no-same-owner -xzf - else local temp=${TMPDIR:-/tmp}/fzf.zip curl -fLo "$temp" $1 && unzip -o "$temp" && rm -f "$temp" @@ -125,7 +125,7 @@ try_curl() { try_wget() { command -v wget > /dev/null && if [[ $1 =~ tar.gz$ ]]; then - wget -O - $1 | tar -xzf - + wget -O - $1 | tar --no-same-owner -xzf - else local temp=${TMPDIR:-/tmp}/fzf.zip wget -O "$temp" $1 && unzip -o "$temp" && rm -f "$temp" @@ -265,7 +265,11 @@ fi EOF if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then - echo "eval \"\$(fzf --$shell)\"" >> "$src" + if [[ "$shell" = zsh ]]; then + echo "source <(fzf --$shell)" >> "$src" + else + echo "eval \"\$(fzf --$shell)\"" >> "$src" + fi else cat >> "$src" << EOF # Auto-completion diff --git a/install.ps1 b/install.ps1 index deb97490..090bb5ed 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,4 +1,4 @@ -$version="0.50.0" +$version="0.52.1" $fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition @@ -3,14 +3,15 @@ package main import ( _ "embed" "fmt" + "os" "strings" fzf "github.com/junegunn/fzf/src" "github.com/junegunn/fzf/src/protector" ) -var version string = "0.50" -var revision string = "devel" +var version = "0.52" +var revision = "devel" //go:embed shell/key-bindings.bash var bashKeyBindings []byte @@ -33,9 +34,21 @@ func printScript(label string, content []byte) { fmt.Println("### end: " + label + " ###") } +func exit(code int, err error) { + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + } + os.Exit(code) +} + func main() { protector.Protect() - options := fzf.ParseOptions() + + options, err := fzf.ParseOptions(true, os.Args[1:]) + if err != nil { + exit(fzf.ExitError, err) + return + } if options.Bash { printScript("key-bindings.bash", bashKeyBindings) printScript("completion.bash", bashCompletion) @@ -51,5 +64,19 @@ func main() { fmt.Println("fzf_key_bindings") return } - fzf.Run(options, version, revision) + if options.Help { + fmt.Print(fzf.Usage) + return + } + if options.Version { + if len(revision) > 0 { + fmt.Printf("%s (%s)\n", version, revision) + } else { + fmt.Println(version) + } + return + } + + code, err := fzf.Run(options) + exit(code, err) } diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 4efb6e79..00000000 --- a/main_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/build" - "go/importer" - "go/parser" - "go/token" - "go/types" - "io/fs" - "os" - "path/filepath" - "sort" - "strings" - "testing" -) - -func loadPackages(t *testing.T) []*build.Package { - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - var pkgs []*build.Package - seen := make(map[string]bool) - err = filepath.WalkDir(wd, func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - name := d.Name() - if d.IsDir() { - if name == "" || name[0] == '.' || name[0] == '_' || name == "vendor" || name == "tmp" { - return filepath.SkipDir - } - return nil - } - if d.Type().IsRegular() && filepath.Ext(name) == ".go" && !strings.HasSuffix(name, "_test.go") { - dir := filepath.Dir(path) - if !seen[dir] { - pkg, err := build.ImportDir(dir, build.ImportComment) - if err != nil { - return fmt.Errorf("%s: %s", dir, err) - } - if pkg.ImportPath == "" || pkg.ImportPath == "." { - importPath, err := filepath.Rel(wd, dir) - if err != nil { - t.Fatal(err) - } - pkg.ImportPath = filepath.ToSlash(filepath.Join("github.com/junegunn/fzf", importPath)) - } - - pkgs = append(pkgs, pkg) - seen[dir] = true - } - } - return nil - }) - if err != nil { - t.Fatal(err) - } - - sort.Slice(pkgs, func(i, j int) bool { - return pkgs[i].ImportPath < pkgs[j].ImportPath - }) - return pkgs -} - -var sourceImporter = importer.ForCompiler(token.NewFileSet(), "source", nil) - -func |