From 2298c0a5aa9cca8bf18bb77de69b154e49ceba33 Mon Sep 17 00:00:00 2001 From: Ralf Steube Date: Sat, 15 Feb 2025 16:03:39 +0100 Subject: [PATCH] fish: erase existing for tombstone (#2704) see https://github.com/fish-shell/fish-shell/commit/5918bca1eba861e3e8f69f055aac20e9cae1af3c --- cmd/carapace/cmd/lazyinit/fish.go | 28 +++++++++++++++++++++------- docs/src/release_notes/v1.x.md | 10 ++++++++++ docs/src/setup.md | 9 +++++++-- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/cmd/carapace/cmd/lazyinit/fish.go b/cmd/carapace/cmd/lazyinit/fish.go index baa0970a..f468b590 100644 --- a/cmd/carapace/cmd/lazyinit/fish.go +++ b/cmd/carapace/cmd/lazyinit/fish.go @@ -8,16 +8,30 @@ import ( func Fish(completers []string) string { snippet := `%v%v -function _carapace_lazy - complete -c $argv[1] -e - carapace $argv[1] fish | source - complete --do-complete=(commandline -cp) +function _carapace_quote_suffix + if not commandline -cp | xargs echo 2>/dev/null >/dev/null + if commandline -cp | sed 's/$/"/'| xargs echo 2>/dev/null >/dev/null + echo '"' + else if commandline -cp | sed "s/\$/'/"| xargs echo 2>/dev/null >/dev/null + echo "'" + end + else + echo "" + end end + +function _carapace_callback + commandline -cp | sed "s/\$/"(_carapace_quote_suffix)"/" | sed "s/ \$/ ''/" | xargs carapace $argv[1] fish +end + %v ` - complete := make([]string, len(completers)) - for index, completer := range completers { - complete[index] = fmt.Sprintf(`complete -c '%v' -f -a '(_carapace_lazy %v)'`, completer, completer) + complete := make([]string, 0, len(completers)*2) + for _, completer := range completers { + complete = append(complete, + fmt.Sprintf(`complete -e '%v'`, completer), + fmt.Sprintf(`complete -c '%v' -f -a '(_carapace_callback %v)'`, completer, completer), + ) } return fmt.Sprintf(snippet, pathSnippet("fish"), envSnippet("fish"), strings.Join(complete, "\n")) } diff --git a/docs/src/release_notes/v1.x.md b/docs/src/release_notes/v1.x.md index 765a2327..ce85fa65 100644 --- a/docs/src/release_notes/v1.x.md +++ b/docs/src/release_notes/v1.x.md @@ -3,3 +3,13 @@ ![](./v1.x/banner.png) Under development. + + +## Fish + +With [4.0b1](https://github.com/fish-shell/fish-shell/releases/tag/4.0b1) onwards the following workaround is not needed anymore: +```sh +mkdir -p ~/.config/fish/completions +carapace --list | awk '{print $1}' | xargs -I{} touch ~/.config/fish/completions/{}.fish # disable auto-loaded completions (#185) +``` +see [fish-shell/fish#6716](https://github.com/fish-shell/fish-shell/issues/6716) diff --git a/docs/src/setup.md b/docs/src/setup.md index 30a1e41e..a836eb77 100644 --- a/docs/src/setup.md +++ b/docs/src/setup.md @@ -39,13 +39,18 @@ eval (carapace _carapace|slurp) ```sh # ~/.config/fish/config.fish set -Ux CARAPACE_BRIDGES 'zsh,fish,bash,inshellisense' # optional -mkdir -p ~/.config/fish/completions -carapace --list | awk '{print $1}' | xargs -I{} touch ~/.config/fish/completions/{}.fish # disable auto-loaded completions (#185) carapace _carapace | source ``` ![](./setup-fish.png) +> With [4.0b1](https://github.com/fish-shell/fish-shell/releases/tag/4.0b1) onwards the following workaround is not needed anymore: +> ```sh +> mkdir -p ~/.config/fish/completions +> carapace --list | awk '{print $1}' | xargs -I{} touch ~/.config/fish/completions/{}.fish # disable auto-loaded completions (#185) +> ``` +> see [fish-shell/fish#6716](https://github.com/fish-shell/fish-shell/issues/6716) + ## Nushell ```sh diff --git a/go.mod b/go.mod index 3e798782..cf6bf3a6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/carapace-sh/carapace-bin go 1.23.1 require ( - github.com/carapace-sh/carapace v1.7.0 + github.com/carapace-sh/carapace v1.7.1 github.com/carapace-sh/carapace-bridge v1.2.3 github.com/carapace-sh/carapace-selfupdate v0.0.10 github.com/carapace-sh/carapace-shlex v1.0.1 diff --git a/go.sum b/go.sum index 04e6222a..65787d3d 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/carapace-sh/carapace v1.7.0 h1:uJK6qvrXow6ZylbjGrU1pEyFCg0ZQ/L951GcIdl2C7U= -github.com/carapace-sh/carapace v1.7.0/go.mod h1:fHdo3nEFe1QnIXxeA/Z1O9dCI83sfCsKfxrogpHfgtM= +github.com/carapace-sh/carapace v1.7.1 h1:GjMjPNEMHhTstneZD2M3Ypjb+lW5YNEV1AfYmRhsG4c= +github.com/carapace-sh/carapace v1.7.1/go.mod h1:fHdo3nEFe1QnIXxeA/Z1O9dCI83sfCsKfxrogpHfgtM= github.com/carapace-sh/carapace-bridge v1.2.3 h1:lalVNRCyUqdPAJbrqkmIDKNnZYsBlo83JBsdP9WFzKM= github.com/carapace-sh/carapace-bridge v1.2.3/go.mod h1:rEOS3MgzTQrCssS8WunHxPz31jZYNudcA7w1W5HrJs0= github.com/carapace-sh/carapace-pflag v1.0.0 h1:uJMhl+vwEM/Eb0UdxZUuv4jo4rUAyPijkRGP5gfCuCE=