* [PATCH] sudo strace -e <TAB>
@ 2015-03-07 4:27 Daniel Shahaf
2015-03-07 7:42 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2015-03-07 4:27 UTC (permalink / raw)
To: zsh-workers
The _sudo completion enters sudoedit mode even if -e is passed to the
command-under-sudo, rather than to sudo itself. Example: 'sudo strace
-e <TAB>' completes files, while 'strace -e <TAB>' completes syscalls,
as expected.
The following fixes this. While it causes 'sudo -A -e' to complete
commands rather than files, the alternative syntaxes 'sudoedit -A' and
'sudo -e -A' complete correctly. Also, the syntax 'sudo -Ae' doesn't
complete either with or without the patch.
I'm inclined to commit this since it there is no workaround for the
'sudo strace -e' breakage, but there is a workaround for the 'sudo -A
-e' breakage. (Also, I have used the former and never used the latter.)
Is there a smarter way to detect whether -e was passed to sudo?
I couldn't see how to get _arguments to tell me that bit.
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index ee238b4..90b34b3 100644
--- a/Completion/Unix/Command/_sudo
+++ b/Completion/Unix/Command/_sudo
@@ -29,7 +29,7 @@ args=(
'(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]"
)
-if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then
+if [[ $service = sudoedit || $words[2] == '-e' ]]; then
args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' )
else
args+=(
Thanks,
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sudo strace -e <TAB>
2015-03-07 4:27 [PATCH] sudo strace -e <TAB> Daniel Shahaf
@ 2015-03-07 7:42 ` Bart Schaefer
2015-03-09 19:57 ` Daniel Shahaf
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-03-07 7:42 UTC (permalink / raw)
To: zsh-workers
On Mar 7, 4:27am, Daniel Shahaf wrote:
} Subject: [PATCH] sudo strace -e <TAB>
}
} Is there a smarter way to detect whether -e was passed to sudo?
Perhaps
(( $words[(i)-e] < $words[(i)[^-]*] ))
would do? That is, the -e appears before the first word that doesn't
begin with a hyphen. The way (i) works in subscripts, the above will
always be true if all the words begin with a hyphen.
A slight tweak might fix the problem with -Ae not working:
(( $words[(i)-(e|Ae)] < $words[(i)[^-]*] ))
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sudo strace -e <TAB>
2015-03-07 7:42 ` Bart Schaefer
@ 2015-03-09 19:57 ` Daniel Shahaf
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2015-03-09 19:57 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]
Bart Schaefer wrote on Fri, Mar 06, 2015 at 23:42:25 -0800:
> On Mar 7, 4:27am, Daniel Shahaf wrote:
> } Subject: [PATCH] sudo strace -e <TAB>
> }
> } Is there a smarter way to detect whether -e was passed to sudo?
>
> Perhaps
>
> (( $words[(i)-e] < $words[(i)[^-]*] ))
>
> would do? That is, the -e appears before the first word that doesn't
> begin with a hyphen. The way (i) works in subscripts, the above will
> always be true if all the words begin with a hyphen.
Good idea, but the RHS will evaluate to 1 since the command word doesn't
begin with a hyphen. This seems to work (with extended_glob):
(( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] ))
> A slight tweak might fix the problem with -Ae not working:
>
> (( $words[(i)-(e|Ae)] < $words[(i)[^-]*] ))
-Ae was just an example, 'sudoedit' takes a few other flags (equivalent
to getopts "AnSC:g:p:u:"). As you can see, some of these flags take
arguments, which may be in separate words. And then there's the '--'
arguments terminator.
I'm not going to try and handle all those cases. (How common is
sudoedit -[x] to begin with, anyway?) The right way is for _arguments
to extract that information and provide it back to _sudo. (I don't
think that's currently possible; the -> syntax is in the {action} field
and -e doesn't take an argument, so there's no way to specify an
{action} for it.)
Cheers,
Daniel
[-- Attachment #2: 0001-_strace-Fix-variable-leakage-of-sys_calls.patch --]
[-- Type: text/x-patch, Size: 730 bytes --]
>From 46aed0420bb7b01db8a7ad60fbd2e6d78a0ec087 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Sat, 7 Mar 2015 15:28:27 +0000
Subject: [PATCH 1/2] _strace: Fix variable leakage of $sys_calls
---
Completion/Linux/Command/_strace | 1 +
1 file changed, 1 insertion(+)
diff --git a/Completion/Linux/Command/_strace b/Completion/Linux/Command/_strace
index 45ebfcf..d6dabfd 100644
--- a/Completion/Linux/Command/_strace
+++ b/Completion/Linux/Command/_strace
@@ -5,6 +5,7 @@
# - allow negated calls (e.g. -e!write)
_sys_calls () {
local expl
+ local -a sys_calls
sys_calls=(_llseek _newselect _sysctl accept access acct
adjtimex afs_syscall alarm bdflush bind break brk cacheflush
--
1.9.1
[-- Attachment #3: 0002-sudo-completion-Don-t-false-positive-sudo-e-detectio.patch --]
[-- Type: text/x-patch, Size: 1256 bytes --]
>From 8baf05d0ad7ea482df6329da13c67695085a0d87 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Sat, 7 Mar 2015 15:31:14 +0000
Subject: [PATCH 2/2] sudo completion: Don't false positive 'sudo -e' detection
---
Completion/Unix/Command/_sudo | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index ee238b4..63ac37f 100644
--- a/Completion/Unix/Command/_sudo
+++ b/Completion/Unix/Command/_sudo
@@ -1,5 +1,7 @@
#compdef sudo sudoedit
+setopt localoptions extended_glob
+
local environ e
local -a args
@@ -29,7 +31,12 @@ args=(
'(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]"
)
-if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then
+# Does -e appears before the first word that doesn't begin with a hyphen?
+# The way (i) works in subscripts, the test will always be true if all the
+# words begin with a hyphen.
+#
+# TODO: use _arguments' $opt_args to detect the cases '-u jrandom -e' and '-Ae'
+if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) ; then
args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' )
else
args+=(
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-09 19:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-07 4:27 [PATCH] sudo strace -e <TAB> Daniel Shahaf
2015-03-07 7:42 ` Bart Schaefer
2015-03-09 19:57 ` 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).