• Stars
    star
    337
  • Rank 125,272 (Top 3 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created 10 months ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inspect and refine PATH environment variable on Windows, Linux and MacOS.

justpath

CI PyPI - Version Reddit Hacker News Python Bytes

Just a simple utility to explore PATH environment variable on Windows, Linux and MacOS.

Workflow

justpath shows your PATH environment 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 of PATH string and use it in your shell startup script or through an environment manager. Note that justpath itself cannot change your shell PATH.

Try quickly

Install (with pip or pipx):

pip install justpath

Try the following:

justpath --raw
justpath
justpath --count
justpath --invalid
justpath --duplicates
justpath --duplicates --follow-symlinks
justpath --correct --string

Screencast

asciicast

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

Show directories from PATH in alphabetic order1:

justpath --sort

What are the paths that contain bin string?

justpath --includes bin

What are the paths that do not contain windows string?

justpath --excludes windows

Are there any directories in PATH that do not exist?

justpath --invalid

Are there any duplicate directories in PATH?

justpath --duplicates

Same, but resolving symbolic links:

justpath --duplicates --follow-symlinks

What is the PATH without invalid paths and duplicates?

justpath --purge-invalid --purge-duplicates

Same as above, but more concise:

justpath --correct

A clean PATH string in OS-native format:

justpath --correct --string

One-line alternatives for justpath commands where they exist:

justpath --shell-equivalents

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. --excludes flag will filter out the directories containing provided string.

λ 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 parts of PATH do not exist or not a directory.

λ 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. The duplicates are purged from the end of a string.

You may also add --follow-symlinks flag in order to resolve symbolic links when counting and purging duplicate directories.

4. Dump PATH as JSON

justpath 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}

7. Follow symlinks when looking for duplicates

Often times symbolic links are added to PATH to point to a particular version of a package. You can discover more duplicate directories with --follow-symlinks flag.

$ justpath --duplicates --follow-symlinks --includes dotnet
 6 /home/codespace/.dotnet (resolves to /usr/local/dotnet/7.0.306, duplicates: 2)
32 /usr/local/dotnet/current (resolves to /usr/local/dotnet/7.0.306, duplicates: 2)

$ justpath --duplicates --follow-symlinks --includes java
10 /home/codespace/java/current/bin (resolves to /usr/local/sdkman/candidates/java/21.0.1-ms/bin, duplicates: 2)
19 /usr/local/sdkman/candidates/java/current/bin (resolves to /usr/local/sdkman/candidates/java/21.0.1-ms/bin, duplicates: 2)

Installation

Stable version

pip install justpath

or with pipx

pipx 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

Other package managers

Installation via conda or homebrew not yet supported.

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.

My own use case for justpath was exploring and sanitizing the PATH on Windows together with Rapid Environment Editor. I also find it useful to inspect PATH on a remote enviroment like Codespaces to detect invalid paths.

Feedback

Some of positive feedback I got about the justpath package:

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.

It's handy to see your path entries in a list. Checking whether each entry is a valid location is neat, too. But even better, from my perspective, you published the code and got feedback from people, including related implementations. That’s worth it, in my book. Edit: I like the includes part, too.

I think this is a cool package. Some of my first scripts in several languages have just been messing with file system abstractions. Files and file paths are much more complex than most people think.

Development notes

More about PATH

See links.md for more information about PATH.

Making of command line interfaces (CLIs)

Few good links about CLI applications in general:

  • docopt is 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 by clig.

Alternatives

Linux scripting

On Linux you can run echo $PATH | tr ";" "\n" to view your path line by line and combine it with grep, sort, uniq and wc -l for the similar effect as justpath commands.

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 would also be a bit more problematic on Windows.

Check out the discussion at Hacker News about bash and zsh scripts and justpath scenarios.

Tip

justpath --shell-equivalents provides a reference about one line commands for several shells that do similar jobs as justpath itself.

Other utilities

Even better tools than justpath may exist.

  • Rapid Environment Editor for Windows is a gem (no affiliation).
  • Maybe some smart command-line utility in Rust will emerge for PATH specifically, but not there yet.
  • There is pathdebug written 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 like dotenv or its Python port, and a newer tool called envio written in Rust.

Footnotes

  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.

More Repositories

1

abacus

A minimal yet valid double-entry accounting system in Python or command line.
Python
58
star
2

haskell-intro

Seven classes on Haskell and a follow-up reading list
Haskell
53
star
3

weo-reader

Python client to read IMF World Economic Outlook (WEO) dataset as pandas dataframe.
Jupyter Notebook
31
star
4

ssg-dataset

Open reproducible dataset on static site generators (SSG) popularity.
Python
28
star
5

data-ust

US Treasuries Yield Curve Data
Python
20
star
6

econometrics-navigator

Review econometrics concepts with code examples
TeX
13
star
7

finec

Financial data and computation for Finec MGIMO students.
Python
11
star
8

ru-cities

Russian cities names, regions, population estimate and geographic coordinates.
Python
10
star
9

impression

Minimal setup to work with Poetry, Sphinx and Streamlit out of the box
Python
8
star
10

justsubs

Download subtitles from YouTube as plain text.
Python
8
star
11

mlmw

Machine Learning My Way (MLMW): a self-study guide for probability, statistics, econometrics and machine learning.
Python
7
star
12

abacus-minimal

A minimal ledger in Python that follows accounting rules
Python
7
star
13

data-rosstat-kep

Time series dataset of Rosstat Short-term Economic Indicators ("KEP") publication
Python
6
star
14

cbr-soap-py

SOAP interface to Bank of Russia online data
Python
5
star
15

accounting

Build your own accounting system in Excel, Python or Haskell
Haskell
5
star
16

linprog

Several PuLP examples for production scheduling
Python
5
star
17

mle-for-nowcasting

Example of maximum likelihood estimation in Python (follows Matlab code)
Python
4
star
18

cmf-macro

Macroeconomic course for CMF
Jupyter Notebook
4
star
19

hrange

Plot horizontal timelines
Python
4
star
20

superhero

Управление данными, программирование, разработка и ИТ-архитекутра - руководителям и бизнесу
4
star
21

facebook-json-to-csv

Convert your personal Facebook JSON archive to CSV or pandas dataframe for data analysis
Python
4
star
22

r-python-julia-book

Why choose - learn them all: R, Python and Julia for economic and financial datasets.
3
star
23

ru-bubble-map

City population bubble map for Russia
HTML
3
star
24

LessOLS.jl

Building a simplistic econometrics package in Julia
Julia
3
star
25

rides-minimal

Car tracks analysis
Python
3
star
26

query-media-wiki-api-category

Query MediaWiki/WikiData by category and its dependents
Python
3
star
27

data-fx-oil

Russian rouble vs oil price graphs and data
HTML
3
star
28

learn-plot

Review of plotting with python
2
star
29

learn-orgmode

My notes about starting Emacs org-mode in WSL (August 2021)
2
star
30

economist-tools

Dataset access, learning resources and research reproducibility
2
star
31

comtrade

Get data from UN Comtrade API as pandas dataframes
Python
2
star
32

multiple-regression-revisited

Standard use and assumption violations for linear regression
Julia
2
star
33

learn

Personal collection of learning resources and some inspiration in programming.
2
star
34

soybean-crush-spread

Measure value added from processing of soybeans to meal and oil, based on FAO data
Python
2
star
35

aloh

Отбор заказов и планирование производства связанных продуктов.
Python
2
star
36

data-rosstat-806-regional

Russian regional economic monitoring datasets
Python
2
star
37

data-lab

Macroeconomic data sandbox
Python
1
star
38

banking

Open source guide to banking data
1
star
39

corporate-banking-course

Course draft - bank corporate lending
HTML
1
star
40

Business-Conditions-Digest-2017

Replicate illustration from Business Conditions Digest
Python
1
star
41

viz_demo

Matplotlib demo
Jupyter Notebook
1
star
42

as-ikea

Convert your name to Ikea product name
Python
1
star
43

notes-slides

Render markdown into html presentation with pandoc
Batchfile
1
star
44

360

Нетехнический курс по информационным технологиям в бизнесе
1
star
45

cmf-dsge

DSGE models for CMF course
1
star
46

energy-electricity-levelised-costs

Calculation of electricty generation costs
1
star
47

cbr-db

Russian banking sector statistics tools (ETL)
Python
1
star
48

plotting

Python ways and means for presentation-grade plotting
Python
1
star
49

notes-linux-cli

A journey from Windows world to Linux command line.
Python
1
star
50

systemfit

Klein model I solved by R (systemfit) and in gretl
R
1
star
51

epogrebnyak.github.io

Personal page
1
star
52

pandoc-for-dummies

Suggestion for beginner track in Zurihac 2021 #pandoc channel
1
star
53

lamr

Python course at command line.
Python
1
star
54

cmf-comovement-tables

Study cases to analyse correlation between detrended residuals in economic time series with different lags
1
star
55

datasets

A dashboard of datasets and codebooks I maintain: boo, weo and other.
1
star
56

anniversary

An anniversary website for Alena from SpB with love (01.03.2021)
1
star
57

pychain

Demonstrate the logic of blockchain and smart contracts using Python (as simple and intuitive as possible)
Jupyter Notebook
1
star
58

cbr-bankform-reader

Reads bank form data from DBF and text files. Emits clean data by row, storable in a database. Supports form 101 and 102.
Python
1
star
59

Handout.jl

Port of python Handout
Julia
1
star
60

notes-pandoc

Markdown to PDF workflow
TeX
1
star
61

product-topics

1
star
62

icode

This is a blog about my coding experience in Python and learning of Julia and Haskell
1
star
63

manubot-cite-minimal

A study of `manubot cite` core functionality
Python
1
star
64

reading-list

Machine learning, econometrics, finance
1
star
65

python-random-quote

A file-based quote bot written in Python
Python
1
star
66

vault

Encode and decode a local text file with password.
Python
1
star