Last active
June 3, 2020 12:59
-
-
Save danielporto/c5d66068a77d6fd928a9d35faf584128 to your computer and use it in GitHub Desktop.
Python plumbum examples for most common tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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