pshell

Crates.iopshell
lib.rspshell
version
sourcesrc
created_at2022-04-13 10:34:08.714919
updated_at2025-02-05 23:00:35.904513
descriptionWorks out if this is running from inside a shell, and if so, which one.
homepagehttps://github.com/a1ecbr0wn/pshell
repositoryhttps://github.com/a1ecbr0wn/pshell
max_upload_size
id566930
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Alec Brown (a1ecbr0wn)

documentation

https://docs.rs/pshell

README

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 - Contribute

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

Why should you use this crate?

It is a small, simple crate that adds very little to your application size for discovering what shell this is running under by inspecting the name of the parent processes against a limited list of known shells.

Why should you not use this crate?

You want an all-singing, all-dancing crate that identifies any knowns 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.

Commit count: 41

cargo fmt