From patchwork Mon Aug 14 20:34:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 9900087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF0FC602BA for ; Mon, 14 Aug 2017 20:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1371286F5 for ; Mon, 14 Aug 2017 20:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5CF628731; Mon, 14 Aug 2017 20:36:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5174C286F5 for ; Mon, 14 Aug 2017 20:36:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E24EE21DFC891; Mon, 14 Aug 2017 13:33:53 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 912F321DFC888 for ; Mon, 14 Aug 2017 13:33:52 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2017 13:36:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,374,1498546800"; d="scan'208";a="137377682" Received: from omniknight.lm.intel.com ([10.232.112.27]) by orsmga005.jf.intel.com with ESMTP; 14 Aug 2017 13:36:15 -0700 From: Vishal Verma To: Subject: [PATCH] bash completion: updates for the improved filtering Date: Mon, 14 Aug 2017 14:34:22 -0600 Message-Id: <20170814203422.28284-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.9.3 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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 nmem0 nmem1 Signed-off-by: Vishal Verma --- contrib/ndctl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/contrib/ndctl b/contrib/ndctl index fd560cb..e77d680 100755 --- a/contrib/ndctl +++ b/contrib/ndctl @@ -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