chore: completion test command sequence (#4115)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
cleanup zsh global scope
authored by LangLangBart · committed by GitHub · parent b5f94f9 · Browse files · 2 files·+30 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−14 removed
- tests:+17 added−0 removed
- other:+13 added−14 removed
Provenance
- Commit
a6957ab- Tree
930ec5e- Author
LangLangBart <92653266+LangLangBart@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
b5f94f9
2 files changed+30 added−14 removed
modified:shell/completion.zsh+13 added-14 removed
120 unmodified lines121 }122 123 # Extract the name of the command. e.g. ls; foo=1 ssh **<tab>124 __fzf_extract_command() {125- setopt localoptions noksh_arrays125 # Control completion with the "compstate" parameter, insert and list nothing126 compstate[insert]=127 compstate[list]=128 cmd_word="${(Q)words[1]}"172 unmodified lines301 awk '{print $2}'302 }303 304 fzf-completion() {306- typeset -g cmd_word307- trap 'unset cmd_word' EXIT308- local tokens prefix trigger tail matches lbuf d_cmds cursor_pos305+ local tokens prefix trigger tail matches lbuf d_cmds cursor_pos cmd_word306 setopt localoptions noshwordsplit noksh_arrays noposixbuiltins307 311- # Check if at least one completion system (old or new) is active312- if ! zmodload -F zsh/parameter p:functions 2>/dev/null || ! (( ${+functions[compdef]} )); then313- if ! zmodload -e zsh/compctl; then314- zmodload -i zsh/compctl315- fi316- fi308 # http://zsh.sourceforge.net/FAQ/zshfaq03.html309 # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags310 tokens=(${(z)LBUFFER})311 if [ ${#tokens} -lt 1 ]; then17 unmodified lines329 # Trigger sequence given330 if [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then331 d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir})332 342- cursor_pos=$CURSOR333 {334+ cursor_pos=$CURSOR335 # Move the cursor before the trigger to preserve word array elements when336 # trigger chars like ';' or '`' would otherwise reset the 'words' array.337 CURSOR=$((cursor_pos - ${#trigger} - 1))347- # Assign the extracted command to the global variable 'cmd_word'338+ # Check if at least one completion system (old or new) is active.339+ # If at least one user-defined completion widget is detected, nothing will340+ # be completed if neither the old nor the new completion system is enabled.341+ # In such cases, the 'zsh/compctl' module is loaded as a fallback.342+ if ! zmodload -F zsh/parameter p:functions 2>/dev/null || ! (( ${+functions[compdef]} )); then343+ zmodload -F zsh/compctl 2>/dev/null344+ fi345+ # Create a completion widget to access the 'words' array (man zshcompwid)346+ zle -C __fzf_extract_command .complete-word __fzf_extract_command347 zle __fzf_extract_command348 } always {349 CURSOR=$cursor_pos350+ # Delete the completion widget351+ zle -D __fzf_extract_command 2>/dev/null352 }353 354 [ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}355 if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'>('* ]] || [[ $prefix = *':='* ]] || [[ $prefix = *'`'* ]]; then20 unmodified lines376 [[ $binding =~ 'undefined-key' ]] || fzf_default_completion=$binding[(s: :w)2]377 unset binding378 }379 379-# Completion widget to gain access to the 'words' array (man zshcompwid)380-zle -C __fzf_extract_command .complete-word __fzf_extract_command380 # Normal widget381 zle -N fzf-completion382 bindkey '^I' fzf-completion383 fi6 unmodified linesmodified:test/test_go.rb+17 added
3735 unmodified lines3736 tmux.send_keys :Enter3737 tmux.until { |lines| assert_equal 'unset FZFFOOBAR', lines[-1] }3738 end3739 3740+ def test_completion_in_command_sequence3741+ tmux.send_keys 'export FZFFOOBAR=BAZ', :Enter3742+ tmux.prepare3743+3744+ triggers = ['**', '~~', '++', 'ff', '/']3745+ triggers.concat(['&', '[', ';', '`']) if instance_of?(TestZsh)3746+3747+ triggers.each do |trigger|3748+ set_var('FZF_COMPLETION_TRIGGER', trigger)3749+ command = "echo foo; QUX=THUD unset FZFFOOBR#{trigger}"3750+ tmux.send_keys command.sub(/(;|`)$/, '\\\\\1'), :Tab3751+ tmux.until { |lines| assert_equal 1, lines.match_count }3752+ tmux.send_keys :Enter3753+ tmux.until { |lines| assert_equal 'echo foo; QUX=THUD unset FZFFOOBAR', lines[-1] }3754+ end3755+ end3756+3757 def test_file_completion_unicode3758 FileUtils.mkdir_p('/tmp/fzf-test')3759 tmux.paste "cd /tmp/fzf-test; echo test3 > $'fzf-unicode \\355\\205\\214\\354\\212\\244\\355\\212\\2701'; echo test4 > $'fzf-unicode \\355\\205\\214\\354\\212\\244\\355\\212\\2702'"3760 tmux.prepare209 unmodified lines