Skip to content

Commit 693fd9f

Browse files
cachebagrami3l
authored andcommitted
feat(self_update): add tcsh shell support to cli #3413
1 parent 2b0b516 commit 693fd9f

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ This is usually done by running one of the following (note the leading DOT):
399399
. "{cargo_home}/env" # For sh/bash/zsh/ash/dash/pdksh
400400
source "{cargo_home}/env.fish" # For fish
401401
source $"{cargo_home_nushell}/env.nu" # For nushell
402+
source "{cargo_home}/env.tcsh" # For tcsh
402403
"#
403404
};
404405
}

src/cli/self_update/env.tcsh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# rustup environment for tcsh
2+
if ( $?PATH ) then
3+
if ( "$PATH" !~ *{cargo_bin}* ) then
4+
setenv PATH "{cargo_bin}:$PATH"
5+
endif
6+
else
7+
setenv PATH "{cargo_bin}"
8+
endif

src/cli/self_update/shell.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fn enumerate_shells() -> Vec<Shell> {
6767
Box::new(Zsh),
6868
Box::new(Fish),
6969
Box::new(Nu),
70+
Box::new(Tcsh),
7071
]
7172
}
7273

@@ -318,6 +319,55 @@ impl UnixShell for Nu {
318319
}
319320
}
320321

322+
struct Tcsh;
323+
324+
impl UnixShell for Tcsh {
325+
fn does_exist(&self, process: &Process) -> bool {
326+
matches!(process.var("SHELL"), Ok(sh) if sh.contains("tcsh"))
327+
|| utils::find_cmd(&["tcsh"], process).is_some()
328+
}
329+
330+
fn rcfiles(&self, process: &Process) -> Vec<PathBuf> {
331+
let mut paths = vec![];
332+
333+
if let Some(home) = process.home_dir() {
334+
paths.push(home.join(".tcshrc"));
335+
paths.push(home.join(".cshrc"));
336+
}
337+
338+
paths
339+
}
340+
341+
fn update_rcs(&self, process: &Process) -> Vec<PathBuf> {
342+
for f in self.rcfiles(process) {
343+
if f.is_file() {
344+
return vec![f];
345+
}
346+
}
347+
348+
// If neither exists, default to ~/.tcshrc
349+
if let Some(home) = process.home_dir() {
350+
return vec![home.join(".tcshrc")];
351+
}
352+
353+
vec![]
354+
}
355+
356+
fn env_script(&self) -> ShellScript {
357+
ShellScript {
358+
name: "env.tcsh",
359+
content: include_str!("env.tcsh"),
360+
}
361+
}
362+
363+
fn source_string(&self, process: &Process) -> Result<String> {
364+
Ok(format!(
365+
r#"source "{}/env.tcsh""#,
366+
self.cargo_home_str(process)?
367+
))
368+
}
369+
}
370+
321371
pub(crate) fn legacy_paths(process: &Process) -> impl Iterator<Item = PathBuf> + '_ {
322372
let zprofiles = Zsh::zdotdir(process)
323373
.into_iter()

0 commit comments

Comments
 (0)