Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for autocomplete behind shim (like asdf) #1959

Closed
kedare opened this issue Sep 15, 2021 · 1 comment · Fixed by #3829
Closed

Add support for autocomplete behind shim (like asdf) #1959

kedare opened this issue Sep 15, 2021 · 1 comment · Fixed by #3829
Assignees
Labels
autocomplete enhancement priority:medium Improvements that are not the main priority

Comments

@kedare
Copy link

kedare commented Sep 15, 2021

Description

When using scw behind a version managed using shims like ASDF, the autocomplete doesn't work as it is generating the full path in the generated autocompletion code (even the scw shim is in PATH)

$ scw autocomplete script
autoload -U compinit && compinit
_/home/mpoussin/.asdf/installs/scaleway-cli/2.3.1/bin/scw () {
        output=($(/home/mpoussin/.asdf/installs/scaleway-cli/2.3.1/bin/scw autocomplete complete zsh -- ${CURRENT} ${words}))
        opts=('-S' ' ')
        if [[ $output == *= ]]; then
                opts=('-S' '')
        fi
        compadd "${opts[@]}" -- "${output[@]}"
}
compdef _/home/mpoussin/.asdf/installs/scaleway-cli/2.3.1/bin/scw /home/mpoussin/.asdf/installs/scaleway-cli/2.3.1/bin/scw

It would be interesting to have a --parameter to force the basename to scw (or configurable)

How this functionality would be exposed

A new parameter --basename for example to force a basename on the autocompletion generated code

References

https://github.com/asdf-vm/asdf
https://github.com/webofmars/asdf-plugin-scaleway-cli

Version

Version 2.3.1
BuildDate 2021-06-08T11:54:02
GoVersion go1.16.4
GitBranch new-release
GitCommit 07dbaeb
GoArch amd64
GoOS linux

@ftoral
Copy link

ftoral commented Mar 2, 2023

Hi,

I will +1 on that issue, because i face the problem with Homebrew (scw formulae).
The autocomplete code generated by the formulae is based on the scw autocomplete script command, but is relative to the brew installation. Consequently and despite the scw is on the $PATH the autocomplete do not work.

brew upgrade scw
==> Upgrading 1 outdated package:
scw 2.10.0 -> 2.11.1
[...]
==> scw
Bash completion has been installed to:
  /home/linuxbrew/.linuxbrew/etc/bash_completion.d
$ cat /home/linuxbrew/.linuxbrew/etc/bash_completion.d/scw 
_/home/linuxbrew/.linuxbrew/Cellar/scw/2.11.1/bin/scw() {
	_get_comp_words_by_ref -n = cword words

	output=$(/home/linuxbrew/.linuxbrew/Cellar/scw/2.11.1/bin/scw autocomplete complete bash -- "$COMP_LINE" "$cword" "${words[@]}")
	COMPREPLY=($output)
	# apply compopt option and ignore failure for older bash versions
	[[ $COMPREPLY == *= ]] && compopt -o nospace 2> /dev/null || true
	return
}
complete -F _/home/linuxbrew/.linuxbrew/Cellar/scw/2.11.1/bin/scw /home/linuxbrew/.linuxbrew/Cellar/scw/2.11.1/bin/scw

The current workaround is to change the brew generated script with

sed -i -E 's#(_?)\/([^ \n]*)scw#\1scw#g' $(brew --prefix)/etc/bash_completion.d/scw
source $(brew --prefix)/etc/bash_completion.d/scw

For reference the line in the scw Homebrew formulae : Formula/scw.rb#L23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocomplete enhancement priority:medium Improvements that are not the main priority
Projects
None yet
5 participants