Skip to content

Instantly share code, notes, and snippets.

@danielporto
Last active June 3, 2020 12:59
Show Gist options
  • Save danielporto/c5d66068a77d6fd928a9d35faf584128 to your computer and use it in GitHub Desktop.
Save danielporto/c5d66068a77d6fd928a9d35faf584128 to your computer and use it in GitHub Desktop.
Python plumbum examples for most common tasks
# basics, importing bash commands
from plumbum import local, FG, BG, TF, RETCODE
from plumbum.cmd import sudo, true, rm, ln, echo, tee, cp, mv, ls, find, grep, curl, zsh, cat
# defining a command
ls = ls['-l','/tmp']
# calling the command
ls()
# defining and calling a command
ls['-l','/tmp'].run()
# alternative
ls['-l','/tmp'] & FG
# running an application
caffeinate = local["caffeinate"]
caff = caffeinate.popen("-i -d")
# curl script to shell
curl["https://raw.githubusercontent.com/zimfw/install/master/install.zsh","-o","/tmp/zimfw_install.zsh"].run()
cat["/tmp/zimfw_install.zsh"] | zsh["/tmp/zimfw_install.zsh"].run()
# call an alias command from a python script (such as wd or zimfw)
# simple answer, you dont. use subprocess.
import subprocess
subprocess.call(['/bin/zsh', '-i', '-c', 'zimfw install'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment