Skip to main content

Tiny cross-OS shell-like helpers for Python

Project description

SHSIM

SHSIM is a tiny unified shell-like helpers, one could use shell like commands cross Windows, Linux and MacOS systems.

It contains following four commands types

  • Log
  • Environment Variables
  • Action
  • Status
  • Action + Status

Log Commands

Format: log(i|d|w|e|ii|dd)

Command Pattern Shell Equivalent Action Type Description
logi echo "INFO:" log print Print info message
logd echo "DEBUG:" log print Print debug message
logw echo "WARN:" log print Print warning message
loge echo "ERROR:" log print Print error message
logii echo "====\n...\n====" log print Info with divider
logdd echo "----\n...\n----" log print Debug with divider

Note:

  • All messages are prefixed with timestamp, filename, and line number.
  • Log messages are always teed to both stdout/stderr and file.
  • Log file is configured via shsim.logfile (default provided).

Action Commands

Format:

  • <command>: stdout/stderr output (shell-style)
  • <command>_list: Python list return for iteration
  • Suffix (_list) means the command supports both
Command Pattern Shell Equivalent Action Type Description
pwd pwd inspect return Get current working directory
abspath realpath path return Get absolute path of input
basename basename path path return Get last component of path
dirname dirname path path return Get parent directory of path
ext N/A path return Get file extension (e.g., .txt)
which which cmd system return Locate command in system PATH
cat(_list) cat read return Read file content
head(_list) head -n read return Read first N lines from file
tail(_list) tail -n read return Read last N lines from file
grep(_list) grep filter return Match lines by fixed string
grepn(_list) grep -n filter return Match lines with line number
egrep(_list) grep -E filter return Match using extended regex
egrepn(_list) grep -nE filter return Extended regex match with line numbers
ls(_list) ls list return List directory contents
lsa(_list) ls -a list return List all files, including hidden
lss(_list) ls -st list return List sorted by modified time
find(_list) find / glob list return Recursively find files
mkp mkdir -p modify exec Create directory and parents if needed
rmrf rm -rf modify exec Recursively delete file or directory
cprf cp -rf modify exec Recursively copy file or directory
mv mv modify exec Move or rename file or directory
touch touch modify exec Create file or update timestamp
ln ln modify exec Create symbolic link
lnsf ln -sf modify exec Force overwrite symbolic link
zipdir zip archive exec Create zip archive
unzip unzip archive exec Extract zip archive
cd cd exec exec Change current working directory
run(_list) echo && eval exec exec Show and execute shell command
envget echo $VAR env return Get environment variable
envset export VAR=val env exec Set environment variable
envlist(_list) set env return Show environment variables
envunset unset VAR env exec Remove environment variable
envappend export VAR=$VAR:val env exec Append value to env variable
envprepend export VAR=val:$VAR env exec Prepend value to env variable
envremove (custom parse/remove) env exec Remove value from env variable
envhas [[ ":$VAR:" == *:val:* ]] env return Check if env variable contains a value

Run Command Usage

run and run_list provide basic shell-style command execution.

Format:

  • run(cmd, ...) → Run shell command and print output
  • run_list(cmd, ...) → Run shell command and return list of output lines

Supported Parameters:

Parameter Type Description
bg=True bool Run in background (non-blocking)
delay=2.5 float Delay execution by seconds (supports float)
logfile="..." str Redirect stdout/stderr to log file (in addition to stdout/stderr)

Status Commands

Format: (is|no)(d|f|e|x|l)

  • is: means is true
  • no: means not true
  • d: directory
  • f: file
  • e: exists
  • x: executable
  • l: symlink
Command Pattern Shell Equivalent Action Type Description
isd [ -d path ] status return True if path is a directory
isf [ -f path ] status return True if path is a file
ise [ -e path ] status return True if path exists
isx [ -x path ] status return True if path is executable
isl [ -L path ] status return True if path is a symlink
nod [ ! -d path ] status return Not a directory
nof [ ! -f path ] status return Not a file
noe [ ! -e path ] status return Path does not exist
nox [ ! -x path ] status return Not executable
nol [ ! -L path ] status return Not a symlink

Combined Status + Action Commands

Format: <status>_<action>([_list])

Command Pattern Shell Equivalent Action Type Description
noe_mkp [ ! -e path ] && mkdir -p status+modify exec Make dir only if not exists
isd_rmrf [ -d path ] && rm -rf status+modify exec Remove dir only if it exists
isf_rmrf [ -f path ] && rm -rf status+modify exec Remove file only if it exists
ise_rmrf [ -e path ] && rm -rf status+modify exec Remove if it exists
ise_mv [ -e path ] && mv status+modify exec Move if source exists
ise_cprf [ -e path ] && cp -rf status+modify exec Copy if source exists
isd_lss(_list) ls -st if dir exists status+list return Sorted list only if directory exists
ise_cat(_list) cat if file exists status+read return Show file contents if exists
ise_grep(_list) grep if file exists status+filter return Grep lines only if file exists

Install

Install Command:

pip install shsim

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

shsim-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shsim-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file shsim-0.1.0.tar.gz.

File metadata

  • Download URL: shsim-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shsim-0.1.0.tar.gz
Algorithm Hash digest
SHA256 156eefe889d5e26cf83d25c6ef3aa4d9f6d6a69ecb1e5df422fee84c4e822ae3
MD5 4b9aff4ee93211ec9b50581046e18753
BLAKE2b-256 0f15682fab1d5133ae10c5e2d2fe637fdce52a8c3d2c5bdf888d71dedd72c17f

See more details on using hashes here.

File details

Details for the file shsim-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shsim-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shsim-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f79990c7abd95703f6f42a9972e9e406ab0621fd7f8c234e01ab7de6ecb72ef7
MD5 57540b80c4322e6da46ae55500a32fc7
BLAKE2b-256 37ebc6ed0409af7a9b1805ca27b90e6ffaf0cf2ef7a1cb601abccf9ee5082b9d

See more details on using hashes here.

Supported by

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