#autoload local expl disp jobs job jids pfx='%' desc _tags jobs || return 1 _style jobs prefix-needed && [[ "$PREFIX" != %* ]] && return 1 _style jobs prefix-hidden && pfx='' _style jobs description && desc=yes if [[ "$1" = -r ]]; then jids=( "${(@k)jobstates[(R)running*]}" ) shift _description expl 'running job' elif [[ "$1" = -s ]]; then jids=( "${(@k)jobstates[(R)running*]}" ) shift _description expl 'suspended job' else [[ "$1" = - ]] && shift jids=( "${(@k)jobtexts}" ) _description expl job fi if [[ -n "$desc" ]]; then disp=() for job in "$jids[@]"; do [[ -n "$desc" ]] && disp=( "$disp[@]" "${pfx}${(r:2:: :)job} -- ${(r:COLUMNS-8:: :)jobtexts[$job]}" ) done fi if _style jobs strings; then local texts i text str tmp # Find shortest unambiguous strings. texts=( "$jobtexts[@]" ) jobs=() for i in "$jids[@]"; do text="$jobtexts[$i]" str="${text%% *}" if [[ "$text" = *\ * ]]; then text="${text#* }" else text="" fi tmp=( "${(@M)texts:#${str}*}" ) while [[ -n "$text" && $#tmp -ge 2 ]]; do str="${str} ${text%% *}" if [[ "$text" = *\ * ]]; then text="${text#* }" else text="" fi tmp=( "${(@M)texts:#${str}*}" ) done jobs=( "$jobs[@]" "$str" ) done [[ -n "$pfx" && -n "$desc" ]] && disp=( "${(@)disp#%}" ) else jobs=( "$jids[@]" ) fi if [[ -n "$desc" ]]; then compadd "$@" "$expl[@]" -ld disp - "%$^jobs[@]" else compadd "$@" "$expl[@]" - "%$^jobs[@]" fi