Skip to content

Commit

Permalink
fix: fixes bash completions for commands that have an underscore in t…
Browse files Browse the repository at this point in the history
…he name

Closes #581
  • Loading branch information
kbknapp committed Feb 3, 2017
1 parent 891a2a0 commit 7f5cfa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/completions/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/completions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec<String> {
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 {
Expand All @@ -138,7 +138,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec<String> {
}
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 {
Expand Down

0 comments on commit 7f5cfa7

Please sign in to comment.