From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1910 invoked by alias); 2 May 2012 14:38:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30466 Received: (qmail 15153 invoked from network); 2 May 2012 14:38:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.217.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer; bh=5s511wwZ4jRfuVSbcuD1Gfn9taNa0TBas4A/EJBPDmY=; b=f1VR46fqEWouMoanu8wBQl6itckU5SWD/MTQZpSYLOxo4YHHWYJL33YjNsYJhGQQTI Llu1TInU866XXm9laxh0nMHwdcLJKTxWxnyu/mYmMD7me/sll1lo2Mi5L0tTdSf/eEUG /8ZMAdEOye+A2ftDUI/RGNVafrReB/Es94r4DiWiKU0p1EFqiyvVZUh/U778REYj44RC QhXeSL8CI5D5fdplJC/IxuQq0GMUG+mNSBQasQmulN5hbAJa6vQdo69OqfFJLJ/AUgaa KHzV1soX7DacoWI8kuQnIQWGc2QfAgpVdann5iQ1vafj9YqWFeFfJLxygE1P+xeEPhx5 4G+A== From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: _print, _ps1234: complete printf and prompt formats, add completer for $PROMPT and friends Date: Wed, 2 May 2012 16:38:05 +0200 Message-Id: <1335969485-3347-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.10.GIT I think I've posted the _ps1234 completer before but I don't remember getting any comments then. Since then I've also added a printf format completer and hooked them both up to print -f/P. --- Completion/Unix/Type/.distfiles | 1 + Completion/Unix/Type/_ps1234 | 103 ++++++++++++++++++++++++++++++++++ Completion/Zsh/Command/_print | 116 ++++++++++++++++++++++++++++----------- 3 files changed, 188 insertions(+), 32 deletions(-) create mode 100644 Completion/Unix/Type/_ps1234 diff --git a/Completion/Unix/Type/.distfiles b/Completion/Unix/Type/.distfiles index 4c0d688..a9dc0d1 100644 --- a/Completion/Unix/Type/.distfiles +++ b/Completion/Unix/Type/.distfiles @@ -36,6 +36,7 @@ _pids _ports _printers _ps +_ps1234 _pspdf _services _signals diff --git a/Completion/Unix/Type/_ps1234 b/Completion/Unix/Type/_ps1234 new file mode 100644 index 0000000..32ff26a --- /dev/null +++ b/Completion/Unix/Type/_ps1234 @@ -0,0 +1,103 @@ +#compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- + +local -a specs +local expl paren + +if [[ -n $compstate[quote] ]]; then + paren='(' +else + paren='\(' +fi + +if [[ $PREFIX == *%(-|)<-># ]]; then + specs=( + 'm:hostname up to first .' + '_:status of parser' + 'd:current working directory' + '/:current working directory' + '~:current working directory, with ~ replacement' + 'N:name of current script or shell function' + 'x:name of file containing code being executed' + 'c:deprecated' + '.:deprecated' + 'C:deprecated' + 'F:start using fg color' + 'K:start using bg color' + 'G:counts as extra character inside %{...%}' + ) + if [[ $PREFIX == *% ]]; then + specs+=( + '%:A %' + '):A )' + 'l:current line (tty) with /dev/tty stripped' + 'M:full hostname' + 'n:username' + 'y:current line (tty)' + '#:a # when root, % otherwise' + '?:return status of last command' + 'h:current history event number' + '!:current history event number' + 'i:current line number' + 'I:current source line number' + 'j:number of jobs' + 'L:$SHLVL' + 'D:date in yy-mm-dd format' + 'T:current time of day, 24-hour format' + 't:current time of day, 12-hour am/pm format' + '@:current time of day, 12-hour am/pm format' + '*:current time of day, 24-hour format with seconds' + 'w:the date in day-dd format' + 'W:the date in mm/dd/yy format' + 'D{}:format string like strftime' + 'B:start bold' + 'b:stop bold' + 'E:clear to end of line' + 'U:start underline' + 'u:stop underline' + 'S:start standout' + 's:stop standout' + 'f:reset fg color' + 'k:reset bg color' + '{:start literal escape sequence' + '}:stop literal escape sequence' + 'v:value from $psvar array' + '(:ternary expression %(x.true-string.false-string)' + '<<:truncation from left %len>:truncation from right %len>string>' + '[]:truncation from who knows where' + ) + fi + compset -P "*" + _describe -t prompt-format-specifier 'prompt format specifier' specs -S '' + _message -e prompt-format-specifier number +elif [[ $PREFIX == *%$paren(-|)<-># ]]; then + specs=( + '!:running with privileges' + '#:effective uid' + '?:exit status' + '_:at least n shell constructs started' + 'C:at least n path elements' + '/:at least n path elements' + '.:at least n path elements' + 'c:at least n path elements' + '~:at least n path elements' + 'D:month' + 'd:day of month' + 'g:effective gid' + 'j:number of jobs' + 'L:SHLVL' + 'l:number of characters already printed' + 'S:SECONDS parameter at least n' + 'T:current hour' + 't:current minute' + 'v:psvar has at least n elements' + 'V:element n of psvar is set and non-empty' + 'w:day of week (Sunday = 0)' + ) + compset -P "*" + _describe -t ternary-prompt-expression 'ternary prompt format test character' specs -S '' + _message -e ternary-prompt-expression number +else + _describe -t prompt-format-specifier 'prompt format specifier' '(%)' -S '' + _default "$@" +fi diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index af0501b..290361e 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -1,32 +1,84 @@ -#compdef print - -local state expl line eflag pflag - -# -e flag available only after -R -eflag="${words[1,CURRENT-1][(r)-*R*]:+-e[enable escapes]}" - -# -p flag only relevant if we have a coprocess -(:>&p) 2>/dev/null && - pflag='(-s -u -z)-p[print arguments to input of coprocess]' - -_arguments -C -s -A "-*" -S \ - '(-f)-r[ignore escape conventions of echo]' \ - '(-r -b -f -m -s -l -N -o -O -i -c -u -p -z -D -P)-R[emulate BSD echo (no escapes, -n & -e flags only)]' \ - '-b[recognise bindkey escape sequences]' \ - '-m[remove arguments matching specified pattern]' \ - '(-r -n -R -l -N -c)-f+[print arguments as for the printf builtin]:format' \ - '(-u -p -z)-s[place results in the history list]' \ - '(-c -f)-n[do not add a newline to the result]' \ - '(-N -c -f)-l[print arguments separated by newlines]' \ - '(-n -l -c -f)-N[print arguments separated and terminated by nulls]' \ - '(-O)-o[sort arguments in ascending order]' \ - '(-o)-O[sort arguments in descending order]' \ - '-i[case-insensitive sorting]' \ - '(-n -l -N -f -s -z)-a[with -c/-C, print arguments across before down]' \ - '(-n -l -N -f -C -s -z)-c[print arguments in columns]' \ - '(-n -l -N -f -c -s -z)-C+[print arguments in specified number of columns]:columns' \ - '(-s -p -z)-u+[specify file descriptor to print arguments to]:file descriptor:_file_descriptors' \ - '(-s -p -u)-z[push arguments onto editing buffer stack]' \ - '-D[substitute any arguments which are named directories using ~ notation]' \ - '-P[perform prompt expansion]' \ - $pflag $eflag '*:default:_default' +#compdef print printf + +local state expl line eflag pflag rest ret=1 + +if [[ $service = print ]]; then + # -e flag available only after -R + eflag="${words[1,CURRENT-1][(r)-*R*]:+-e[enable escapes]}" + + # -p flag only relevant if we have a coprocess + (:>&p) 2>/dev/null && + pflag='(-s -u -z)-p[print arguments to input of coprocess]' + + if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then + rest='*: :_ps1234' + else + rest='*: :_default' + fi + + _arguments -C -s -A "-*" -S \ + '(-f)-r[ignore escape conventions of echo]' \ + '(-r -b -f -m -s -l -N -o -O -i -c -u -p -z -D -P)-R[emulate BSD echo (no escapes, -n & -e flags only)]' \ + '-b[recognise bindkey escape sequences]' \ + '-m[remove arguments matching specified pattern]' \ + '(-r -n -R -l -N -c)-f+[print arguments as for the printf builtin]:format:->printfformat' \ + '(-u -p -z)-s[place results in the history list]' \ + '(-c -f)-n[do not add a newline to the result]' \ + '(-N -c -f)-l[print arguments separated by newlines]' \ + '(-n -l -c -f)-N[print arguments separated and terminated by nulls]' \ + '(-O)-o[sort arguments in ascending order]' \ + '(-o)-O[sort arguments in descending order]' \ + '-i[case-insensitive sorting]' \ + '(-n -l -N -f -s -z)-a[with -c/-C, print arguments across before down]' \ + '(-n -l -N -f -C -s -z)-c[print arguments in columns]' \ + '(-n -l -N -f -c -s -z)-C+[print arguments in specified number of columns]:columns' \ + '(-s -p -z)-u+[specify file descriptor to print arguments to]:file descriptor:_file_descriptors' \ + '(-s -p -u)-z[push arguments onto editing buffer stack]' \ + '-D[substitute any arguments which are named directories using ~ notation]' \ + '-P[perform prompt expansion]' \ + $pflag $eflag $rest && ret=0 +elif [[ $service = printf ]]; then + state=printf +fi + +if [[ $state = printf ]]; then + _arguments -C -s -S \ + '1:format:->printfformat' \ + '*: :_default' && ret=0 +fi + +if [[ $state = printfformat ]]; then + if [[ ${(Q)PREFIX} = *%((-|)<->|[-#0 +*.])# ]]; then + local -a specs + specs=( + '#:alternate form' + '0:zeropad to length n' + '-:left adjust result' + ' :leave one space in front of positive number from signed conversion' + '+:always place sign before a number from signed conversion' + '*:field width in next argument' + '.:precision' + 'c:print the first character of the argument' + 's:print the argument as a string' + {d,i}':signed decimal number or with leading " numeric value of following character' + 'o:unsigned octal number' + 'u:unsigned decimal number' + {x,X}':unsigned hexadecimal number, letters capitalized as x' + {e,E}':double number in scientific notation' + 'f:double number' + {g,G}':double number as %f or %e depending on size' + '%:a percent sign' + 'n:store number of printed bytes in parameter specified by argument' + 'b:as %s but interpret escape sequences in argument' + 'q:as %s but shell quote result' + ) + compset -P "*" + _describe -t print-format-specifier 'print format specifier' specs -S '' + _message -e print-format-specifier 'number' + else + _describe -t print-format-specifier 'print format specifier' '(%)' -S '' + fi + ret=0 +fi + +return ret -- 1.7.10.GIT