diff options
author | Thomas O'Donnell <andytom@users.noreply.github.com> | 2021-03-25 21:08:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 15:08:28 -0500 |
commit | e0da57df3febe194aa2541e09167869c330cb77f (patch) | |
tree | 1d5a4180a3253fa1bbda7fc84c28a6d3709ba319 /src/init | |
parent | ba40ad5ce6efc7949f28c2fd3435fad71d841c91 (diff) |
style(init): Cleanup the unknown shell message (#2444)
* style(init): Cleanup the unknown shell message
Have make a small change to the message that is printed when an unknow
shell is used. This correct the placement of the trailing `"` so that
the two training new lines are correctly printed and updates the list of
supported shells.
* refactor(init): consolidate unknown shell errors
Have consolidated the two unknown shell errors
* refactor(init): Quote the shell name in the output
Quote the shell name in the script and combined the shell_name and
shell_basename to simplify the code a little.
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/mod.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/init/mod.rs b/src/init/mod.rs index be1d228f0..f140fb8a5 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -81,12 +81,15 @@ init code. The stub produces the main init script, then evaluates it with pub fn init_stub(shell_name: &str) -> io::Result<()> { log::debug!("Shell name: {}", shell_name); - let shell_basename = Path::new(shell_name).file_stem().and_then(OsStr::to_str); + let shell_basename = Path::new(shell_name) + .file_stem() + .and_then(OsStr::to_str) + .unwrap_or(shell_name); let starship = StarshipPath::init()?; let setup_stub = match shell_basename { - Some("bash") => { + "bash" => { /* * The standard bash bootstrap is: * `source <(starship init bash --print-full-init)` @@ -132,14 +135,14 @@ fi"#, Some(script) } - Some("zsh") => { + "zsh" => { let script = format!( "source <(\"{}\" init zsh --print-full-init)", starship.sprint_posix()? ); Some(script) } - Some("fish") => { + "fish" => { // Fish does process substitution with pipes and psub instead of bash syntax let script = format!( "source (\"{}\" init fish --print-full-init | psub)", @@ -147,7 +150,7 @@ fi"#, ); Some(script) } - Some("powershell") => { + "powershell" => { // Explanation of syntax: // &: Explicitly tells powershell to execute path with starship executable. // @@ -162,41 +165,40 @@ fi"#, ); Some(script) } - Some("ion") => { + "ion" => { let script = format!("eval $({} init ion --print-full-init)", starship.sprint()?); Some(script) } - Some("elvish") => { + "elvish" => { let script = format!( "eval (\"{}\" init elvish --print-full-init | slurp)", starship.sprint_posix()? ); Some(script) } - Some("tcsh") => { + "tcsh" => { let script = format!( r#"eval "`("{}" init tcsh --print-full-init)`""#, starship.sprint_posix()? ); Some(script) } - None => { - println!( - "Invalid shell name provided: {}\\n\ - If this issue persists, please open an \ - issue in the starship repo: \\n\ - https://github.com/starship/starship/issues/new\\n\"", - shell_name - ); - None - } - Some(shell_basename) => { + _ => { + let quoted_arg = shell_words::quote(shell_basename); println!( - "printf \"\\n{0} is not yet supported by starship.\\n\ - For the time being, we support bash, zsh, fish, and ion.\\n\ + "printf \"\\n%s is not yet supported by starship.\\n\ + For the time being, we support the following shells:\\n\ + * bash\\n\ + * elvish\\n\ + * fish\\n\ + * ion\\n\ + * powershell\\n\ + * tcsh\\n\ + * zsh\\n\ + \\n\ Please open an issue in the starship repo if you would like to \ - see support for {0}:\\nhttps://github.com/starship/starship/issues/new\"\\n\\n", - shell_basename + see support for %s:\\nhttps://github.com/starship/starship/issues/new\\n\\n\" {0} {0}", + quoted_arg ); None } |