Metadata-Version: 2.4
Name: shell-lib
Version: 2.0.2
Summary: A Python utility to simplify the writing of shell-like scripts.
Author-email: Ma Lin <malincns@163.com>, Google Gemini <no@no.com>
License-Expression: MIT
Project-URL: Repository, https://bitbucket.org/wjssz/shell_lib
Project-URL: Documentation, https://shell-lib.readthedocs.io
Project-URL: Changelog, https://shell-lib.readthedocs.io/changelog.html
Classifier: Programming Language :: Python :: 3
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: System :: Shells
Classifier: Topic :: Utilities
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.7
Description-Content-Type: text/markdown

### Introduction

[Documentation](https://shell-lib.readthedocs.io) | [Changelog](https://shell-lib.readthedocs.io/changelog.html) | [Repository](https://bitbucket.org/wjssz/shell_lib)

`shell-lib` is designed to simplify the writing of shell-like scripts:

- Python syntax: Write scripts in readable Python, freeing from complex shell command syntax.
- Reliable error handling: Use Python's exception to manage command failure. If a command fails, by default, it raises a `subprocess.CalledProcessError` exception. For commands that may fail, user can also only check the exit-code.
- Cross-platform compatibility: Write a single script that works across Linux, macOS, and Windows platforms.
- Rich ecosystem integration: Easily integrate with both the CLI tool and Python library ecosystems.
- Lightweight and portable: Only use Python standard library.
- Well tested: Consistent and reliable behavior on different platforms and Python versions.
- Friendly: Readers can understand the code without consulting the documentation. If writers use modern IDEs, then almost no need to consult the documentation.

It provides some functions that make writing shell-like scripts easy:

1. Executing external command: Conveniently invoke external commands.
2. File and directory operations: Provide a consistent and intuitive file system operations API, that clearly distinguish between file and directory operations.
3. User interactions: Do common interactions with one line of code.
4. Obtaining system information: Get common system information for shell-like scripts.

This module was co-created with [Google Gemini](https://gemini.google.com/).

### Usage

```python
#!/usr/bin/python3
from shell_lib import sh

PROJECT_PATH = "my_project"
FILE = "hello.txt"

sh.create_dir(PROJECT_PATH)
# sh.cd() context manager restores the previous working directory when
# exiting the code block, even if an exception raised within the code block.
with sh.cd(PROJECT_PATH):
    sh(f"echo 'Hello, World!' > {FILE}")
    print(f"File size: {sh.get_file_size(FILE)} bytes")
sh.remove_dir(PROJECT_PATH)
```
There is a [demo script](https://shell-lib.readthedocs.io/#demo-script) at the documentation page.
