Skip to main content

Explore PATH environment variable on Windows and Linux.

Project description

pathit

Explore PATH environment variable on both Windows and Linux.

Usage

What directories are part of PATH? Use echo $PATH | tr ";" "\n" or

pathit show

Sort them alphabetically. Use echo $PATH | tr ";" "\n" | sort or

pathit show --sort

What are the paths with bin? Use echo $PATH | tr ";" "\n" | grep bin or

pathit show --includes bin

More complex sorting cases are easier with pathit than with bash on Linux or batch files in Windows.

pathit will indicate non-existent directory. Below is an example from Github Codespaces, somehow /usr/local/sdkman/candidates/ant/current/bin does not exist, but included in PATH.

$ poetry run pathit show --sort --includes sdkman
19 /usr/local/sdkman/bin
23 /usr/local/sdkman/candidates/ant/current/bin (directory does not exist)
21 /usr/local/sdkman/candidates/gradle/current/bin
20 /usr/local/sdkman/candidates/java/current/bin
22 /usr/local/sdkman/candidates/maven/current/bin

pathit allows to filter paths that must or must not include a certain string. Filtering is case insensitive, --includes windows and --includes Windows will produce the same result.

$ pathit show --sort --includes windows --excludes system32
39 C:\Users\Евгений\AppData\Local\Microsoft\WindowsApps
24 C:\WINDOWS
14 C:\Windows
46 C:\tools\Cmder\vendor\git-for-windows\cmd
47 C:\tools\Cmder\vendor\git-for-windows\mingw64\bin
12 C:\tools\Cmder\vendor\git-for-windows\usr\bin

--purge flag will drop invalid paths from listing.

λ pathit show --includes quarto
33 C:\Program Files\Quarto\bin
41 D:\Quarto\bin
50 x:\quarto\does_not_exist (directory does not exist)
51 d:\quarto\this_is_a_file (it's a file, not a directory)
λ pathit show --includes quarto --purge
33 C:\Program Files\Quarto\bin
41 D:\Quarto\bin

You can get a valid string for your PATH in a format native to your operating system using --string ouput flag.

λ pathit show --purge --string
C:\tools\Cmder\bin;C:\tools\Cmder\vendor\bin;C:\Windows\system32;C:\Windows

Installation

git clone https://github.com/epogrebnyak/what-the-path.git
cd what-the-path
pip install -e .

or shorter:

pip install git+https://github.com/epogrebnyak/what-the-path.git

Motivation

PATH environment variable syntax on Windows vs Linux scares me, so I wrote this utility to be able to explore PATH more easily.

Notes

  1. Neither pathit nor any child process cannot modify your shell PATH, just view it.
  2. Yes, you can run echo $PATH | tr ";" "\n" | sort instead of pathit show --sort on Linux.
  3. Even better tools than pathit may exist:
    • Rapid Environment Editor for Windows is a gem (no affiliation, just a thankful user).
    • Maybe some smart command-line utility in Rust will emerge for PATH, but not there yet.
    • There is pathdebug written in Go that goes a step futher and attempts to trace where your PATH is defined.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

justpath-0.0.4.tar.gz (16.0 kB view hashes)

Uploaded Source

Built Distribution

justpath-0.0.4-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page