#shell #cli #infer-shell

whattheshell

Infer the current shell the application is running on

3 stable releases

1.1.0 Jan 15, 2024
1.0.1 Jul 24, 2023
1.0.0 Jul 23, 2023

#284 in Unix APIs

Download history 62/week @ 2023-12-18 134/week @ 2023-12-25 30/week @ 2024-01-01 25/week @ 2024-01-08 503/week @ 2024-01-15 134/week @ 2024-01-22 323/week @ 2024-01-29 508/week @ 2024-02-05 702/week @ 2024-02-12 261/week @ 2024-02-19 68/week @ 2024-02-26 38/week @ 2024-03-04 12/week @ 2024-03-11 60/week @ 2024-04-01

75 downloads per month
Used in goup

MIT license

9KB
187 lines

whattheshell

This crate tries to provide a simple solution for a simple problem: "In what shell am I running?"

With Shell::infer(), the currently used shell is tried to be inferred by inspecting the given environment.

On unix-systems, the output of ps -o ppid,comm {pid} is inspected to get the process' parent process which is followed down the tree until a shell process was found. On non-unix system, the same algorithm is used but by the help of the crate sysinfo.

Example

use whattheshell::Shell;

fn main() {
    let shell = Shell::infer().unwrap();
    println!("{shell}"); // -> "zsh"
}

Credits

This implementation is very much inspired and influenced by the shell infer implementation in Schniz/fnm (see fnm/src/shell).

Dependencies

~1–1.7MB
~37K SLoC