diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bug_report.rs | 1 | ||||
-rw-r--r-- | src/configs/shell.rs | 2 | ||||
-rw-r--r-- | src/context.rs | 2 | ||||
-rw-r--r-- | src/init/mod.rs | 10 | ||||
-rw-r--r-- | src/init/starship.tcsh | 9 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/module.rs | 1 | ||||
-rw-r--r-- | src/modules/shell.rs | 1 | ||||
-rw-r--r-- | src/print.rs | 7 | ||||
-rw-r--r-- | src/utils.rs | 4 |
10 files changed, 38 insertions, 1 deletions
diff --git a/src/bug_report.rs b/src/bug_report.rs index d93fcc80f..943a146f0 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -205,6 +205,7 @@ fn get_config_path(shell: &str) -> Option<PathBuf> { } "zsh" => Some(".zshrc"), "elvish" => Some(".elvish/rc.elv"), + "tcsh" => Some(".tcshrc"), _ => None, } .map(|path| home_dir.join(path)) diff --git a/src/configs/shell.rs b/src/configs/shell.rs index 24551df97..4b56189c6 100644 --- a/src/configs/shell.rs +++ b/src/configs/shell.rs @@ -11,6 +11,7 @@ pub struct ShellConfig<'a> { pub powershell_indicator: &'a str, pub ion_indicator: &'a str, pub elvish_indicator: &'a str, + pub tcsh_indicator: &'a str, pub disabled: bool, } @@ -24,6 +25,7 @@ impl<'a> RootModuleConfig<'a> for ShellConfig<'a> { powershell_indicator: "psh", ion_indicator: "ion", elvish_indicator: "esh", + tcsh_indicator: "tsh", disabled: true, } } diff --git a/src/context.rs b/src/context.rs index 251e5e337..807f3d183 100644 --- a/src/context.rs +++ b/src/context.rs @@ -251,6 +251,7 @@ impl<'a> Context<'a> { "powershell" => Shell::PowerShell, "zsh" => Shell::Zsh, "elvish" => Shell::Elvish, + "tcsh" => Shell::Tcsh, _ => Shell::Unknown, } } @@ -486,6 +487,7 @@ pub enum Shell { PowerShell, Zsh, Elvish, + Tcsh, Unknown, } diff --git a/src/init/mod.rs b/src/init/mod.rs index a06bf32d7..be1d228f0 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -173,6 +173,13 @@ fi"#, ); Some(script) } + Some("tcsh") => { + let script = format!( + r#"eval "`("{}" init tcsh --print-full-init)`""#, + starship.sprint_posix()? + ); + Some(script) + } None => { println!( "Invalid shell name provided: {}\\n\ @@ -212,6 +219,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> { "powershell" => print_script(PWSH_INIT, &starship_path.sprint()?), "ion" => print_script(ION_INIT, &starship_path.sprint()?), "elvish" => print_script(ELVISH_INIT, &starship_path.sprint_posix()?), + "tcsh" => print_script(TCSH_INIT, &starship_path.sprint_posix()?), _ => { println!( "printf \"Shell name detection failed on phase two init.\\n\ @@ -255,3 +263,5 @@ const PWSH_INIT: &str = include_str!("starship.ps1"); const ION_INIT: &str = include_str!("starship.ion"); const ELVISH_INIT: &str = include_str!("starship.elv"); + +const TCSH_INIT: &str = include_str!("starship.tcsh"); diff --git a/src/init/starship.tcsh b/src/init/starship.tcsh new file mode 100644 index 000000000..7d4b4b9a0 --- /dev/null +++ b/src/init/starship.tcsh @@ -0,0 +1,9 @@ +setenv STARSHIP_SHELL tcsh; +setenv STARSHIP_SESSION_KEY `::STARSHIP:: session`; +set USER_PRECMD = "`alias precmd`"; +set USER_POSTCMD = "`alias postcmd`"; +set STARSHIP_PRECMD = 'set STARSHIP_CMD_STATUS = $status;set STARSHIP_PATH = ::STARSHIP::;set STARSHIP_END_TIME = `$STARSHIP_PATH time`;set STARSHIP_DURATION = 0;if ( $STARSHIP_START_TIME != -1 ) @ STARSHIP_DURATION = $STARSHIP_END_TIME - $STARSHIP_START_TIME;set prompt = "`$STARSHIP_PATH prompt --status $STARSHIP_CMD_STATUS --cmd-duration $STARSHIP_DURATION`";set STARSHIP_START_TIME = -1'; +set STARSHIP_POSTCMD = 'set STARSHIP_START_TIME = `::STARSHIP:: time`'; +alias precmd "$STARSHIP_PRECMD;$USER_PRECMD"; +alias postcmd "$STARSHIP_POSTCMD;$USER_POSTCMD"; +set STARSHIP_START_TIME = `::STARSHIP:: time`; diff --git a/src/main.rs b/src/main.rs index 2701b21f3..977f99414 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ fn main() { let shell_arg = Arg::with_name("shell") .value_name("SHELL") .help( - "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish", + "The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish, tcsh", ) .required(true); diff --git a/src/module.rs b/src/module.rs index e222ef2e0..7a6961beb 100644 --- a/src/module.rs +++ b/src/module.rs @@ -144,6 +144,7 @@ impl<'a> Module<'a> { match shell { Shell::Bash => ansi_strings_modified(ansi_strings, shell), Shell::Zsh => ansi_strings_modified(ansi_strings, shell), + Shell::Tcsh => ansi_strings_modified(ansi_strings, shell), _ => ansi_strings, } } diff --git a/src/modules/shell.rs b/src/modules/shell.rs index fe90b2e89..fc51b52f7 100644 --- a/src/modules/shell.rs +++ b/src/modules/shell.rs @@ -23,6 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { Shell::PowerShell => Some(config.powershell_indicator), Shell::Ion => Some(config.ion_indicator), Shell::Elvish => Some(config.elvish_indicator), + Shell::Tcsh => Some(config.tcsh_indicator), Shell::Unknown => None, }, _ => None, diff --git a/src/print.rs b/src/print.rs index 78e67694c..0330af07e 100644 --- a/src/print.rs +++ b/src/print.rs @@ -87,6 +87,13 @@ pub fn get_prompt(context: Context) -> String { } write!(buf, "{}", ANSIStrings(&module_strings)).unwrap(); + // escape \n and ! characters for tcsh + if let Shell::Tcsh = context.shell { + buf = buf.replace('!', "\\!"); + // space is required before newline + buf = buf.replace('\n', " \\n"); + } + buf } diff --git a/src/utils.rs b/src/utils.rs index c9d076ae7..d1a3025c5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -226,6 +226,8 @@ pub fn wrap_seq_for_shell( const BASH_END: &str = "\u{5c}\u{5d}"; // \] const ZSH_BEG: &str = "\u{25}\u{7b}"; // %{ const ZSH_END: &str = "\u{25}\u{7d}"; // %} + const TCSH_BEG: &str = "\u{25}\u{7b}"; // %{ + const TCSH_END: &str = "\u{25}\u{7d}"; // %} // ANSI escape codes cannot be nested, so we can keep track of whether we're // in an escape or not with a single boolean variable @@ -238,6 +240,7 @@ pub fn wrap_seq_for_shell( match shell { Shell::Bash => format!("{}{}", BASH_BEG, escape_begin), Shell::Zsh => format!("{}{}", ZSH_BEG, escape_begin), + Shell::Tcsh => format!("{}{}", TCSH_BEG, escape_begin), _ => x.to_string(), } } else if x == escape_end && escaped { @@ -245,6 +248,7 @@ pub fn wrap_seq_for_shell( match shell { Shell::Bash => format!("{}{}", escape_end, BASH_END), Shell::Zsh => format!("{}{}", escape_end, ZSH_END), + Shell::Tcsh => format!("{}{}", escape_end, TCSH_END), _ => x.to_string(), } } else { |