Giter Club home page Giter Club logo

niceshell's Introduction

niceshell - Python 3 module for better shell coding

Requirements

  • Python 3.6+ (tested on 3.6.0)

Installation

Automatic installation

python3 -m pip install niceshell

Manual installation

cd /tmp/
version=2.0.3 # Choose desired version
wget -c "https://github.com/Andrew15-5/niceshell/releases/download/v${version}/niceshell-${version}-py3-none-any.whl"
python3 -m pip -U --user install niceshell-${version}-py3-none-any.whl

Usage

from niceshell import *
ext = "py"

process1 = ls(f"*.{ext}", batch=True)
if process1.exit_code():
    print("No Python scripts here. :(")
    print("stderr:", process1.error_output(), end='')
    exit(1)

process2 = ls(f"*.{ext}", True).shell("head -n 5")
print("stdout:", process2.output(), end='')
files = process2.get_lines()

ln(files, "/tmp/").wait()

Important note

Due to different preferences among coders some things like:

  • raised error instead of silently returned error code or None
  • type of raised error and its message;
  • behavior of edge cases (the way parameter's data is handled);
  • parameter names and their ordinal position
  • behavior of command with provided input text (with sudo)

can be inconvenient to some extent for someone and be perfect for others. Therefore, I encourage everyone to test result of each function, method, variable, constant, etc. to be 100% sure of how your script/program/app will handle every situation.

There are some tests in "tests" directory (./niceshell/tests/) to get you started. And of course you can see implementation of whatever the module provides for better understanding of what you are looking for.

Complete list of modules and their functions/classes

Note: list can be exteneded in future updates.

  • __init__
    • GID ($USER's group ID)
    • GROUP ($USER's group name)
    • HOME ($USERS's home dir aka '~')
    • UID ($USER's ID)
    • USER ($USER)
  • core
    • expose_tilde()
    • normalize_short_and_long_args()
    • quotes_wrapper()
    • shell()
    • Shell
    • ShortArgsOption
  • extra
    • force_sudo_password_promt()
    • get_root_privileges()
    • get_root_privileges_or_exit()
    • has_root_privileges()
    • list_dirs()
    • list_files()
  • gnu_coreutils
    • cd()
    • cp()
    • ln()
    • ls()
    • mv()
    • pwd()
    • rm()

TODO list

  • Add grep
  • Add dirname and basename
  • Add pwd
  • Add functions to get dirs and files from path
  • Add ability to install module via pip
  • Add ability to get command's output and pipe it to another command
  • Add function that check if sudo can be used without password
  • Add ability to provide input to command in core.Shell
  • Add cd
  • Add mv
  • Add rm
  • Add cp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.