summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2011-11-09 18:35:13 +0200
committerVille Skyttä <ville.skytta@iki.fi>2011-11-09 18:35:13 +0200
commit22dff29dc4b320d8a5a91341c46db4dc1e484891 (patch)
tree6386105b4b51113186d385f9d65caa0c063d19c2
parent3f851722d7ec106b0cf4ec561dac45080c8e5d64 (diff)
downloadbash-completion-22dff29dc4b320d8a5a91341c46db4dc1e484891.tar.gz
_npus: Split out of lrzip for general use.
-rw-r--r--bash_completion8
-rw-r--r--completions/lrzip5
2 files changed, 9 insertions, 4 deletions
diff --git a/bash_completion b/bash_completion
index 76852c53..73ae920d 100644
--- a/bash_completion
+++ b/bash_completion
@@ -888,6 +888,14 @@ _available_interfaces()
COMPREPLY=( $( compgen -W '${COMPREPLY[@]/%[[:punct:]]/}' -- "$cur" ) )
}
+# Echo number of CPUs, falling back to 1 on failure.
+_ncpus()
+{
+ local var=NPROCESSORS_ONLN
+ [[ $OSTYPE == *linux* ]] && var=_$var
+ local n=$( getconf $var 2>/dev/null )
+ printf %s ${n:-1}
+}
# Perform tilde (~) completion
# @return True (0) if completion needs further processing,
diff --git a/completions/lrzip b/completions/lrzip
index 1569dab4..da1730aa 100644
--- a/completions/lrzip
+++ b/completions/lrzip
@@ -35,10 +35,7 @@ _lrzip()
return 0
;;
-p)
- local var=NPROCESSORS_ONLN
- [[ $OSTYPE == *linux* ]] && var=_$var
- local n=$( getconf $var 2>/dev/null )
- COMPREPLY=( $( compgen -W "{1..${n:-1}}" -- "$cur" ) )
+ COMPREPLY=( $( compgen -W "{1..$(_ncpus)}" -- "$cur" ) )
return 0
;;
esac