Explore PATH environment variable on Windows and Linux.
Project description
justpath
Just a simple utility to explore and generate PATH
environment variable on both Windows and Linux.
Note that neither justpath
nor any child process cannot modify your shell PATH
, just view it.
With justpath
you can get a modified version of PATH
(e.g. by excluding non-existent paths),
and later you can use the generated string in your shell startup start.
Try quickly
Install:
pip install justpath
Try the following:
justpath
justpath --invalid
justpath --duplicates
justpath --correct
justpath --correct --string
Basic usage
What is the raw content of PATH
string?
justpath --raw
List directories in PATH
line by line.
justpath
Same as above, but no line numbers, no comments, no color, just bare text.
justpath --bare --no-color
Show directories from PATH in alphabetic order[^1]:
justpath --sort
[^1]: Sorting helps to view and analyze PATH
. Do not put a sorted PATH
back on your system as you will loose useful information about path resolution order.
What are the paths that contain bin
string?
justpath --includes bin
Are there any direcotries in PATH
that do not exist?
justpath --invalid
Are there any duplicate directories in PATH
?
justpath --duplicates
What is the PATH
without invalid paths and duplicates?
justpath --purge-invalid --purge-duplicates
More concise:
justpath --correct
A clean PATH
string in OS-native format:
justpath --correct --string
Useful cases
1. Filter directory names
justpath
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.
λ justpath --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
2. Directory does not exist or not a directory
justpath
will indicate if path does not exist or path is not a directory.
Below is an example from Github Codespaces, for some reason
/usr/local/sdkman/candidates/ant/current/bin
does not exist,
but included in PATH
.
λ justpath --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
Added file touch d:\quarto\this_is_a_file
for example below.
λ justpath --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 (not a directory)
Use --invalid
flag to explore what is parts of PATH do not exist.
λ justpath --includes quarto --invalid
50 x:\quarto\does_not_exist (directory does not exist)
51 d:\quarto\this_is_a_file (not a directory)
3. Purge incorrect paths
--correct
flag will drop invalid paths from listing.
λ justpath --includes quarto --correct
33 C:\Program Files\Quarto\bin
41 D:\Quarto\bin
--correct
flag is the same as applying both --purge-invalid
and --purge-duplicates
flag.
4. Dump PATH
as JSON
justpath
you can dump a list of paths from PATH
to JSON.
You may add --correct
flag to list only correct paths.
justpath --correct --json
5. Create new content string for PATH
With justpath
you can create new PATH
contents and use it in your shell startup script.
As any child process justpath
itself cannot modify PATH in your current environment.
You can get a valid string for your PATH in a format native to your operating system
using --string
ouput flag.
λ justpath --correct --string
C:\tools\Cmder\bin;C:\tools\Cmder\vendor\bin;C:\Windows\system32;C:\Windows;...
6. Count directories in PATH
λ justpath --count
52 directories in your PATH
1 does not exist
16 duplicates
λ justpath --count --json
{"total": 52, "invalid": 1, "duplicates": 16}
Installation
Stable version
pip install justpath
Development version
git clone https://github.com/epogrebnyak/justpath.git
cd justpath
pip install -e .
or shorter:
pip install git+https://github.com/epogrebnyak/justpath.git
CLI tool
After installation you can try the command line script:
justpath --help
Motivation
I think this quote about PATH
is quite right:
I always get the feeling that nobody knows what a PATH is and at this point they are too afraid to ask.
PATH
environment variable syntax on Windows and on Linux are different,
so I wrote this utility to be able to explore PATH
more easily.
Development notes
- See links.md for more about
PATH
. - Few good links about CLI apps in general
- docopt is a great package to develop intuition about command line interfaces.
- clig - ton of useful suggestions about CLIs.
- 12 factor CLI app - cited by
clig
.
Alternatives
Even better tools than justpath
may exist.
- On Linux you can run
echo $PATH | tr ";" "\n"
to view your path line by line and combine it withgrep
to gain more insights. - Rapid Environment Editor for Windows is a gem (no affiliation).
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for justpath-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa72c78b63946f429520ce52e136e48859283c40d98565876c32ee01f97144d4 |
|
MD5 | 40421a82b921823bdd6d63b8d89bc20c |
|
BLAKE2b-256 | 3725a5ff5d5c846d98158ec5608ac5d666c6bbcafaad90b8bdf95c703bcf9c89 |