File tree Expand file tree Collapse file tree 14 files changed +54
-16
lines changed Expand file tree Collapse file tree 14 files changed +54
-16
lines changed Original file line number Diff line number Diff line change @@ -1508,13 +1508,19 @@ _available_interfaces()
1508
1508
}
1509
1509
1510
1510
# Echo number of CPUs, falling back to 1 on failure.
1511
- # TODO:API: rename per conventions, rework to use vars rather than outputting
1512
- _ncpus ()
1511
+ # @var[out] ret
1512
+ # @return 0 if it successfully obtained the number of CPUs, or otherwise 1
1513
+ # @since 2.12
1514
+ _comp_get_ncpus ()
1513
1515
{
1514
1516
local var=NPROCESSORS_ONLN
1515
1517
[[ $OSTYPE == * @ (linux| msys| cygwin)* ]] && var=_$var
1516
- local n=$( getconf $var 2> /dev/null)
1517
- printf %s " ${n:- 1} "
1518
+ if ret=$( getconf $var 2> /dev/null) && (( ret >= 1 )) ; then
1519
+ return 0
1520
+ else
1521
+ ret=1
1522
+ return 1
1523
+ fi
1518
1524
}
1519
1525
1520
1526
# Perform tilde (~) completion
Original file line number Diff line number Diff line change @@ -335,4 +335,12 @@ _parse_usage()
335
335
return 0
336
336
}
337
337
338
+ # @deprecated 2.12 Use `_comp_get_ncpus`.
339
+ _ncpus ()
340
+ {
341
+ local ret
342
+ _comp_get_ncpus
343
+ printf %s " $ret "
344
+ }
345
+
338
346
# ex: filetype=sh
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ _comp_cmd_2to3()
15
15
return
16
16
;;
17
17
-j | --processes)
18
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
18
+ local ret
19
+ _comp_get_ncpus
20
+ _comp_compgen -- -W " {1..$ret }"
19
21
return
20
22
;;
21
23
-o | --output-dir)
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ _comp_cmd_bzip2()
12
12
return
13
13
;;
14
14
-${noargopts} n)
15
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
15
+ local ret
16
+ _comp_get_ncpus
17
+ _comp_compgen -- -W " {1..$ret }"
16
18
return
17
19
;;
18
20
esac
Original file line number Diff line number Diff line change @@ -42,7 +42,9 @@ _comp_cmd_cppcheck()
42
42
return
43
43
;;
44
44
-j)
45
- COMPREPLY=($( compgen -W " {2..$( _ncpus) }" -- " $cur " ) )
45
+ local ret
46
+ _comp_get_ncpus
47
+ _comp_compgen -- -W " {2..$ret }"
46
48
return
47
49
;;
48
50
--language | -x)
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ _comp_cmd_flake8()
16
16
return
17
17
;;
18
18
--jobs | -${noargopts} j)
19
- COMPREPLY=($( compgen -W " auto {1..$( _ncpus) }" -- " $cur " ) )
19
+ local ret
20
+ _comp_get_ncpus
21
+ _comp_compgen -- -W " auto {1..$ret }"
20
22
return
21
23
;;
22
24
--output-file | --append-config | --config)
Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ _comp_cmd_gzip()
13
13
return
14
14
;;
15
15
--processes | -${noargopts} p)
16
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
16
+ local ret
17
+ _comp_get_ncpus
18
+ _comp_comgpen -- -W " {1..$ret }"
17
19
return
18
20
;;
19
21
esac
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ _comp_cmd_isort()
15
15
return
16
16
;;
17
17
--jobs | -j)
18
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
18
+ local ret
19
+ _comp_get_ncpus
20
+ _comp_comgpen -- -W " {1..$ret }"
19
21
return
20
22
;;
21
23
--multi-line | -m)
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ _comp_cmd_lrzip()
34
34
return
35
35
;;
36
36
--threads | -${noargopts} p)
37
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
37
+ local ret
38
+ _comp_get_ncpus
39
+ _comp_compgen -- -W " {1..$ret }"
38
40
return
39
41
;;
40
42
esac
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ _comp_cmd_lzip()
18
18
decompress=set
19
19
;;
20
20
--threads | -${noargopts} n)
21
- COMPREPLY=($( compgen -W " {1..$( _ncpus) }" -- " $cur " ) )
21
+ local ret
22
+ _comp_get_ncpus
23
+ _comp_compgen -- -W " {1..$ret }"
22
24
return
23
25
;;
24
26
--output | -${noargopts} o)
You can’t perform that action at this time.
0 commit comments