Package: justpath
justpathJust a simple utility to explorePATHenvironment variable on both Windows and Linux.Workflowjustpathshows yourPATHenvironment variable line by line with numbering, comments and highlighing
and helps detecting invalid or duplicate directories on your PATH.You can also create a modified version ofPATHstring and use it to setPATHin your shell startup script
or through an environment manager. Note thatjustpathcannot change your shellPATHdirectly.My own use case forjustpathwas exploring and sanitizing thePATHon Windows together with Rapid Environment Editor.
I also find it useful to inspectPATHon a remote enviroment like Codespaces to detect invalid paths.Try quicklyInstall:pip install justpathTry the following:justpath --rawjustpathjustpath --countjustpath --invalidjustpath --duplicatesjustpath --correct --stringScreencastBasic usageWhat is the raw content ofPATHstring?justpath --rawList directories inPATHline by line.justpathSame as above, but no line numbers, no comments, no color, just bare text.justpath --bare --no-colorShow directories from PATH in alphabetic order[^1]:justpath --sort[^1]: Sorting helps to view and analyzePATH. Do not put a sortedPATHback on your system as you will loose useful information about path resolution order.What are the paths that containbinstring?justpath --includes binWhat are the paths that do not containwindowsstring?justpath --excludes windowsAre there any directories inPATHthat do not exist?justpath --invalidAre there any duplicate directories inPATH?justpath --duplicatesWhat is thePATHwithout invalid paths and duplicates?justpath --purge-invalid --purge-duplicatesMore concise:justpath --correctA cleanPATHstring in OS-native format:justpath --correct --stringUseful cases1. Filter directory namesjustpathallows to filter paths that must or must not include a certain string.
Filtering is case insensitive,--includes windowsand--includes Windowswill
produce the same result.--excludesflag will filter out the directories containing provided string.λ justpath --sort --includes windows --excludes system3239 C:\Users\Евгений\AppData\Local\Microsoft\WindowsApps24 C:\WINDOWS14 C:\Windows46 C:\tools\Cmder\vendor\git-for-windows\cmd47 C:\tools\Cmder\vendor\git-for-windows\mingw64\bin12 C:\tools\Cmder\vendor\git-for-windows\usr\bin2. Directory does not exist or not a directoryjustpathwill 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/bindoes not exist,
but included inPATH.λ justpath --sort --includes sdkman19 /usr/local/sdkman/bin23 /usr/local/sdkman/candidates/ant/current/bin (directory does not exist)21 /usr/local/sdkman/candidates/gradle/current/bin20 /usr/local/sdkman/candidates/java/current/bin22 /usr/local/sdkman/candidates/maven/current/binAdded filetouch d:\quarto\this_is_a_filefor example below.λ justpath --includes quarto33 C:\Program Files\Quarto\bin41 D:\Quarto\bin50 x:\quarto\does_not_exist (directory does not exist)51 d:\quarto\this_is_a_file (not a directory)Use--invalidflag to explore what parts of PATH do not exist or not a directory.λ justpath --includes quarto --invalid50 x:\quarto\does_not_exist (directory does not exist)51 d:\quarto\this_is_a_file (not a directory)3. Purge incorrect paths--correctflag will drop invalid paths from listing.λ justpath --includes quarto --correct33 C:\Program Files\Quarto\bin41 D:\Quarto\bin--correctflag is the same as applying both--purge-invalidand--purge-duplicatesflag. The duplicates are purged from the end of a string.You may also add--follow-symlinksflag in order to resolve symbolic links
when counting and purging duplicate directories.4. DumpPATHas JSONjustpathcan dump a list of paths fromPATHto JSON.
You may add--correctflag to list only correct paths.justpath --correct --json5. Create new content string forPATHWithjustpathyou can create newPATHcontents and use it in your shell startup script.
As any child processjustpathitself 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--stringouput flag.λ justpath --correct --stringC:\tools\Cmder\bin;C:\tools\Cmder\vendor\bin;C:\Windows\system32;C:\Windows;...6. Count directories inPATHλ justpath --count52 directories in your PATH1 does not exist16 duplicatesλ justpath --count --json
{"total": 52, "invalid": 1, "duplicates": 16}InstallationStable versionpip install justpathDevelopment versiongit clone https://github.com/epogrebnyak/justpath.gitcd justpathpip install -e .or shorter:pip install git+https://github.com/epogrebnyak/justpath.gitCLI toolAfter installation you can try the command line script:justpath --helpMotivationI thinkthis quoteaboutPATHis quite right:I always get the feeling that nobody knows what a PATH is and at this point they are too afraid to ask.PATHenvironment variable syntax on Windows and on Linux are different,
so I wrote this utility to be able to explorePATHmore easily.Some of positive feedback I got forjustpath:I like it! I do the steps involved in this occasionally, manually.
It's not hard but this makes it nice.
Not sure I'll use it since it is one more thing to install and remember,
but the author had an itch and scratched it. Well done.DiscussionsI made posts about this package on Reddit and at Hacker News. Click on badges above to follow the discussions.Development notesMore aboutPATHSeelinks.mdfor more information aboutPATH.Making of command line interfaces (CLIs)Few good links about CLI applications in general:docoptis a great package to develop intuition about command line interfaces.clig- ton of useful suggestions about CLIs including expected standard flags (--silent,--json, etc).12 factor CLI app- cited byclig.AlternativesLinux scriptingOn Linux you can runecho $PATH | tr ";" "\n"to view your path line by line and
combine it withgrep,sort,uniqandwc -lfor the same effect
as mostjustpathcommands. The benefit of a script is that you do not
need to install any extra dependency. The drawback is that not everyone is
good at writing bash scripts. Scripting also would a bit more problematic
on Windows.Check out the discussion atHacker Newsabout bash and zsh scripts andjustpathscenarios.Other utilitiesEven better tools thanjustpathmay exist.Rapid Environment Editorfor Windows
is a gem (no affiliation).Maybe some smart command-line utility in Rust will emerge for PATH specifically,
butnot there yet.There ispathdebugwritten in Go
that goes a step futher and attempts to trace where your PATH is defined.There is a family of tools to manage environment paths
likedotenvor its Python port, and a newer tool calledenviowritten in Rust.