#shell #utility

pshell

Works out if this is running from inside a shell, and if so, which one

9 stable releases

1.0.10 May 21, 2023
1.0.9 Feb 19, 2023
1.0.8 Dec 30, 2022
1.0.5 Oct 18, 2022
1.0.1 Apr 13, 2022

#663 in Filesystem

Download history 11/week @ 2023-06-11 34/week @ 2023-06-18 20/week @ 2023-06-25 48/week @ 2023-07-02 10/week @ 2023-07-09 15/week @ 2023-07-16 31/week @ 2023-07-23 9/week @ 2023-07-30 29/week @ 2023-08-06 20/week @ 2023-08-13 10/week @ 2023-08-20 17/week @ 2023-08-27 22/week @ 2023-09-03 19/week @ 2023-09-10 9/week @ 2023-09-17 12/week @ 2023-09-24

62 downloads per month
Used in bookmark-cd

Apache-2.0

10KB

pshell

Crates.io Crates.io Build Status docs.rs dependency status

pshell answers the question "Is my application running in a shell, and if so, which one".

Example: you are installing something and want to make changes to the shell and you want to know what changes are required to which shell script.

Usage

Just a simple function that tells you whether the application is run from inside a shell:

use pshell;

fn main() {
    // `find` returns the name of the shell in a string and the pid as a u32
    let (sh, pid) = pshell::find().unwrap_or(("unknown".to_string(), 0));
    println!("This application has been run from pid `{}`, which is a {} shell", pid, sh);
}

To try this out, and check it works OK on your OS/shell combination run the following from your shell:

cargo run --example what_shell

Contribute

I have created a list of shells where this could be run from, it is not exhaustive, if your shell is not supported, feel free to raise an issue or a PR.

Dependencies

~0.6–0.9MB
~18K SLoC