* [PATCH] Correct completion of 'tmux new <TAB>'.
@ 2017-07-20 20:58 Daniel Shahaf
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-07-20 20:58 UTC (permalink / raw)
To: zsh-workers; +Cc: Daniel Shahaf
Reference: window_pane_spawn() in tmux 2.5.
Also, document _cmdstring and _precommand.
---
To reproduce:
% touch foo\ bar
% tmux new ls ./foo<TAB>
% tmux new ls\ ./foo<TAB>
Use remain-on-exit (or a script that calls ls and sleeps) to see the difference.
Cheers,
Daniel
Completion/Unix/Command/_tmux | 2 +-
Doc/Zsh/compsys.yo | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_tmux b/Completion/Unix/Command/_tmux
index 0917da604..5f5bea922 100644
--- a/Completion/Unix/Command/_tmux
+++ b/Completion/Unix/Command/_tmux
@@ -526,7 +526,7 @@ _tmux-new-session() {
'-t+[specify target session]:session:__tmux-sessions' \
'-x[specify width]:width' \
'-y[specify height]:height' \
- '*:: :_cmdstring'
+ '*:: :_cmdambivalent'
}
_tmux-new-window() {
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 47b07e85e..47c30843c 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3014,6 +3014,17 @@ tt(-n), tt(-F), tt(-X) are passed to tt(compadd).
See tt(_description) for a description of var(tag) and var(descr).
)
+findex(_cmdambivalent)
+item(tt(_cmdambivalent))(
+Completes an external command.
+If there is a single argument, complete the command in a single word, like tt(_cmdstring);
+otherwise, complete the command in word-separated arguments, like tt(_precommand).
+)
+findex(_cmdstring)
+item(tt(_cmdstring))(
+Completes an external command as a single argument, as for
+tt(system+LPAR()...+RPAR()).
+)
findex(_complete)
item(tt(_complete))(
This completer generates all possible completions in a context-sensitive
@@ -3214,6 +3225,11 @@ tt(old-menu), see
ifzman(the section `Completion System Configuration' above)\
ifnzman(noderef(Completion System Configuration)).
)
+findex(_precommand)
+item(tt(_precommand))(
+Complete an external command in word-separated arguments, as for
+tt(exec) and tt(/usr/bin/env).
+)
findex(_prefix)
item(tt(_prefix))(
This completer can be used to try completion with the suffix (everything
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] Correct completion of 'tmux new <TAB>'.
@ 2017-07-26 14:55 Daniel Shahaf
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-07-26 14:55 UTC (permalink / raw)
To: zsh-workers
Reference: window_pane_spawn() in tmux 2.5.
Also, document _cmdstring and _precommand.
---
I think this implements all feedback from the previous thread.
I noticed two related issues:
1.
% sh -c 'rsync --dele<TAB>
removes the leading quote.
2.
% sh -c '/usr/bin/rsyn<TAB>
adds the «c» (since "/usr/bin/rsync" is the unique completion) but doesn't add
space afterwards.
Cheers,
Daniel
Completion/Unix/Command/_tmux | 2 +-
Completion/Unix/Type/_cmdambivalent | 17 +++++++++++++++++
Doc/Zsh/compsys.yo | 21 +++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 Completion/Unix/Type/_cmdambivalent
diff --git a/Completion/Unix/Command/_tmux b/Completion/Unix/Command/_tmux
index 0917da604..5f5bea922 100644
--- a/Completion/Unix/Command/_tmux
+++ b/Completion/Unix/Command/_tmux
@@ -526,7 +526,7 @@ _tmux-new-session() {
'-t+[specify target session]:session:__tmux-sessions' \
'-x[specify width]:width' \
'-y[specify height]:height' \
- '*:: :_cmdstring'
+ '*:: :_cmdambivalent'
}
_tmux-new-window() {
diff --git a/Completion/Unix/Type/_cmdambivalent b/Completion/Unix/Type/_cmdambivalent
new file mode 100644
index 000000000..1f15d11ab
--- /dev/null
+++ b/Completion/Unix/Type/_cmdambivalent
@@ -0,0 +1,17 @@
+#autoload
+
+if (( CURRENT == 1 && ${#words} == 1 )); then
+ # Heuristics to decide whether to complete for system() or for execl().
+ local space=' '
+ if (( ${${words[CURRENT]}[(I)$space]} )); then
+ _cmdstring
+ elif [[ ${${compstate[all_quotes]}[1]} == (\'|\") ]]; then
+ _cmdstring
+ else
+ _command_names -e
+ fi
+elif (( CURRENT == 1 )); then
+ _command_names -e
+else
+ _normal
+fi
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 47b07e85e..36afd7305 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3014,6 +3014,22 @@ tt(-n), tt(-F), tt(-X) are passed to tt(compadd).
See tt(_description) for a description of var(tag) and var(descr).
)
+findex(_cmdambivalent)
+item(tt(_cmdambivalent))(
+Completes the remaining positional arguments as an external command.
+The external command and its arguments are completed as separate arguments
+(in a manner appropriate for completing tt(/usr/bin/env))
+if there are two or more remaining positional arguments on the command line,
+and as a quoted command string (in the manner of tt(system+LPAR()...+RPAR())) otherwise.
+See also tt(_cmdstring) and tt(_precommand).
+
+This function takes no arguments.
+)
+findex(_cmdstring)
+item(tt(_cmdstring))(
+Completes an external command as a single argument, as for
+tt(system+LPAR()...+RPAR()).
+)
findex(_complete)
item(tt(_complete))(
This completer generates all possible completions in a context-sensitive
@@ -3214,6 +3230,11 @@ tt(old-menu), see
ifzman(the section `Completion System Configuration' above)\
ifnzman(noderef(Completion System Configuration)).
)
+findex(_precommand)
+item(tt(_precommand))(
+Complete an external command in word-separated arguments, as for
+tt(exec) and tt(/usr/bin/env).
+)
findex(_prefix)
item(tt(_prefix))(
This completer can be used to try completion with the suffix (everything
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-26 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-20 20:58 [PATCH] Correct completion of 'tmux new <TAB>' Daniel Shahaf
2017-07-26 14:55 Daniel Shahaf
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).