Skip to content

Commit 3852a7d

Browse files
akinomyogascop
andcommitted
refactor: rename { => _comp_get}_ncpus and change interface
Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
1 parent a17197f commit 3852a7d

File tree

14 files changed

+54
-16
lines changed

14 files changed

+54
-16
lines changed

bash_completion

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,13 +1508,19 @@ _available_interfaces()
15081508
}
15091509

15101510
# 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()
15131515
{
15141516
local var=NPROCESSORS_ONLN
15151517
[[ $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
15181524
}
15191525

15201526
# Perform tilde (~) completion

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,12 @@ _parse_usage()
335335
return 0
336336
}
337337

338+
# @deprecated 2.12 Use `_comp_get_ncpus`.
339+
_ncpus()
340+
{
341+
local ret
342+
_comp_get_ncpus
343+
printf %s "$ret"
344+
}
345+
338346
# ex: filetype=sh

completions/2to3

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ _comp_cmd_2to3()
1515
return
1616
;;
1717
-j | --processes)
18-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
18+
local ret
19+
_comp_get_ncpus
20+
_comp_compgen -- -W "{1..$ret}"
1921
return
2022
;;
2123
-o | --output-dir)

completions/bzip2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ _comp_cmd_bzip2()
1212
return
1313
;;
1414
-${noargopts}n)
15-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
15+
local ret
16+
_comp_get_ncpus
17+
_comp_compgen -- -W "{1..$ret}"
1618
return
1719
;;
1820
esac

completions/cppcheck

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ _comp_cmd_cppcheck()
4242
return
4343
;;
4444
-j)
45-
COMPREPLY=($(compgen -W "{2..$(_ncpus)}" -- "$cur"))
45+
local ret
46+
_comp_get_ncpus
47+
_comp_compgen -- -W "{2..$ret}"
4648
return
4749
;;
4850
--language | -x)

completions/flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ _comp_cmd_flake8()
1616
return
1717
;;
1818
--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}"
2022
return
2123
;;
2224
--output-file | --append-config | --config)

completions/gzip

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ _comp_cmd_gzip()
1313
return
1414
;;
1515
--processes | -${noargopts}p)
16-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
16+
local ret
17+
_comp_get_ncpus
18+
_comp_comgpen -- -W "{1..$ret}"
1719
return
1820
;;
1921
esac

completions/isort

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ _comp_cmd_isort()
1515
return
1616
;;
1717
--jobs | -j)
18-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
18+
local ret
19+
_comp_get_ncpus
20+
_comp_comgpen -- -W "{1..$ret}"
1921
return
2022
;;
2123
--multi-line | -m)

completions/lrzip

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ _comp_cmd_lrzip()
3434
return
3535
;;
3636
--threads | -${noargopts}p)
37-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
37+
local ret
38+
_comp_get_ncpus
39+
_comp_compgen -- -W "{1..$ret}"
3840
return
3941
;;
4042
esac

completions/lzip

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ _comp_cmd_lzip()
1818
decompress=set
1919
;;
2020
--threads | -${noargopts}n)
21-
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
21+
local ret
22+
_comp_get_ncpus
23+
_comp_compgen -- -W "{1..$ret}"
2224
return
2325
;;
2426
--output | -${noargopts}o)

0 commit comments

Comments
 (0)