From 07f071e4381559f2cfb26019eb700c0a21de7db5 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 30 Jan 2017 23:56:36 -0500 Subject: [PATCH] fix: fixes bash completions for commands that have an underscore in the name Closes #581 --- src/completions/bash.rs | 12 ++++++------ src/completions/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/completions/bash.rs b/src/completions/bash.rs index 47a69e14b6d8..ab94865b8e53 100644 --- a/src/completions/bash.rs +++ b/src/completions/bash.rs @@ -77,10 +77,10 @@ complete -F _{name} -o bashdefault -o default {name} for sc in &scs { subcmds = format!("{} {name}) - cmd+=\"_{name}\" + cmd+=\"__{name}\" ;;", subcmds, - name = sc.replace("-", "_")); + name = sc.replace("-", "__")); } subcmds @@ -111,9 +111,9 @@ complete -F _{name} -o bashdefault -o default {name} return 0 ;;", subcmd_dets, - subcmd = sc.replace("-", "_"), + subcmd = sc.replace("-", "__"), sc_opts = self.all_options_for_path(&*sc), - level = sc.split("_").map(|_| 1).fold(0, |acc, n| acc + n), + level = sc.split("__").map(|_| 1).fold(0, |acc, n| acc + n), opts_details = self.option_details_for_path(&*sc)); } @@ -123,7 +123,7 @@ complete -F _{name} -o bashdefault -o default {name} fn option_details_for_path(&self, path: &str) -> String { debugln!("BashGen::option_details_for_path: path={}", path); let mut p = self.p; - for sc in path.split('_').skip(1) { + for sc in path.split("__").skip(1) { debugln!("BashGen::option_details_for_path:iter: sc={}", sc); p = &p.subcommands .iter() @@ -212,7 +212,7 @@ complete -F _{name} -o bashdefault -o default {name} fn all_options_for_path(&self, path: &str) -> String { debugln!("BashGen::all_options_for_path: path={}", path); let mut p = self.p; - for sc in path.split('_').skip(1) { + for sc in path.split("__").skip(1) { debugln!("BashGen::all_options_for_path:iter: sc={}", sc); p = &p.subcommands .iter() diff --git a/src/completions/mod.rs b/src/completions/mod.rs index 8a7c21f1b2f6..6d067882bf0c 100644 --- a/src/completions/mod.rs +++ b/src/completions/mod.rs @@ -125,7 +125,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec { if !p.has_subcommands() { if !first { let name = &*p.meta.name; - let path = p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "_"); + let path = p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "__"); let mut ret = vec![path.clone()]; if let Some(ref aliases) = p.meta.aliases { for &(n, _) in aliases { @@ -138,7 +138,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec { } for sc in &p.subcommands { let name = &*sc.p.meta.name; - let path = sc.p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "_"); + let path = sc.p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "__"); subcmds.push(path.clone()); if let Some(ref aliases) = sc.p.meta.aliases { for &(n, _) in aliases {