On 28 Jan, Bart wrote: > On Jan 28, 10:18am, Oliver Kiddle wrote: > } The only things I've knowingly left unimplemented is completion for > } jobs (because compgen is always run in a subshell) > > We could do something about this, generically, by saving local copies of > the jobstates and jobtexts hashes in _main_complete or some such. I didn't think of that. I've done that in the _bash_completion function. I can't see that it would be particularly useful to have in _main_complete (matches added by a compadd running in a subshell are lost anyway). It's not likely to be so useful though because job completion is most useful with builtins for which we have perfectly good zsh completions already. But it is nice to have for completeness. I've attached an update patch which does this job stuff, fixes $COMP_POINT and does complete -r. Only thing it doesn't do now is complete bash help topics. The second (mime) attachment is the 4.0 back port. Any ideas on where in the manual I should mention this function? It only needs a couple of lines. The User Contributions chapter seems to cover stuff in the Functions directory. Or would it be better mentioned in the FAQ? Oliver --- Completion/bashcompinit Wed Jan 29 10:28:23 2003 +++ Completion/bashcompinit Wed Jan 29 10:28:23 2003 @@ -6,12 +6,16 @@ local COMP_POINT COMP_CWORD local -a COMP_WORDS COMPREPLY BASH_VERSINFO local COMP_LINE="$words" + local -A savejobstates savejobtexts - (( COMP_POINT = ${#${(j. .)words}} + $$#QIPREFIX + $#IPREFIX + $#PREFIX )) + (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX )) (( COMP_CWORD = CURRENT - 1)) COMP_WORDS=( $words ) BASH_VERSINFO=( 2 05b 0 1 release ) + savejobstates=( ${(kv)jobstates} ) + savejobtexts=( ${(kv)jobtexts} ) + [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' ) matches=( ${(f)"$(compgen $@)"} ) @@ -38,8 +42,8 @@ } compgen() { - local opts prefix suffix ret=1 OPTARG OPTIND - local -a name res results + local opts prefix suffix job OPTARG OPTIND ret=1 + local -a name res results jids local -A shortopts emulate -L sh @@ -93,12 +97,25 @@ setopt kshglob noshglob braceexpand results+=( "${res[@]}" ) ;; + job) results+=( "${savejobtexts[@]%% *}" );; keyword) results+=( "${(k)reswords[@]}" ) ;; + running) + jids=( "${(@k)savejobstates[(R)running*]}" ) + for job in "${jids[@]}"; do + results+=( ${savejobtexts[$job]%% *} ) + done + ;; + stopped) + jids=( "${(@k)savejobstates[(R)suspended*]}" ) + for job in "${jids[@]}"; do + results+=( ${savejobtexts[$job]%% *} ) + done + ;; setopt|shopt) results+=( "${(k)options[@]}" ) ;; signal) results+=( "SIG${^signals[@]}" ) ;; user) results+=( "${(k)userdirs[@]}" ) ;; variable) results+=( "${(k)parameters[@]}" ) ;; - helptopic|job|running|stopped) ;; + helptopic) ;; esac ;; F) @@ -125,8 +142,8 @@ esac done - # support for the last, `word' option to compgen. Not particularly valuable - # and without it zsh matching can do a better job. Comment in if needed. + # support for the last, `word' option to compgen. Zsh's matching does a + # better job but if you need to, comment this in and use compadd -U #shift $(( OPTIND - 1 )) #(( $# )) && results=( "${(M)results[@]:#$1*}" ) @@ -140,11 +157,11 @@ zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v \ p=print r=remove if [[ -n $print ]]; then - for cmd print in ${(kv)_comps[(R)_bash*]}; do - print "complete ${print#* } $cmd" - done + printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }" elif [[ -n $remove ]]; then - print "not implemented: -r option" + for cmd; do + unset "_comps[$cmd]" + done else compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@" fi This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.