about summary refs log tree commit diff
path: root/Completion/Unix/Command/_lp
blob: d21f970f78e41f4797bd14af06e642acf2dcff73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#compdef lp lpr lpq lprm

local expl ret=1 printer list disp strs shown

if compset -P -[dP] || [[ "$words[CURRENT-1]" = -[dP] ]]; then
  _printers
else
  if [[ "$service" = (lpq|lprm) ]]; then
    if [[ "$words" = *-P* ]]; then
      printer=(-P "${${words##*-P( |)}%% *}")
    else
      printer=()
    fi
    list=( ${(M)"${(f@)$(_call_program jobs lpq $printer 2> /dev/null)}":#[0-9]*} )

    if (( $#list )); then
      _tags users jobs

      while _tags; do
        if _requested users; then
          strs=( "${(@)${(@)list##[^ 	]##[ 	]##[^ 	]##[ 	]##}%%[ 	]*}" )
          if [[ -z "$shown" ]] &&
             zstyle -T ":completion:${curcontext}:users" verbose; then
            disp=(-ld list)
  	  shown=yes
          else
  	  disp=()
          fi
	  _all_labels users expl user compadd "$disp[@]" -a strs ||
              _users && ret=0
        fi
        if _requested jobs; then
          strs=( "${(@)${(@)list##[^ 	]##[ 	]##[^ 	]##[ 	]##[^ 	]##[ 	]##}%%[ 	]*}" )
          if [[ -z "$shown" ]] &&
             zstyle -T ":completion:${curcontext}:jobs" verbose; then
            disp=(-ld list)
  	  shown=yes
          else
  	  disp=()
          fi
          _all_labels jobs expl job compadd "$disp[@]" -a strs && ret=0
        fi
        (( ret )) || return 0
      done
    else
      _message 'no print jobs'
    fi
    return 1
  else
    _ps
  fi
fi