zsh-workers
 help / color / mirror / code / Atom feed
* completion function help
@ 2008-09-19 20:43 Bismark
  2008-09-19 20:54 ` Mikael Magnusson
  2008-09-22 14:39 ` Oliver Kiddle
  0 siblings, 2 replies; 4+ messages in thread
From: Bismark @ 2008-09-19 20:43 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

I'm trying to right a command completion function and I'm stuck.  I've
been looking through examples and the documentation but having no luck.

What I'm looking for is for the parameters for an option to a command to
have a description. I've gotten the completion to work for the command
but when I complete the option I only get the values.

$ medusa -
option
-C  -- File containing combo entries. (see man page)
-H  -- Reads Target specifications from a file.
-P  -- Reads Passwords from a file.
-U  -- Reads Usernames from a file.
-e  -- Additional password checks
-h  -- Target hostname or IP address.
-p  -- Password.
-u  -- Username.

$ medusa -e
Additional password checks
n   ns  s

I would like it to display something like the following

$ medusa -e
Additional password checks
n       -- No Password
s       -- Username = Password
ns      -- No Password & Username = Password

What is the best way to go about doing this?

--
Bis



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: completion function help
  2008-09-19 20:43 completion function help Bismark
@ 2008-09-19 20:54 ` Mikael Magnusson
  2008-09-22 17:16   ` Bismark
  2008-09-22 14:39 ` Oliver Kiddle
  1 sibling, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2008-09-19 20:54 UTC (permalink / raw)
  To: Bismark; +Cc: zsh-workers

2008/9/19 Bismark <bismark@foofus.net>:
> I'm trying to right a command completion function and I'm stuck.  I've
> been looking through examples and the documentation but having no luck.
>
> What I'm looking for is for the parameters for an option to a command to
> have a description. I've gotten the completion to work for the command
> but when I complete the option I only get the values.
>
> $ medusa -
> option
> -C  -- File containing combo entries. (see man page)
> -H  -- Reads Target specifications from a file.
> -P  -- Reads Passwords from a file.
> -U  -- Reads Usernames from a file.
> -e  -- Additional password checks
> -h  -- Target hostname or IP address.
> -p  -- Password.
> -u  -- Username.
>
> $ medusa -e
> Additional password checks
> n   ns  s
>
> I would like it to display something like the following
>
> $ medusa -e
> Additional password checks
> n       -- No Password
> s       -- Username = Password
> ns      -- No Password & Username = Password
>
> What is the best way to go about doing this?

It would of course help a lot if you also posted your code, but at a guess,
where you have -d array in your compdef call, change it to -ld array, where
array is the array with your descriptions, i think. Maybe the problem is
you don't have a -d array at all. ie
mydescriptions=('No Password' 'Username = Password' etc)
compdef blabla -ld mydescriptions blabla

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: completion function help
  2008-09-19 20:43 completion function help Bismark
  2008-09-19 20:54 ` Mikael Magnusson
@ 2008-09-22 14:39 ` Oliver Kiddle
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2008-09-22 14:39 UTC (permalink / raw)
  To: Bismark; +Cc: zsh-workers

On 19 Sep, Bismark wrote:
> What I'm looking for is for the parameters for an option to a command to
> have a description. I've gotten the completion to work for the command
> but when I complete the option I only get the values.

> I would like it to display something like the following
> 
> $ medusa -e
> Additional password checks
> n       -- No Password
> s       -- Username = Password
> ns      -- No Password & Username = Password

I'm guessing that you've got this far by using _arguments and passing it
something like the following:
  '-e[additional password checks]:check:(n s ns)' \

To add descriptions, you would use something like the following:
  '-e[additional password checks]:check:((n\:No\ password s\:Username\ =\ Password ns\:No\ Password\ \&\ Username\ =\ Password))'

I'm not familiar with the medusa software so can't say for sure if this
really is the right answer. You might actually want to use _values for
the list of checks.

Oliver


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: completion function help
  2008-09-19 20:54 ` Mikael Magnusson
@ 2008-09-22 17:16   ` Bismark
  0 siblings, 0 replies; 4+ messages in thread
From: Bismark @ 2008-09-22 17:16 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 4704 bytes --]

Mikael Magnusson wrote:
> 2008/9/19 Bismark <bismark@foofus.net>:
>> I'm trying to right a command completion function and I'm stuck.  I've
>> been looking through examples and the documentation but having no luck.
>>
>> What I'm looking for is for the parameters for an option to a command to
>> have a description. I've gotten the completion to work for the command
>> but when I complete the option I only get the values.
>>
>> $ medusa -
>> option
>> -C  -- File containing combo entries. (see man page)
>> -H  -- Reads Target specifications from a file.
>> -P  -- Reads Passwords from a file.
>> -U  -- Reads Usernames from a file.
>> -e  -- Additional password checks
>> -h  -- Target hostname or IP address.
>> -p  -- Password.
>> -u  -- Username.
>>
>> $ medusa -e
>> Additional password checks
>> n   ns  s
>>
>> I would like it to display something like the following
>>
>> $ medusa -e
>> Additional password checks
>> n       -- No Password
>> s       -- Username = Password
>> ns      -- No Password & Username = Password
>>
>> What is the best way to go about doing this?
> 
> It would of course help a lot if you also posted your code, but at a guess,
> where you have -d array in your compdef call, change it to -ld array, where
> array is the array with your descriptions, i think. Maybe the problem is
> you don't have a -d array at all. ie
> mydescriptions=('No Password' 'Username = Password' etc)
> compdef blabla -ld mydescriptions blabla

I'm doing this for Medusa http://www.foofus.net/jmk/medusa/medusa.html
by the way.

Yes including the code probably would have helped, sorry about that.  I
think I have it working now though I do not know if it's the proper or
most efficient way to do it. What I have so far is below:

####### _medusa ######
#compef medusa

local expl context state line ret=1

_select_module() {
        local modules
        modules=( $(medusa -d | grep + | awk '/.mod/ {print $2}' | cut
-d"." -f 1) )
        _wanted select-module expl 'Module' compadd "$@" -a - modules
}

_arguments \
        '-h[Target hostname or IP address.]:Hostname or IP Address' \
        '-H[Read Targets from a file.]:Hosts file:_files' \
        '-u[Username.]:Username' \
        '-U[Read Usernames from a file.]:Username file:_files' \
        '-p[Password.]:Password' \
        '-P[Read Passwords from a file.]:Password file:_files' \
        '-C[File containing combo entries. (see man page)]:Combo
file:_files' \
        "-e[Additional password checks]:Additional password
checks:_values 'Additional password checks' 'n[No Password]' 's[Password
= Username]' 'ns[No Password & Password = Username]'" \
        '-O[File to append log information to.]:xiLlog file:_files' \
        '-M[Name of the module to execute (without the .mod
extension)]:Module:_select_module' \
        '*-m[Parameter to pass to the module.]:Module Parameters' \
        '-d[Dump all known modules.]:Dump Modules' \
        '-n[Use for non-default TCP port number.]:tcp port' \
        '-s[Enable SSL.]:Enable SSL' \
        '-g[Give up after trying to connect for NUM seconds (default
3).]:Retry seconds' \
        '-r[Sleep number of seconds between retry attempts (default
3).]:Sleep seconds' \
        '-R[Attempted retries before giving up. The total number of
attempts will be retries + 1.]:Retries' \
        '-t[Total number of logins to be tested concurrently]:Concurrent
Logins' \
        '-T[Total number of hosts to be tested concurrently.]:Concurrent
Hosts' \
        '-L[Parallelize logins using one username per
thread.]:Parallelize' \
        '-f[Stop scanning host after first valid username/password
found.]:Stop scan after host' \
        '-F[Stop audit after first valid username/password found on any
host.]:Stop scan after username' \
        '-b[Suppress startup banner]:Suppress Banner' \
        '-q[Display module’s usage information.]:Module Usage' \
        '-v[Verbose level (0 - 6)]:Verbosity:(0 1 2 3 4 5 6)' \
        '-w[Error debug level (0 - 10)]:Debug:(0 1 2 3 4 5 6 7 8 9 10)' \
        '-V[Display version]:Version' && return 0

#### end _medusa ####

I also have a couple of other questions along with this one.

1) I know how to setup mutually exclusive arguments, is it possible to
configure prerequisite arguments? In medusa you have to select a module
'-M <module>' and then the individual modules themselves can have
additional arguments '-m <argument>', but -m doesn't do anything unless
-M is given.

2) If it is possible to do #1 can you get the value passed to -M to help
complete the values for the -m argument?

Thanks,
Bismark


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-22 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-19 20:43 completion function help Bismark
2008-09-19 20:54 ` Mikael Magnusson
2008-09-22 17:16   ` Bismark
2008-09-22 14:39 ` Oliver Kiddle

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).