bash completion: updates for the improved filtering
Vishal Verma
maintainerPATCH 1/1 bash completion: updates for the improved filtering
ndctl added improved filtering means, allowing one to filter listings with any combination of bus, dimm, region, or namespace. Make bash completion use that to only show the filtered set for any object. For example:
$ ndctl list --region=region6 --dimm=nmem<tab> nmem0 nmem1
Signed-off-by Vishal Verma <[email protected]>
--- contrib/ndctl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
contrib/ndctl +25 -1
@@ -103,6 +103,9 @@ __ndctlcomp() __ndctl_get_buses() { local opts="--buses $*" + [ -n "$dimm_filter" ] && opts="$opts --dimm=$dimm_filter" + [ -n "$reg_filter" ] && opts="$opts --region=$reg_filter" + [ -n "$ns_filter" ] && opts="$opts --namespace=$ns_filter" echo "$(ndctl list $opts | grep -E "^\s*\"provider\":" | cut -d\" -f4)" }
@@ -110,6 +113,8 @@ __ndctl_get_regions() { local opts="--regions $*" [ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter" + [ -n "$dimm_filter" ] && opts="$opts --dimm=$dimm_filter" + [ -n "$ns_filter" ] && opts="$opts --namespace=$ns_filter" [ -n "$type_filter" ] && opts="$opts --type=$type_filter" [ -n "$idle_filter" ] && opts="$opts --idle" echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)"
@@ -119,7 +124,9 @@ __ndctl_get_ns() { opts="--namespaces $*" [ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter" - [ -n "$reg_filter" ] && opts="$opts --bus=$reg_filter" + [ -n "$dimm_filter" ] && opts="$opts --dimm=$dimm_filter" + [ -n "$reg_filter" ] && opts="$opts --region=$reg_filter" + [ -n "$mode_filter" ] && opts="$opts --mode=$mode_filter" [ -n "$type_filter" ] && opts="$opts --type=$type_filter" [ -n "$idle_filter" ] && opts="$opts --idle" echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)"
@@ -129,6 +136,8 @@ __ndctl_get_dimms() { opts="--dimms $*" [ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter" + [ -n "$reg_filter" ] && opts="$opts --region=$reg_filter" + [ -n "$ns_filter" ] && opts="$opts --namespace=$ns_filter" echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)" }
@@ -263,6 +272,8 @@ __ndctl_init_filters() { bus_filter='' reg_filter='' + ns_filter='' + dimm_filter='' type_filter='' idle_filter='' mode_filter=''
@@ -280,6 +291,19 @@ __ndctl_init_filters() local regions=$(__ndctl_get_regions -i) [[ "$regions" == *"$reg_filter"* ]] || reg_filter='' fi + if [[ "$__word" =~ --namespace=(.*) ]]; then + ns_filter="${BASH_REMATCH[1]}" + # lets make sure this is in the list of namespaces + local nss=$(__ndctl_get_ns -i) + [[ "$nss" == *"$ns_filter"* ]] || ns_filter='' + fi + if [[ "$__word" =~ --dimm=(.*) ]]; then + dimm_filter="${BASH_REMATCH[1]}" + # lets make sure this is in the list of dimms + local dimms=$(__ndctl_get_dimms) + [[ "$dimms" == *"$dimm_filter"* ]] || dimm_filter='' + fi + if [[ "$__word" =~ --idle ]]; then idle_filter="1" fi
Signature · 6 lines
2.9.3 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 7 lines · Vishal Verma
ndctl added improved filtering means, allowing one to filter listings with any combination of bus, dimm, region, or namespace. Make bash completion use that to only show the filtered set for any object. For example:
$ ndctl list --region=region6 --dimm=nmem<tab> nmem0 nmem1
Slick! Applied.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm