Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for querying packages #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Checks for archlinux
OS_INFO=$(cat /etc/os-release | grep -i 'archlinux')
if [ "$?" -eq 0 ]; then
pkg_srch=$(pacman -Ss | grep ${1})

if [ "$?" -eq 0 ]; then
sudo pacman -Syu ${1} 2> /dev/null
else
exit 1
fi
fi

# Checks for Ubuntu
OS_INFO=$(cat /etc/os-release | grep -i 'Ubuntu')
if [ "$?" -eq 0 ]; then
pkg_srch=$(apt-get list | grep ${1})

if [ "$?" -eq 0 ]; then
sudo apt-get install -y ${1} 2> /dev/null
else
exit 1
fi
fi

# Checks for fedora
OS_INFO=$(cat /etc/os-release | grep -i 'fedora')
if [ "$?" -eq 0 ]; then
pkg_srch=$(yum list | grep ${1})

if [ "$?" -eq 0 ]; then
sudo yum update && yum install -y ${1} 2> /dev/null
else
exit 1
fi
fi

# Will Check for gentoo
# OS_INFO=$(cat /etc/os-release | grep -i 'gentoo')
# if [ "$?" -eq 0 ]; then
# emerge -s ${1}
#
# if [ "$?" -eq 0 ]; then
# emerge ${1} 2> /dev/null
# else
# exit 1
# fi
# fi
12 changes: 10 additions & 2 deletions zpyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import os
from math import *
import subprocess

if 'ZPYI_IMPORTS' in os.environ:
for module in os.environ['ZPYI_IMPORTS'].split(','):
Expand Down Expand Up @@ -38,10 +39,17 @@ def cleanup():
# Use try catch to return only after cleanup
try:
if len(code) == 1 and not code[0].startswith('print'):

# Call to import script to check if it's a package and installable
_import_call_result = subprocess.call(['./import.sh', code[0]])

# If the above call exits with non-zero status than the usual eval
# is called so that
# Commands like:
# '1+2'
# Also should display output
print (eval(code[0]))
# Also display output
if _import_call_result != 0:
print (eval(code[0]))
else:
# Bigger commands
# 'a = 2
Expand Down
12 changes: 8 additions & 4 deletions zpyi.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ command_not_found_handler() {
# and still work.
zpyi_dir=$(dirname ${(%):-%x})

if [ "$#" -ne 1 ]; then
python ${zpyi_dir}/zpyi.py $INPUT_PIPE $ARGS_PIPE
rm $ARGS_PIPE
if [[ -a ${zpyi_dir}/zpyi.py ]]; then
if [ "$#" -ne 1 ]; then
python ${zpyi_dir}/zpyi.py $INPUT_PIPE $ARGS_PIPE
rm $ARGS_PIPE
else
python ${zpyi_dir}/zpyi.py $INPUT_PIPE
fi
else
python ${zpyi_dir}/zpyi.py $INPUT_PIPE
echo "Couldn't find ${zpyi_dir}/zpyi.py...Downloading again might help."
fi

# Optionally uncomment the below lines if
Expand Down