zpython 

Send to Kindle
home » snippets » zsh » zpython



Building on OS X

cd ~/vcs_3p
git clone https://bitbucket.org/ZyX_I/zsh.git zsh_zpython

cd zsh_zpython

autoreconf
./configure --disable-gdbm --enable-zpython --with-tcsetpgrp --prefix=/usr/local

# Edit Makefile:
#
# Append to "CFLAGS = "
#     -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
# Append to "LIBS = "
#     -L/opt/local/lib -L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7
# 
# replace
#   @for subdir in Src Doc; do \
# with
#   @for subdir in Src; do \
#

make

mkdir -p ~/.local/lib/zsh_modules/zsh
cp **/zpython.so ~/.local/lib/zsh_modules/zsh # for zsh 5.0.2
cp **/zpython.so ~/.local/lib/zsh_modules/zsh/zpython.bundle # for zsh 5.0.5 installed by macports

# Installation is done.  Test it out.

module_path=($module_path ~/.local/lib/zsh_modules)
zmodload zsh/zpython
zpython "print 'hello world'"

# Now maybe add this to zshenv or zshrc
if [[ "$ZSH_VERSION" == "5.0.2" || "$ZSH_VERSION" == "5.0.5" ]]; then
  module_path=($module_path $HOME/.local/lib/zsh_modules)
fi

Installing this zsh instead of just the .so

# The docs step will fail since we didn't build it (it
# doesn't build.)  So igore that.
sudo make install

# Verify that the permissions are ugo+rX.  For Ubuntu
# with prefix /usr/local, this would be:
#  
sudo chmod -R ugo+rX \
    /usr/local/share/zsh \
    /usr/local/lib/zsh \
    #

# Now, to change your shell, you need to register this
# binary in /etc/shells
#
# WARNING: If you lose access to this shell for some
# reason (e.g. you delete the binary, or a system
# upgrade breaks it in some way, you'll have trouble
# logging in!
sudo zsh -c (echo '/usr/local/bin/zsh' >> /etc/shells)

# Type out the full path to the new zsh in this step.
chsh

Some random stuff

zmodload zsh/zpython
zpython '
import datetime
import zsh

class Nows(object):
  def __str__(self):
    return str(datetime.datetime.now())

nows = Nows()

zsh.set_special_string("zpython_nows", nows)
'

echo $zpython_nows
sleep 1
echo $zpython_nows