Skip to content

Commit

Permalink
updated env PATH init
Browse files Browse the repository at this point in the history
  • Loading branch information
mitnk committed Feb 14, 2022
1 parent 2aa2731 commit 3c67f81
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# cicada Release Notes

## 0.9.23 - 2022-02-22
## 0.9.24 - 2022-02-14

- updated `PATH` initialization.

## 0.9.23 - 2022-01-22

- updated to use rust edition 2021.
- disable self-defined signal handler by default for safety.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition = "2021"
build = "src/build.rs"
name = "cicada"
version = "0.9.23"
version = "0.9.24"
authors = ["Hugo Wang <w@mitnk.com>"]

description = "A simple Bash-like Unix shell."
Expand Down
6 changes: 6 additions & 0 deletions docs/completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ $ pip install --requirement

**You may use sub commands in it**. For example:

> WARNING: when
> [CICADA_ENABLE_SIG_HANDLER](https://github.com/mitnk/cicada/blob/master/docs/envs.md#cicada_enable_sig_handler)
> is enabled, use in-line command in completion file could cause cicada crash,
> with error message like `BUG IN CLIENT OF LIBPLATFORM: Trying to recursively
> lock an os_unfair_lock`. View [detailed logs](https://pastebin.com/3krRLUNp)
```
$ cat ~/.config/cicada/completers/git.yaml
... skipped ...
Expand Down
6 changes: 6 additions & 0 deletions docs/prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ would render prompt with:
$ [master] mitnk@mpb$
```

> WARNING: when
> [CICADA_ENABLE_SIG_HANDLER](https://github.com/mitnk/cicada/blob/master/docs/envs.md#cicada_enable_sig_handler)
> is enabled, use in-line command in prompt could cause cicada crash, with
> error message like `BUG IN CLIENT OF LIBPLATFORM: Trying to recursively lock
> an os_unfair_lock`. View [detailed logs](https://pastebin.com/3krRLUNp)
### Use prefix & suffix in it (BETA)
You can use `[` or `{` as prefix, and `]`, `}` as suffix when using command
output int prompt. e.g.
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fn main() {
libc::signal(libc::SIGQUIT, libc::SIG_IGN);
}

tools::init_path_env();

let mut sh = shell::Shell::new();
let args: Vec<String> = env::args().collect();
// only load RC in a login shell
Expand Down
9 changes: 0 additions & 9 deletions src/rcfile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env;
use std::path::Path;

use crate::scripting;
Expand All @@ -24,14 +23,6 @@ pub fn get_rc_file() -> String {
}

pub fn load_rc_files(sh: &mut shell::Shell) {
// make "/usr/local/bin" as the first item in PATH
if let Ok(env_path) = env::var("PATH") {
if !env_path.contains("/usr/local/bin:") {
let env_path_new = format!("/usr/local/bin:{}", env_path);
env::set_var("PATH", &env_path_new);
}
}

let rc_file = get_rc_file();
if !Path::new(&rc_file).exists() {
return;
Expand Down
21 changes: 21 additions & 0 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,27 @@ pub fn is_builtin(s: &str) -> bool {
builtins.contains(&s)
}

pub fn init_path_env() {
// order matters. took from `runc spec`
let mut paths: Vec<String> = vec![
"/usr/local/sbin".to_string(),
"/usr/local/bin".to_string(),
"/usr/sbin".to_string(),
"/usr/bin".to_string(),
"/sbin".to_string(),
"/bin".to_string(),
];
if let Ok(env_path) = env::var("PATH") {
for x in env_path.split(":") {
if !paths.contains(&x.to_string()) {
paths.push(x.to_string());
}
}
}
let paths = paths.join(":");
env::set_var("PATH", paths);
}

#[cfg(test)]
mod tests {
use super::escape_path;
Expand Down

0 comments on commit 3c67f81

Please sign in to comment.