All Projects → sakshamsharma → Zpyi

sakshamsharma / Zpyi

Licence: mit
The power of python in your Zsh - Unobtrusive and easy python scripting in shell

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to Zpyi

Nostromo
CLI for building powerful aliases
Stars: ✭ 76 (-2.56%)
Mutual labels:  zsh, tool
Awesome Osx
📦 Awesome stuff for OSX
Stars: ✭ 54 (-30.77%)
Mutual labels:  zsh, tool
Andes
Python toolbox / library for power system transient dynamics simulation with symbolic modeling and numerical analysis 🔥
Stars: ✭ 68 (-12.82%)
Mutual labels:  tool
Code Checker
✅ A simple tool to check source code against a set of Nette coding standards.
Stars: ✭ 76 (-2.56%)
Mutual labels:  tool
Deployer
A deployment tool written in PHP with support for popular frameworks out of the box
Stars: ✭ 8,928 (+11346.15%)
Mutual labels:  tool
Eye
Process monitoring tool. Inspired from Bluepill and God.
Stars: ✭ 1,167 (+1396.15%)
Mutual labels:  tool
Colorechoforshell
Make 🐚(shell) 's 💬 (`echo`) to be 🌈 easily ✨ Support ✅ sh ➕ bash ➕ zsh ➕ ksh ➕ 🐟
Stars: ✭ 75 (-3.85%)
Mutual labels:  zsh
Animockup
Create animated mockups in the browser 🔥
Stars: ✭ 1,152 (+1376.92%)
Mutual labels:  tool
To Vim Tmux Zsh
如何让 vim,tmux,zsh 成为我们的神器
Stars: ✭ 78 (+0%)
Mutual labels:  zsh
Flutter device preview
Approximate how your app looks and performs on another device.
Stars: ✭ 1,191 (+1426.92%)
Mutual labels:  tool
Pi
A minimalist zsh theme with git status decorations
Stars: ✭ 76 (-2.56%)
Mutual labels:  zsh
Lambda Gitster
oh-my-zsh theme
Stars: ✭ 74 (-5.13%)
Mutual labels:  zsh
Dotfiles
💻 Dotfiles for zsh, vim, emacs, tmux, and bash. Tested on mac os.
Stars: ✭ 70 (-10.26%)
Mutual labels:  zsh
Appimage Builder
Recipe based AppImage creation tool
Stars: ✭ 76 (-2.56%)
Mutual labels:  tool
Imgursniper
📷 A quick and easy Image, Screenshot and Screen recording sharing tool
Stars: ✭ 69 (-11.54%)
Mutual labels:  tool
Ptdesigner
Library and GUI tool for designing and generation of procedural textures, made as a part of my Bachelor thesis.
Stars: ✭ 77 (-1.28%)
Mutual labels:  tool
Cloud Security Audit
A command line security audit tool for Amazon Web Services
Stars: ✭ 68 (-12.82%)
Mutual labels:  tool
Image To Xls
A simple tool to make ascii art from an image using excel colored cells.
Stars: ✭ 75 (-3.85%)
Mutual labels:  tool
Labeler
Manage labels on GitHub as code
Stars: ✭ 78 (+0%)
Mutual labels:  tool
Vg
Virtualgo: Easy and powerful workspace based development for go
Stars: ✭ 1,213 (+1455.13%)
Mutual labels:  zsh

zpyi

zpyi makes your shell smarter, in more ways than one. It's no magic, it's python.

                    _
                   (_)
 ____ _ __   _   _  _
|_  /| '_ \ | | | || |
 / / | |_) || |_| || |
/___|| .__/  \__, ||_|
     | |      __/ |
     |_|     |___/

Your shell now falls back to python if some command couldn't be handled by zsh. So you can now do 2+3 directly in your shell. Well, something much more complex than that too.

Of course, to prevent breaking any existing functionality provided by Zsh, you need to use '2**107' instead of 2**107 and the likes. Simply enclose your python program by some unused delimiters, and you're good to go.

You can assume that anything written at the start of a shell command, within single or double quotes would be interpreted as a python script.

Also, now instead of piping shell output to age-old (and still awesome, don't get me wrong) programs like awk, grep, sed, you can actually pipe shell output to short Python inline scripts, just like the good old awk scripts.

Of note, this is not a subset of python -c. python -c will not let you run python programs. It lets you run interactive python commands. Using zpyi, you can actually write programs and keep them in shell history, just like you've been doing with awk and grep since ages.

Examples

Here are some cool things you can now do. Note that all the code blocks below are to be run in the shell itself! No need to write python scripts to do small one-time stuff. And all this stays in your shell history! No need to store your small scripts too.

Cool One liners

  • '2**107'
  • 'sqrt(10)'
  • '"user".upper()'
  • Multiline code!
'
a = 1
b = 2**107
c = a + b
print (c*2)
'

Use shell commands and env vars inside python code

  • "print ('$(whoami)'.upper())"
  • export myname="me"; "print ('$myname is nice')"

Pass stuff to python script using stdin

cat /etc/passwd | '
lines = sys.stdin.readlines()

for line in lines:
    print line.upper()
'

Stdin and Stdout redirection

  • 'print (input().upper())' < infile > outfile
  • echo "what, my name is shady" | 'print (input().upper())'

Command line parameters

Yes, they work too, using either the sys.argv or argv to refer to the 1 based indexing. There is also an array named args which has the args in 0 based indexing

  • 'print (str(int(sys.argv[1]) + int(sys.argv[2])))' 2 3 returns 5
  • 'print (str(int(args[0]) + int(args[1])))' 2 3 returns 5 too

Imports!

The modules math, sys and os are already imported!

In addition, you can define an environment variable to use any custom imports, thanks to @orf for the PR on this!

# This is a shell command, run in your shell
export ZPYI_IMPORTS=requests

# This is the python line you run
"get('http://google.com')"

So now you don't need to run python -c 'print(sqrt(2**10))' > outputfile, only to remember that it won't work because math is not imported while using python -c.

Write cool shell scripts

Here's a simple zsh script to be run via zsh script.sh. Just that now you don't need to do complicated string parsing in shell, when you have python for that.

source ~/.zshrc
myname=$(whoami)
"print ('${myname}'.upper())"

Installing?

The installation script is concise enough:

cd ~
git clone https://github.com/sakshamsharma/zpyi ~/.zpyi
echo "source ~/.zpyi/zpyi.zsh" >> ~/.zshrc
source ~/.zshrc

If you feel lazy, this works too:

curl https://raw.githubusercontent.com/sakshamsharma/zpyi/master/install_script.sh | bash

Or if you make use of antigen (which is probably a good idea):

antigen bundle https://github.com/sakshamsharma/zpyi zpyi.zsh

Uninstallation

rm -rf ~/.zpyi
sed -i '/zpyi.zsh/d' ~/.zshrc

TODO

  • Add support for querying for missing packages
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].