• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Python API to execute shell functions as they would be Python functions

shellfuncs

Build Status PyPI package version PyPI python versions

Python API to execute functions written in shell script.

Let's assume you have a shell script counters.sh like this:

count_python_imports() {
    find -name '*.py' | xargs grep -e '^import os$' -e '^import sys$' -e '^import re$' | cut -d: -f2 | sort | uniq -c
}

And you want to execute the count_python_imports function within Python. Instead of using cumbersome subprocess wouldn't it be awesome to do something like this:

import shellfuncs

from counters import count_python_imports

returncode, stdout, stderr = count_python_imports()

Yeah, yeah, I know about easier ways of achieving the above, too. Thanks.

Why should I use that?

  • use existing shell scripts in a pythonic way
  • complex piping stuff might be easier to implement in shell script
  • testing shell scripts is a pain in the a** - with Python it'll be easier

Installation

The recommended way to install shellfuncs is to use pip:

pip install shellfuncs

Usage

shellfuncs can be configured on different levels.

The following configuration variables are available:

  • shell (defaults to /bin/sh)
  • env (defaults to os.environ)

Configuration via environment variables

Set the default shell via SHELLFUNCS_DEFAULT_SHELL environment variable:

export SHELLFUNCS_DEFAULT_SHELL=/bin/bash

Configuration via context manager

Set the configuration block-wise with a context manager:

import shellfuncs

with shellfuncs.config(shell='/bin/bash'):
    from counters import count_python_imports

count_python_imports()  # the shell used will be /bin/bash

Configuration for specific function call

Set the configuration when function is executed:

import shellfuncs

from counters import count_python_imports

count_python_imports(shell='/bin/bash')

This project is published under MIT.
A Timo Furrer project.
- ๐ŸŽ‰ -

More Repositories

1

awesome-asyncio

A curated list of awesome Python asyncio frameworks, libraries, software and resources
4,607
star
2

try

Dead simple CLI tool to try Python packages - It's never been easier! ๐Ÿ“ฆ
Python
721
star
3

colorful

Terminal string styling done right, in Python ๐Ÿ ๐ŸŽ‰
Python
523
star
4

w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
Python
485
star
5

russian-roulette

๐Ÿ€ You want to push your luck? ... Go ahead and try your best with this CLI russian roulette! ๐Ÿ’ฅ
Shell
112
star
6

pandoc-plantuml-filter

Pandoc filter for PlantUML code blocks
Python
104
star
7

observable

minimalist event system for Python
Python
86
star
8

WOL

C program to send wol magic packets
C
79
star
9

pandoc-mermaid-filter

Pandoc filter for mermaid code blocks
Python
76
star
10

devheart

Listen to Tux's heartbeat with this awesome Linux Kernel Module โค๏ธ
C
57
star
11

git-russian-roulette

๐Ÿ€ play russian roulette in your git repository. ๐Ÿ”ซ
Shell
44
star
12

minion-ci

minimalist, decentralized, flexible Continuous Integration Server for hackers.
Python
43
star
13

javascript-style-guide

Ein vernรผnftiger Ansatz fรผr einen JavaScript-Style-Guide
35
star
14

securityheaders

๐Ÿ”’ CLI application to analyse Security Headers from a given URL using securityheaders.io
Python
19
star
15

musichaos

tool to tidy up your music chaos
Python
17
star
16

dropbox-cli

cli to manage your dropbox account
Python
10
star
17

ariseem

Minimalistic REST API for wake-on-lan
Python
10
star
18

leaked

Find leaked information in different kind of services
Python
9
star
19

retry-cmd

Retry commands on the command line without all the loops you always used!
Rust
9
star
20

confluo

โžฐ Minimalist scalable microservice framework for distributed systems using AMQP/RabbitMQ.
Python
9
star
21

ptipython-meta

Metapackage to install ptpython and ipython.
Python
7
star
22

idn-homograph-attack

Resources for "IDN Homograph Attack" for HSLU FKOM blog post testat
HTML
7
star
23

.vim

vim configuration for myself.
Vim Script
6
star
24

ramlient

Access to a RAML API done right, in Python. (Feasibility)
RAML
6
star
25

embedeval

NLP Embeddings Evaluation Tool
Python
5
star
26

avra-atmega2560

This repository is a clone of avra version 1.3.0 with additional fixes to support the ATmega2560 chip
C
5
star
27

dotfiles.attic

My personal dotfiles
Shell
4
star
28

broadcom-wl-monitormode

This is a source mirror for the broadcom wl driver version 6.30.223.141 with fixed monitor mode
C
4
star
29

hslu-pren-fs19

Implementation of the PREN FS2019 challenge at @ HSLU
Jupyter Notebook
4
star
30

saythanks-cli

Say Thanks via CLI. Uses @kennethreitz's great saythanks.io
Python
4
star
31

tag-expressions

Python implementation of Shunting-yard Algorithm to evaluate logical tag expressions
Python
3
star
32

dotfiles-2

Vim Script
3
star
33

hslu-pren-digit-cnn

Convolutional Neural Network to recognize digits used in the PREN class @ HSLU
Jupyter Notebook
3
star
34

python3.10-pattern-matching

Python 3.10 demos
Jupyter Notebook
3
star
35

pylemon

python daemon to monitor specific directories and react on changes
2
star
36

advent-of-code

My solutions for the Advent of Code puzzles
Python
2
star
37

java-dev

Java dev environment (Vagrant, Ansible, VirtualBox, Ubuntu 16.04) for HSLU
2
star
38

hslu-webtec-testat

HSLU WebTec Testat
JavaScript
2
star
39

pysingleton

module which provides a decorator to create thread-safe singleton classes
Python
2
star
40

lightning-talk-linux-kernel-module-examples

Examples for my "Linux Kernel Modules 101" Lightning Talk โšก
C
2
star
41

timofurrer.github.io

Personal website and blog
HTML
2
star
42

edelweiss

edelweiss. A delightful color scheme for my personal terminal stack
Lua
2
star
43

asciitable

print formatted ascii table on console
C
1
star
44

hslu-roblab-behavior

Python
1
star
45

sudoku.vim

vim plugin to solve sudoku files
Python
1
star
46

coverage-importlib-test

Python
1
star
47

.tmux

my tmux configuration
1
star
48

clicore

small cli to use in python programs
Python
1
star
49

schoolcli

This is a very useful command line interface to manage your school marks
Python
1
star
50

hslu-xml-technologies

HSLU - XML Technologies - Projektarbeit
XSLT
1
star
51

hslu-ipcv

Exercises for the IPCV class @ HSLU
Jupyter Notebook
1
star
52

hslu-dbs

HSLU - DBS
TypeScript
1
star
53

hslu-aiso

HSLU AISO Class Exercises
Jupyter Notebook
1
star
54

dotfiles

Lua
1
star