-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#15 flag renamed to
--shell-equivalents
, lists 3 shell jobs in total
- Loading branch information
1 parent
73b02b9
commit eba115a
Showing
6 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class OneLiner: | ||
job: str | ||
justpath_args: str | ||
bash: str = "" | ||
cmd: str = "" | ||
ps: str = "" | ||
python: str = "" | ||
|
||
@property | ||
def justpath(self): | ||
return "justpath " + self.justpath_args | ||
|
||
@property | ||
def python_command(self): | ||
return f'python -c "{self.python}"' | ||
|
||
def print(self): | ||
print(self.job) | ||
if self.bash: | ||
print("bash (Linux):\n ", self.bash) | ||
if self.cmd: | ||
print("cmd.exe (Windows):\n ", self.cmd) | ||
if self.ps: | ||
print("poweshell (Windows):\n ", self.ps) | ||
if self.python: | ||
print("python (any OS):\n ", self.python_command) | ||
print("justpath (any OS):\n ", self.justpath) | ||
|
||
|
||
RAW = OneLiner( | ||
job="Print PATH as is", | ||
justpath_args="--raw", | ||
bash="echo $PATH", | ||
cmd="echo %PATH%", | ||
ps="echo $Env:PATH", | ||
python="import os; print(os.environ['PATH']", | ||
) | ||
|
||
BY_LINE = OneLiner( | ||
job="Print PATH by line (possibly with line numbers)", | ||
justpath_args="", | ||
bash='echo $PATH | tr ":" "\\n" | nl', | ||
ps='$env:PATH.split(";")', | ||
python="import os; print(os.environ['PATH'].replace(os.pathsep, '\\n'))", | ||
) | ||
|
||
DUPLICATES = OneLiner( | ||
job="Show duplicate directories", | ||
justpath_args="--duplicates # preserves order from PATH", | ||
bash='echo $PATH | tr ":" "\\n" | sort | uniq -d # does not preserve order from PATH', | ||
) | ||
|
||
def print_alternatives(): | ||
for job in [RAW, DUPLICATES, BY_LINE]: | ||
job.print() | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "justpath" | ||
version = "0.0.15" | ||
version = "0.0.16" | ||
description = "Explore PATH environment variable on Windows and Linux." | ||
authors = ["Evgeny Pogrebnyak <[email protected]>"] | ||
license = "GNU" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from justpath.oneliners import RAW, BY_LINE, DUPLICATES | ||
|
||
|
||
def test_oneliners(): | ||
RAW.print() | ||
BY_LINE.print() | ||
DUPLICATES.print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters