* GPG completion function @ 2001-09-16 22:05 Bruno Bonfils 2001-09-17 14:07 ` Oliver Kiddle 0 siblings, 1 reply; 6+ messages in thread From: Bruno Bonfils @ 2001-09-16 22:05 UTC (permalink / raw) To: zsh-workers [-- Attachment #1.1: Type: text/plain, Size: 626 bytes --] hi all, i submit you my first completion function (for gpg) i don't have finish completely, but i send you in order to have comments/idea. _any_ comments/ideas are welcome thank you very much for this very powerfull shell (i fall in love :) ++ -- Bruno Bonfils Admin Sys Linux http://www.darksnow.org http://www.debian-fr.org Selon les logs, il y a des pertes de porteuses, mais surtout des requêtes de déconnexion qui viennent de votre machine. Il faut se rappeler que windows 95 est un systeme bio-dégradable. -+- Support technique HOL in: Guide du Cabaliste Usenet - CQFD ! -+- [-- Attachment #1.2: _gpg --] [-- Type: text/plain, Size: 2832 bytes --] #compdef gpg # Author : Bruno Bonfils <asyd@debian-fr.org> # Date : Sept 2001 local context state line typeset -A opt_args _pub-keys-list () { local keys_list # i must rewrite this line using pattern matching for name in `gpg --list-keys | awk '/^pub/ { print $NF }' | tr "<|>" -d` do compadd "$name"; done } _arguments -C -s \ '-a[create ASCII armored output]' \ '-o[write output to file]:_files attachment:_files' \ '-u[use name as the user ID to sign]'\ '-b[make a detached signature]' \ '-s[sign a file]:file attachment:_files' \ '-e[encrypt data. this option may be combined with --sign]' \ '-h[help]' \ '--clearsign[make a clear text signature]' \ '--check-sigs[verify all signatures]' \ '--decrypt[decrypt file or stdin]:file attachment:_files' \ '--delete-key[remove key from public keyring]:key attachment:_pub-keys-list' \ '--delete-secret-key[remove key from public & private keyring]' \ '--delete-secret-and-public-key[remove key from private & public keyring]' \ '--edit-key[a menu for edit yours keys]:key attachment:_pub-keys-list' \ '--export[export all key from all keyrings]' \ '--export-all[export all key and not OpenPGP compatible keys]' \ '--export-ownertrust[list the assigned ownertrust values in ASCII format]' \ '--export-secret-keys[export a list of secret keys]' \ '--export-secret-subkeys[same as --export but export the secret keys instead'] \ '--fast-import[import a file without build trustdb]:_files attachment:_files' \ '--fingerprint[list all keys with their fingerprints]' \ '--gen-key[generate a new pair key]' \ '--gen-random[emit random bytes of the given level quality]' \ '--gen-prime[use the source, luke :-)]' \ '--import[import a gpg key from a file]:_files attachment:_files' \ '--import-ownertrust[update the trustdb with a file]:_files attachment:_files'\ '--keyserver[use server for send/recv keys]:_hosts attachment:_hosts' \ '--list-keys[list all keys]:key attachment:_pub-keys-list' \ '--list-public-keys[list all public keys]:key attachment:_pub-keys-list' \ '--list-secret-keys[list all secret keys]:key attachment:_pub-keys-list' \ '--list-packets[list only the sequence of packets]' \ '--lsign-key[sign a key but mark not is as non-exportable]:key attachment:_pub-keys-list' \ '--print-md[Print message digest of the given algorithm for all given files]' \ '--recv-keys[receive a list of keys from a keyserver]' \ '--send-keys[send keys to a keyserver]:key attachment:_pub-keys-list' \ '--sign-key[sign a key]:key attachment:_pub-keys-list '\ '--store[store only]' \ '--trusted-key[assume that the specified key is trustworthy]' \ '--verify[verify a signature]' \ '--verify-files[verify a list of files]:file attachment:_files' \ && return 0 return 1 [-- Attachment #2: Type: application/pgp-signature, Size: 249 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GPG completion function 2001-09-16 22:05 GPG completion function Bruno Bonfils @ 2001-09-17 14:07 ` Oliver Kiddle 2001-09-17 14:17 ` Bruno Bonfils 2001-09-17 16:15 ` Bruno Bonfils 0 siblings, 2 replies; 6+ messages in thread From: Oliver Kiddle @ 2001-09-17 14:07 UTC (permalink / raw) To: Bruno Bonfils; +Cc: zsh-workers Bruno Bonfils wrote: > > i submit you my first completion function (for gpg) > > i don't have finish completely, but i send you in order > to have comments/idea. Looks good. Let us know when it is finished and we can include it in the distribution. > _any_ comments/ideas are welcome Mainly it looks fine. I've added a few comments though within limits as I'm not familiar with usage of gpg. > local context state line You only need these declared if you use states with _arguments. With -C to _arguments the form would be slightly different actually. I suspect the final version may use states though. > typeset -A opt_args I think you only need this if you're going to use it. > local keys_list You don't need that any more but `name' needs to be declared local. > # i must rewrite this line using pattern matching > for name in `gpg --list-keys | awk '/^pub/ { print $NF }' | tr "<|>" -d` > do > compadd "$name"; > done As you say in the comment this could be rewritten with a zsh substitution using pattern matching. You then shouldn't need the for loop. It could do with then using _wanted with the compadd to assign a tag and description. Also, you will need to redirect stderr from gpg --list-keys so anyone who hasn't used gpg ever will get nothing completed instead of error messages. > _arguments -C -s \ > '-a[create ASCII armored output]' \ > '-o[write output to file]:_files attachment:_files' \ Your description on that line and others is messed up. I'd need to know more about gpg usage but the file attachment maybe could be completed with a '1' or '*' spec to _arguments. > '-u[use name as the user ID to sign]'\ I think that needs to be -u+[... The plus indicates that the username can be specified imediately after -u without a space, or a space can be used. > '-s[sign a file]:file attachment:_files' \ I see that options like this have a long form as well. Zsh 4.1.x can recognise this and list them together so I'd suggest using something like: '(-s --sign)'{-s,--sign}'[sign a file]:file attachment:_files' It seems that you still have a few gpg options to add to it. There are also no exclusion lists - I take it that -e and -s can not be used together for example. I hope that is helpful Oliver _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GPG completion function 2001-09-17 14:07 ` Oliver Kiddle @ 2001-09-17 14:17 ` Bruno Bonfils 2001-09-17 16:15 ` Bruno Bonfils 1 sibling, 0 replies; 6+ messages in thread From: Bruno Bonfils @ 2001-09-17 14:17 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 612 bytes --] Le lun 17 septembre, Oliver Kiddle a écrit : > > I hope that is helpful very much !!! i modify my function Thant you > > Oliver > > _____________________________________________________________________ > This message has been checked for all known viruses by the > MessageLabs Virus Scanning Service. For further information visit > http://www.messagelabs.com/stats.asp -- Bruno Bonfils Admin Sys Linux http://www.darksnow.org http://www.debian-fr.org Arrêtez de poster des AAD, cela encombre le forum. -+- EN in: Guide du Cabaliste Usenet - fufer en nettoyant -+- [-- Attachment #2: Type: application/pgp-signature, Size: 249 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GPG completion function 2001-09-17 14:07 ` Oliver Kiddle 2001-09-17 14:17 ` Bruno Bonfils @ 2001-09-17 16:15 ` Bruno Bonfils 2001-09-17 19:45 ` new version of " Bruno Bonfils 2001-09-18 13:43 ` Oliver Kiddle 1 sibling, 2 replies; 6+ messages in thread From: Bruno Bonfils @ 2001-09-17 16:15 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 3576 bytes --] Le lun 17 septembre, Oliver Kiddle a écrit : > Bruno Bonfils wrote: > > > > i submit you my first completion function (for gpg) > > > > i don't have finish completely, but i send you in order > > to have comments/idea. > > Looks good. Let us know when it is finished and we can include it in > the distribution. > > > _any_ comments/ideas are welcome > > Mainly it looks fine. I've added a few comments though within limits as > I'm not familiar with usage of gpg. > > > local context state line > > You only need these declared if you use states with _arguments. With -C > to _arguments the form would be slightly different actually. I suspect > the final version may use states though. > i believe that some functions declared this var without using them. That's why i write this line > > typeset -A opt_args > > I think you only need this if you're going to use it. > ok > > local keys_list > > You don't need that any more but `name' needs to be declared local. > yes, i forgot to remplace keys_list by name (grrr) > > # i must rewrite this line using pattern matching > > for name in `gpg --list-keys | awk '/^pub/ { print $NF }' | tr "<|>" -d` > > do > > compadd "$name"; > > done > > As you say in the comment this could be rewritten with a zsh > substitution using pattern matching. You then shouldn't need the for > loop. It could do with then using _wanted with the compadd to assign a > tag and description. Also, you will need to redirect stderr from gpg > --list-keys so anyone who hasn't used gpg ever will get nothing > completed instead of error messages. i need to read and reread doc, i have some difficulty with pattern matching > > > _arguments -C -s \ > > '-a[create ASCII armored output]' \ > > '-o[write output to file]:_files attachment:_files' \ > > Your description on that line and others is messed up. I'd need to know > more about gpg usage but the file attachment maybe could be completed > with a '1' or '*' spec to _arguments. > i don't understand completely. you mean that i delete all descriptions (which comes from gpg's manpage) ? > > '-u[use name as the user ID to sign]'\ > > I think that needs to be -u+[... The plus indicates that the username > can be specified imediately after -u without a space, or a space can be > used. > ok > > '-s[sign a file]:file attachment:_files' \ > > I see that options like this have a long form as well. Zsh 4.1.x can > recognise this and list them together so I'd suggest using something > like: '(-s --sign)'{-s,--sign}'[sign a file]:file attachment:_files' ok it is possible to tell zsh there maybe more than 1 file after the option ? > It seems that you still have a few gpg options to add to it. There are > also > no exclusion lists - I take it that -e and -s can not be used together > for example. > > I hope that is helpful > Thank you very I'm sorry for my mistakes (i'm beginner, i use zsh since 2 months) and for my __very__ poor english > Oliver > > _____________________________________________________________________ > This message has been checked for all known viruses by the > MessageLabs Virus Scanning Service. For further information visit > http://www.messagelabs.com/stats.asp -- Bruno Bonfils Admin Sys Linux http://www.darksnow.org http://www.debian-fr.org Si la connerie était cotée en bourse,tu serais incarcéré pour délit d'initié... -+- EB in: Guide du Cabaliste Usenet - Les initiés ont la cote -+- [-- Attachment #2: Type: application/pgp-signature, Size: 249 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: new version of GPG completion function 2001-09-17 16:15 ` Bruno Bonfils @ 2001-09-17 19:45 ` Bruno Bonfils 2001-09-18 13:43 ` Oliver Kiddle 1 sibling, 0 replies; 6+ messages in thread From: Bruno Bonfils @ 2001-09-17 19:45 UTC (permalink / raw) To: zsh-workers [-- Attachment #1.1: Type: text/plain, Size: 456 bytes --] hi all, i corrige my function i'm happy because i success to use pattern matching :) but there is yet some problems.. (like optionnel argument of an option, is there the -w option of _arguments ?) (Note : /join #zsh (OPN) ) -- Bruno Bonfils Admin Sys Linux http://www.darksnow.org http://www.debian-fr.org <Pingouino> X windows c un concurrent de Windows Manager ? - #linuxfr [-- Attachment #1.2: _gpg --] [-- Type: text/plain, Size: 3335 bytes --] #compdef gpg # Author : Bruno Bonfils <asyd@debian-fr.org> # Date : Sept 2001 # Thanks to Oliver Kiddle and Denis Bodor _pub-keys-list () { local list list=(${${(Mo)$(gpg --list-keys 2>/dev/null):%<*>}//(<|>)/}) compadd $list } _sec-keys-list () { local list list=(${${(Mo)$(gpg --list-secret-keys 2>/dev/null):%<*>}//(<|>)/}) compadd $list } _arguments -C -s \ '-a[create ASCII armored output]' \ '-o[write output to file]:_files attachment:_files' \ '-u+[use name as the user ID to sign]:user attachment:_users'\ '(-b --detach-sign)'{-b,--detach-sign}'[make a detached signature]' \ '(-s --sign)'{-s,--sign}'[sign a file]:file attachment:_files' \ '(-e --encrypt)'{-e,--encrypt}'[encrypt data. this option may be combined with --sign]' \ '(-c --symetric)'{-c,--symetric}'[encrypt with symmetric cypher only]' \ '-h[help]' \ '--clearsign[make a clear text signature]' \ '--check-sigs[lists key, signatures and check them]:key attachment:_pub-keys-list' \ '--decrypt[decrypt file or stdin]:file attachment:_files' \ '--delete-key[remove key from public keyring]:key attachment:_pub-keys-list' \ '--delete-secret-key[remove key from public & private keyring]:key attachment:_sec-keys-list' \ '--delete-secret-and-public-key[remove key from private & public keyring]:key attachment:_sec-keys-list' \ '--edit-key[a menu for edit yours keys]:key attachment:_pub-keys-list' \ '--export[export all key from all keyrings]:key attachment:_pub-keys-list' \ '--export-all[export all key and not OpenPGP compatible keys]' \ '--export-ownertrust[list the assigned ownertrust values in ASCII format]' \ '--export-secret-keys[export a list of secret keys]:key attachment:_sec-keys-list' \ '--export-secret-subkeys[same as --export but export the secret keys instead]:key attachment:_sec-keys-list' \ '--fast-import[import a file without build trustdb]:_files attachment:_files' \ '--fingerprint[list all keys with their fingerprints]:key attachment:_pub-keys-list' \ '--gen-key[generate a new pair key]' \ '--gen-random[emit random bytes of the given level quality]' \ '--gen-prime[use the source, luke :-)]' \ '--import[import a gpg key from a file]:_files attachment:_files' \ '--import-ownertrust[update the trustdb with a file]:_files attachment:_files'\ '--keyserver[use server for send/recv keys]:_hosts attachment:_hosts' \ '--list-keys[list all keys]:key attachment:_pub-keys-list' \ '--list-public-keys[list all public keys]:key attachment:_pub-keys-list' \ '--list-secret-keys[list all secret keys]:key attachment:_pub-keys-list' \ '--list-packets[list only the sequence of packets]' \ '--list-sigs[lists keys and signatures]:key attachment:_pub-keys-list' \ '--lsign-key[sign a key but mark not is as non-exportable]:key attachment:_pub-keys-list' \ '--print-md[Print message digest of the given algorithm for all given files]' \ '--recv-keys[receive a list of keys from a keyserver]:key attachment:_pub-keys-list' \ '--send-keys[send keys to a keyserver]:key attachment:_pub-keys-list' \ '--sign-key[sign a key]:key attachment:_pub-keys-list '\ '--store[store only]' \ '--trusted-key[assume that the specified key is trustworthy]' \ '--verify[verify a signature]:file attachment:_files' \ '--verify-files[verify a list of files]:_files attachment_files' \ && return 0 return 1 [-- Attachment #2: Type: application/pgp-signature, Size: 249 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GPG completion function 2001-09-17 16:15 ` Bruno Bonfils 2001-09-17 19:45 ` new version of " Bruno Bonfils @ 2001-09-18 13:43 ` Oliver Kiddle 1 sibling, 0 replies; 6+ messages in thread From: Oliver Kiddle @ 2001-09-18 13:43 UTC (permalink / raw) To: Bruno Bonfils; +Cc: zsh-workers [-- Attachment #1: Type: text/plain, Size: 3229 bytes --] Bruno Bonfils wrote: > > > > local context state line > > > i believe that some functions declared this var without using them. That's why > i write this line They are used internally to _arguments for calls which use states so the functions probably do use them, just it isn't imediately apparent. > > > '-s[sign a file]:file attachment:_files' \ > it is possible to tell zsh there maybe more than 1 file after the > option ? Yes. '-s[sign a file]:*:file attachment:_files' I think it is. Though that isn't exactly what you want to do in this case. > > > '-o[write output to file]:_files attachment:_files' \ > > > > Your description on that line and others is messed up. I'd need to know > > more about gpg usage but the file attachment maybe could be completed > > with a '1' or '*' spec to _arguments. > > > i don't understand completely. you mean that i delete all descriptions > (which comes from gpg's manpage) ? I was refering to the `_files attachment' description which is the description used when completing the output file with _files. I might use `output file' here. Perhaps you don't see these descriptions because you won't by default. zstyle ':completion:*:descriptions' format '%B%d%b' enables them (displayed in bold). > _pub-keys-list () > { > local list > list=(${${(Mo)$(gpg --list-keys 2>/dev/null):%<*>}//(<|>)/}) > compadd $list > } You could use `compadd -a list' as a slightly more efficient alternative to that though in this case, you can just put the parameter substitution directly as an argument to compadd. It is also useful to use _wanted here. I've made this change in an attached _gpg and have also added a few more gpg options. I've now had a slightly closer look at gpg. You've not picked the easiest command to start with. gpg arguments are in this form: gpg [options] command [options] [args] The commands look like options (e.g. --export) but affect the type of the final [args]. You are also allowed things like `--export --armour key' where another option (--armor) intervenes between the command and the args. So basically, instead of completing public keys as an argument to --export, we need to setup something for completing the final args which looks back to see which command has been used. To do this, I've added '*:args:->args' to the _arguments specs. This says that for the non-option arguments enter the args state. The state handler for `args' then checks which gpg command was used to select between completing keys, secret keys and files. Other options, e.g. --recipient can use the public-key and secret-key states to complete single keys as arguments instead of the functions. There is still a good deal to do on this: exclusion lists are needed for incompatible commands (e.g. --export and --decrypt), any command such as --gen-key which allows no args needs to exclude '*', more commands need to use the states, and there are many options which this still doesn't complete. Oliver _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp [-- Attachment #2: _gpg --] [-- Type: text/plain, Size: 4239 bytes --] #compdef gpg # Author : Bruno Bonfils <asyd@debian-fr.org> # Date : Sept 2001 # Thanks to Oliver Kiddle and Denis Bodor local curcontext="$curcontext" state line expl typeset -A opt_args _arguments -C -s -S -A "-*" \ '(-a --armor)'{-a,--armor}'[create ASCII armored output]' \ '(-o --output)'{-o+,--output}'[write output to file]:output file:_files' \ '(-u --local-user)'{-u+,--local-user}'[use name as the user ID to sign]:user attachment:_users'\ '(-b --detach-sign)'{-b,--detach-sign}'[make a detached signature]' \ '(-s --sign)'{-s,--sign}'[sign a file]' \ '(-e --encrypt)'{-e,--encrypt}'[encrypt data. this option may be combined with --sign]' \ '(-c --symmetric)'{-c,--symmetric}'[encrypt with symmetric cypher only]' \ '(-h --help)'{-h,--help}'[display usage information]' \ '(-n --dry-run)'{-n,--dry-run}"[don't make any changes]" \ '(-q --quiet -v --verbose)'{-q,--quiet}'[reduce amount of output]' \ '(-q --quiet)*'{-v,--verbose}'[increase amount of output]' \ '*'{-r+,--recipient}'[specify user to encrypt for]:recipient:->public-key' \ '--clearsign[make a clear text signature]' \ '--charset[specify native character set]:character set:(iso-8859-1 iso-8859-2 koi8-r utf-8)' \ '--check-sigs[lists key, signatures and check them]:key attachment:_pub-keys-list' \ '--decrypt[decrypt file or stdin]' \ '--delete-key[remove key from public keyring]:key attachment:_pub-keys-list' \ '--delete-secret-key[remove key from public & private keyring]:key attachment:_sec-keys-list' \ '--delete-secret-and-public-key[remove key from private & public keyring]:key attachment:_sec-keys-list' \ '--edit-key[a menu for edit yours keys]:key attachment:_pub-keys-list' \ '--export[export all key from all keyrings]' \ '--export-all[export all key and not OpenPGP compatible keys]' \ '--export-ownertrust[list the assigned ownertrust values in ASCII format]' \ '--export-secret-keys[export a list of secret keys]:key attachment:_sec-keys-list' \ '--export-secret-subkeys[same as --export but export the secret keys instead]:key attachment:_sec-keys-list' \ '--fast-import[import a file without build trustdb]:_files attachment:_files' \ '--fingerprint[list all keys with their fingerprints]:key attachment:_pub-keys-list' \ '(*)--gen-key[generate a new pair key]' \ '--gen-random[emit random bytes of the given level quality]' \ '--gen-prime[use the source, luke :-)]' \ '--import[import a gpg key from a file]:_files attachment:_files' \ '--import-ownertrust[update the trustdb with a file]:_files attachment:_files'\ '--keyserver[use server for send/recv keys]:_hosts attachment:_hosts' \ '--list-keys[list all keys]' \ '--list-public-keys[list all public keys]' \ '--list-secret-keys[list all secret keys]' \ '--list-packets[list only the sequence of packets]' \ '--list-sigs[lists keys and signatures]:key attachment:_pub-keys-list' \ '--lsign-key[sign a key but mark not is as non-exportable]:key attachment:_pub-keys-list' \ '(--no-options)--options[specify file to read options from]:options file:_files' \ "(--options)--no-options[don't read options file]" \ '--print-md[print message digest of the given algorithm for all given files]' \ '--recv-keys[receive a list of keys from a keyserver]:key attachment:_pub-keys-list' \ '--send-keys[send keys to a keyserver]:key attachment:_pub-keys-list' \ '--sign-key[sign a key]:key attachment:_pub-keys-list '\ '--store[store only]' \ '--trusted-key[assume that the specified key is trustworthy]' \ '--verify[verify a signature]:file attachment:_files' \ '--verify-files[verify a list of files]:_files attachment_files' \ '*:args:->args' && return if [[ $state = args ]]; then if (( ${+opt_args[--export]} || ${+opt_args[--list-keys]} )); then state=public-key elif (( ${+opt_args[--list-secret-keys]} )); then state=secret-key else _files && return fi fi case "$state" in public-key) _wanted public-keys expl 'public key' \ compadd ${${(Mo)$(gpg --list-keys 2>/dev/null):%<*>}//(<|>)/} && return ;; secret-key) _wanted secretkeys expl 'secret key' compadd \ ${${(Mo)$(gpg --list-secret-keys 2>/dev/null):%<*>}//(<|>)/} && return ;; esac return 1 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-09-18 13:46 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-09-16 22:05 GPG completion function Bruno Bonfils 2001-09-17 14:07 ` Oliver Kiddle 2001-09-17 14:17 ` Bruno Bonfils 2001-09-17 16:15 ` Bruno Bonfils 2001-09-17 19:45 ` new version of " Bruno Bonfils 2001-09-18 13:43 ` 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).