Closed thk-gh closed 2 years ago
Sorry, but I'm unable to reproduce this. I created a temp folder, pasted your .zshrc
file into it and then did this:
env -i HOME=$PWD ZDOTDIR=$PWD TERM=$TERM PATH=$PATH FPATH=$FPATH zsh -d
Works fine, which makes me suspect there might be something in your environment variables that's messing things up.
Can you run env
and paste the output here?
Yes, sure:
Thanks again for looking into this!
I don't see anything suspicious in there.
After trying completion on znap
, can you do functions -T _znap
, then try completion again and paste the output here?
❯ znap [TAB]
Applications/ Library/ Public/ [...]
~
❯ functions -T _znap
~
❯ echo $?
1
~
❯ znap [TAB]
Applications/ Library/ Public/ [...]
In a shell/terminal where tab-completion works, it is:
~
❯ functions -T _znap
~
❯ echo $?
0
This is not really a grave problem, since it affects apparently only Znap's own completions (brew [TAB] e.g. works as expected), but...
I just noticed that there should be some debugging output...
This is from a shell/terminal where tab-completions works. I could not get such info from a shell where it does not, sorry.
~
❯ functions -T _znap
~
❯ znap ++++++ _znap:3 @_znap:3> [[ -v _ZNAP_ARGS ]]
++++++ _znap:6 @_znap:6> local -a subcommands=( )
++++++ _znap:7 @_znap:7> local k
++++++ _znap:7 @_znap:7> k=clean
++++++ _znap:8 @_znap:8> subcommands+=( 'clean\:'\''remove outdated .zwc binaries'\' )
++++++ _znap:7 @_znap:7> k=clone
++++++ _znap:8 @_znap:8> subcommands+=( 'clone\:'\''download repos in parallel'\' )
++++++ _znap:7 @_znap:7> k=compdef
++++++ _znap:8 @_znap:8> subcommands+=( 'compdef\:'\''add output of command as completion function (deprecated)'\' )
++++++ _znap:7 @_znap:7> k=compile
++++++ _znap:8 @_znap:8> subcommands+=( 'compile\:'\''compile zsh scripts and functions'\' )
++++++ _znap:7 @_znap:7> k=eval
++++++ _znap:8 @_znap:8> subcommands+=( 'eval\:'\''cache & eval output of command'\' )
++++++ _znap:7 @_znap:7> k=fpath
++++++ _znap:8 @_znap:8> subcommands+=( 'fpath\:'\''install command output as a function'\' )
++++++ _znap:7 @_znap:7> k=function
++++++ _znap:8 @_znap:8> subcommands+=( 'function\:'\''create a set of lazy-loading functions'\' )
++++++ _znap:7 @_znap:7> k=help
++++++ _znap:8 @_znap:8> subcommands+=( 'help\:'\''print help text for command'\' )
++++++ _znap:7 @_znap:7> k=ignore
++++++ _znap:8 @_znap:8> subcommands+=( 'ignore\:'\''add local exclude patterns to repo'\' )
++++++ _znap:7 @_znap:7> k=install
++++++ _znap:8 @_znap:8> subcommands+=( 'install\:'\''install executables & completion functions'\' )
++++++ _znap:7 @_znap:7> k=multi
++++++ _znap:8 @_znap:8> subcommands+=( 'multi\:'\''run tasks in parallel'\' )
++++++ _znap:7 @_znap:7> k=prompt
++++++ _znap:8 @_znap:8> subcommands+=( 'prompt\:'\''instant prompt from repo'\' )
++++++ _znap:7 @_znap:7> k=pull
++++++ _znap:8 @_znap:8> subcommands+=( 'pull\:'\''update repos in parallel'\' )
++++++ _znap:7 @_znap:7> k=restart
++++++ _znap:8 @_znap:8> subcommands+=( 'restart\:'\''validate dotfiles & safely restart Zsh'\' )
++++++ _znap:7 @_znap:7> k=source
++++++ _znap:8 @_znap:8> subcommands+=( 'source\:'\''load plugins'\' )
++++++ _znap:7 @_znap:7> k=status
++++++ _znap:8 @_znap:8> subcommands+=( 'status\:'\''fetch updates & show git status'\' )
++++++ _znap:7 @_znap:7> k=uninstall
++++++ _znap:8 @_znap:8> subcommands+=( 'uninstall\:'\''remove executables & completion functions'\' )
++++++ _znap:11 @_znap:11> local -A opt_args
++++++ _znap:12 @_znap:12> local -a opts=( -qS ' ' ) context line state state_descr
++++++ _znap:13 @_znap:13> _arguments -A '' -O opts : ':command:(( clean\:'\''remove outdated .zwc binaries'\'' clone\:'\''download repos in parallel'\'' compdef\:'\''add output of command as completion function (deprecated)'\'' compile\:'\''compile zsh scripts and functions'\'' eval\:'\''cache & eval output of command'\'' fpath\:'\''install command output as a function'\'' function\:'\''create a set of lazy-loading functions'\'' help\:'\''print help text for command'\'' ignore\:'\''add local exclude patterns to repo'\'' install\:'\''install executables & completion functions'\'' multi\:'\''run tasks in parallel'\'' prompt\:'\''instant prompt from repo'\'' pull\:'\''update repos in parallel'\'' restart\:'\''validate dotfiles & safely restart Zsh'\'' source\:'\''load plugins'\'' status\:'\''fetch updates & show git status'\'' uninstall\:'\''remove executables & completion functions'\'' ))' '*:: :->next'
++++++ _znap:14 @_znap:14> local ret=0
++++++ _znap:16 @_znap:16> [[ '' == next ]]
++++++ _znap:17 @_znap:17> return ret
znap
clean -- remove outdated .zwc binaries
clone -- download repos in parallel
compdef -- add output of command as completion function (deprecated)
compile -- compile zsh scripts and functions
eval -- cache & eval output of command
fpath -- install command output as a function
function -- create a set of lazy-loading functions
help -- print help text for command
ignore -- add local exclude patterns to repo
install -- install executables & completion functions
multi -- run tasks in parallel
prompt -- instant prompt from repo
pull -- update repos in parallel
restart -- validate dotfiles & safely restart Zsh
source -- load plugins
status -- fetch updates & show git status
uninstall -- remove executables & completion functions
I could not get such info from a shell where it does not, sorry.
In the shell where it does not work, what output do you get from trying completion after running functions -t _main_complete
? And what output do you get from print $_comps[znap]
?
❯ print $_comps[znap] ~
This means that Znap's completion function has not been loaded by compinit
, which is confirmed by the rest of the output.
Please check the output of env
and print -l $fpath
before and after you restart. Are there any differences?
No differences in env
or $fpath
between znap restart
s.
❯ print -l $fpath
/Users/thk/src/zsh/pure
/usr/local/share/zsh/site-functions
/usr/share/zsh/site-functions
/usr/share/zsh/5.8/functions
/Users/thk/.local/share/zsh/site-functions
❯ ls -l /Users/thk/.local/share/zsh/site-functions/
total 16
lrwxr-xr-x 1 thk staff 43 Nov 3 22:00 _znap@ -> /Users/thk/src/zsh/zsh-snap/functions/_znap
-rw-r----- 1 thk staff 5984 Nov 2 12:48 _znap.zwc
❯ ls -l /Users/thk/src/zsh/zsh-snap/functions/_znap -rw-r--r-- 1 thk staff 2064 Nov 2 12:47 /Users/thk/src/zsh/zsh-snap/functions/_znap
I just found the cause.
I have these lines in my .zshenv
I had forgotten about.
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
Apparently brew cask info google-cloud-sdk
told me to put them there some time ago.
The second line (.../completion.zsh.inc) causes the phenomenon; if I comment it out the problem disappears. Of course, now gcloud [TAB]
doesn't work anymore... :-) I'll try to find a workaround or solution or I just live with it.
So, thank you very much for your help, very much appreciated, great support!
In case you are still interested, here is the completion.zsh.inc file from Google's Cloud SDK:
autoload -U +X bashcompinit && bashcompinit
zmodload -i zsh/parameter
if ! (( $+functions[compdef] )) ; then
autoload -U +X compinit && compinit
fi
_python_argcomplete() {
local prefix=
if [[ $COMP_LINE == 'gcloud '* ]]; then
if [[ $3 == ssh && $2 == *@* ]] ;then
# handle ssh user@instance specially
prefix=${2%@*}@
COMP_LINE=${COMP_LINE%$2}"${2#*@}"
elif [[ $2 == *'='* ]] ; then
# handle --flag=value
prefix=${2%=*}'='
COMP_LINE=${COMP_LINE%$2}${2/'='/' '}
fi
fi
local IFS='^K'
COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT"
_ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1
9>&2 1>/dev/null 2>/dev/null) )
if [[ $? != 0 ]]; then
unset COMPREPLY
return
fi
# if one completion without a trailing space, add the space
if [[ ${#COMPREPLY[@]} == 1 && $COMPREPLY != *[=' '] ]]; then
COMPREPLY+=' '
fi
if [[ $prefix != '' ]]; then
typeset -i n
for ((n=0; n < ${#COMPREPLY[@]}; n++));do
COMPREPLY[$n]=$prefix${COMPREPLY[$n]}
done
fi
}
complete -o nospace -o default -F _python_argcomplete "gcloud"
_completer() {
command=$1
name=$2
eval '[[ -n "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"'
set -- $COMP_LINE
shift
while [[ $1 == -* ]]; do
shift
done
[[ -n "$2" ]] && return
grep -q "${name}\s*$" <<< $COMP_LINE &&
eval 'COMPREPLY=($'"${name}"'_COMMANDS)' &&
return
[[ "$COMP_LINE" == *" " ]] && return
[[ -n "$1" ]] &&
eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))'
}
unset bq_COMMANDS
_bq_completer() {
_completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]* ' | sed 's/ .*//'" bq
}
complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil
In case you are still interested, here is the completion.zsh.inc file from Google's Cloud SDK:
Wow, that code is so messed up on so many levels, I don't even know where to start to explain what's wrong with it. The people who wrote this don't seem to have any clue what they were doing. Don't use it! It will do you more harm than good.
Instead, add this to your .zshrc
file:
# Lazy-load the completion function for these commands.
znap function _python_argcomplete gloud gsutil \
'eval "$( register-python-argcomplete gloud gsutil )"'
# Cache command output.
bqinit() {
unfunction bqinit
typeset -gH BQ_COMMANDS="$(
CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help |
grep '^[^ ][^ ]* ' |
sed 's/ .*//'
)"
typeset -m BQ_COMMANDS
}
znap eval bq bqinit
# Define custom, bash-style completion function.
_bq() {
set -- $COMP_LINE
shift
while [[ $1 == -* ]]; do
shift
done
[[ -n "$2" ]] &&
return
grep -q 'bq\s*$' <<< $COMP_LINE &&
COMPREPLY=( $BQ_COMMANDS ) &&
return
[[ "$COMP_LINE" == *' ' ]] &&
return
[[ -n "$1" ]] &&
COMPREPLY=( $( echo "$BQ_COMMANDS" | grep ^"$1" ) )
}
# Register bash-style completions.
complete -o nospace -o default -F _python_argcomplete gcloud
complete -o nospace -F _python_argcomplete gsutil
complete -o default -F _bq bq
Hi,
I have a weird problem with znap on my MacBook (running macOS 11.6).
Tab-completion of znap itself is working only once after installation or after changes to .zshrc -- in following shells or after 'znap restart' tab-completion is not working anymore. I do not have this behaviour on other machines running (Void) Linux or OpenBSD.
I can't figure out what is causing this -- maybe you consider this a bug and can fix it?
Here's a demonstration so you see what I'm talking about:
(click to expand)
``` ❯ znap [TAB] clean -- remove outdated .zwc binaries clone -- download repos in parallel compdef -- add output of command as completion function (deprecated) compile -- compile zsh scripts and functions eval -- cache & eval output of command fpath -- install command output as a function function -- create a set of lazy-loading functions help -- print help text for command ignore -- add local exclude patterns to repo install -- install executables & completion functions multi -- run tasks in parallel prompt -- instant prompt from repo pull -- update repos in parallel restart -- validate dotfiles & safely restart Zsh source -- load plugins status -- fetch updates & show git status uninstall -- remove executables & completion functions ~ ❯ znap restart Validating dotfiles... Restarting Zsh... ~ ❯ znap [TAB] Applications/ Library/ Public/ src/ Applications\ \(Parallels\)/ Movies/ bin/ tmp/ Desktop/ Music/ fossil/ Documents/ Parallels/ lib/ Downloads/ Pictures/ org/ ~ ❯ zsh --version zsh 5.8 (x86_64-apple-darwin20.0) ```FWIW, here's most of my .zshrc (I left out key bindings and aliases):
(click to expand)
``` [[ ! -o interactive ]] && return # Znap: # Download Znap, if it's not there yet. [[ -f ~/src/zsh/zsh-snap/znap.zsh ]] || git clone --depth 1 -- \ https://github.com/marlonrichert/zsh-snap.git ~/src/zsh/zsh-snap # source ~/src/zsh/zsh-snap/znap.zsh # Start Znap #zstyle ':znap:*' auto-compile no # # https://github.com/sindresorhus/pure : # change the path color #zstyle :prompt:pure:path color white znap prompt sindresorhus/pure # # `znap source` automatically downloads and starts your plugins. #znap source marlonrichert/zsh-autocomplete #znap source zsh-users/zsh-autosuggestions # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md : ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) znap source zsh-users/zsh-syntax-highlighting # Miscellanous options: setopt extendedglob nomatch notify # autocd ? setopt CORRECT_ALL # Correct spelling of all arguments in the command line #REPORTTIME=3 # Report command running time if it is more than 3 seconds # Autocompletion: #autoload -Uz compinit && compinit -u zstyle :compinstall filename '~/.zshrc' zstyle ':completion:*' completer _complete _correct _approximate zstyle ':completion:*' menu select zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh_cache # doesn't work? zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS' zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS' zstyle ':completion:*:functions' ignored-patterns '_*' setopt COMPLETE_ALIASES # History: HISTFILE=~/.zsh_history HISTSIZE=5000 SAVEHIST=4000 setopt SHARE_HISTORY setopt HIST_IGNORE_ALL_DUPS # Do not keep duplicate commands in history setopt HIST_IGNORE_SPACE # Do not remember commands that start with a whitespace. #setopt HIST_FIND_NO_DUPS # Do not display a previously found event. setopt HIST_VERIFY # Do not execute immediately upon history expansion. setopt HIST_NO_STORE # Don't store history commands setopt INC_APPEND_HISTORY # Add commands to history as they are entered unsetopt EXTENDED_HISTORY INC_APPEND_HISTORY_TIME ```Thanks for your time, and thanks for writing and sharing zsh-snap! -- Thomas