Skip to content

Commit

Permalink
add manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
yotsuyanagi committed Feb 19, 2016
1 parent bb2b780 commit 7665e92
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ temp
# Python
*.pyc
*.pyo
dist/
jj_menu.egg-info/

# Windows
Thumbs.db
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include activate-jj.sh
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Install
-------
::

$ sudo pip install git+https://github.com/junion-org/pip_github_test.git
$ pip install git+https://github.com/ytyng/jj-menu.git


Setup
Expand Down
9 changes: 9 additions & 0 deletions activate-jj.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
function jj(){
RESULT_FILE=/tmp/_jj_result
jj-menu --result-file=${RESULT_FILE}
if [ $? == 0 ]; then
echo "> `cat ${RESULT_FILE}`"
source ${RESULT_FILE}
fi
}
2 changes: 1 addition & 1 deletion jj_menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# coding: utf-8

__author__ = 'ytyng'
__version__ = '0.0.1'
__version__ = '0.0.2'
__license__ = 'MIT'
53 changes: 31 additions & 22 deletions jj_menu/jj_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# -*- coding:utf-8 -*-

from __future__ import unicode_literals, print_function

import argparse
import os
import sys
import locale
import curses
import _curses
import subprocess
import six

# 文字化け対応
locale.setlocale(locale.LC_ALL, '')

COLOR_ACTIVE = 1

result_filename = '/tmp/_jj_result'


class MenuFileNotFound(Exception):
pass
Expand Down Expand Up @@ -54,9 +54,6 @@ def import_menu_settings():

def get_menu():
def _get_menus():
"""
メニュー項目1つなら同じものに展開
"""
menus = getattr(import_menu_settings(), 'menu')
for m in menus:
if isinstance(m, str):
Expand Down Expand Up @@ -89,9 +86,10 @@ def window_addstr(window, y, x, message, color=None):


class Launcher(object):
def __init__(self, stdscr):
stdscr.refresh() # なにより先にまず1回リフレッシュ
def __init__(self, stdscr, result_file=None):
stdscr.refresh()
self.stdscr = stdscr
self.result_file = result_file
self.max_y, self.max_x = stdscr.getmaxyx()
self.pos_y = 0
self.menu = get_menu()
Expand Down Expand Up @@ -121,7 +119,7 @@ def render(self):

def debug(self, message):
"""
簡易デバッグ
Easy debug
"""
win = curses.newwin(1, 10, self.max_y - 2, self.max_x - 10)
window_addstr(win, 0, 0, message[:10])
Expand All @@ -132,7 +130,7 @@ def serve(self):

self.render()

# キー入力待機
# Waiting key input
c = self.stdscr.getch()

if c in (14, 106, 258): # ↓
Expand All @@ -151,32 +149,43 @@ def serve(self):
elif c in (113, 27): # Q, Esc
raise KeyboardInterrupt()
elif c == 10:
# 決定
with open(result_filename, 'w') as fp:
fp.write(self.menu[self.pos_y][1])
return self.menu[self.pos_y]
# choose
script = self.menu[self.pos_y][1]
if self.result_file:
with open(self.result_file, 'w') as fp:
fp.write(script)
return script
else:
self.debug('{}'.format(c))

def init_outfile(self):
with open(result_filename, 'w') as fp:
if not self.result_file:
return
with open(self.result_file, 'w') as fp:
fp.write('')


def launch(stdscr):
def launch(stdscr, args):
initialize_colors()
_curses.curs_set(0)
# 画面サイズ取得
launcher = Launcher(stdscr)
launcher = Launcher(stdscr, result_file=args.result_file)

selected = launcher.serve()
return selected
return launcher.serve()


def main():
parser = argparse.ArgumentParser(description='jj-menu core')
parser.add_argument('--result-file', dest='result_file',
help='result script file path', default=None)

args = parser.parse_args()

try:
selected = curses.wrapper(launch)
print('$ {}'.format(selected[1]))
script = curses.wrapper(launch, args)
print('$ {}'.format(script))
if not args.result_file:
print(subprocess.check_output(script, shell=True))

except KeyboardInterrupt:
exit(1)

Expand Down
13 changes: 11 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from setuptools import setup, find_packages
from jj_menu import __author__, __version__, __license__

install_requires=['curses', 'six']
# In [2]: from setuptools.command.bdist_egg import _get_purelib
#
# In [3]: _get_purelib()
# Out[3]: '/Users/yotsuyanagi/.virtualenvs/default/lib/python2.7/site-packages'
# $ cd $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"

setup(
name='jj-menu',
Expand All @@ -15,5 +19,10 @@
url='https://github.com/jytyng/jj-menu.git',
keywords='CLI Menu, Python',
packages=find_packages(),
install_requires=[],
install_requires=['six'],
entry_points={
'console_scripts': [
'jj-menu = jj_menu.jj_menu:main',
]
},
)

0 comments on commit 7665e92

Please sign in to comment.