#windows #terminal #applications

crabtrap

Detect whether your app was launched from the terminal or from explorer/PowerToys in Windows

1 unstable release

new 0.1.0 Oct 15, 2024

#740 in Command-line interface

Download history 120/week @ 2024-10-12

120 downloads per month

MIT/Apache

8KB
70 lines

crabtrap

Rust porting of the golang library mousetrap

This is a tiny crate with a minimal footprint, that solves a simple problem:

Was the binary launched from the terminal or by double clicking on it?

This crate gives an answer in the Windows world, keeping the question open in all other operating systems (suggestions are welcome).

Example

use crabtrap::started_by_explorer;

fn main(){
    if started_by_explorer(){
        println!("I'm from a GUI");
    } else{
        println!("I'm from the terminal");
    }
}

lib.rs:

This crate provides a single function started_by_explorer

started_by_explorer can be used to check if a windows executable was launched by double clicking on the executable or from "PowerToys Run" or, instead, if it was launched from the terminal

Dependencies

~0–35MB
~526K SLoC