Skip to content

Commit

Permalink
Moved completion, refactored full_install in setup.py, fixed MANIFEST.in
Browse files Browse the repository at this point in the history
  • Loading branch information
pblocz committed Dec 28, 2014
1 parent 0353f09 commit 89adef8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include README.MD requirements.txt
exclude *.orig *.pyc
include README.md requirements.txt MANIFEST.in
include completion/zsh_completion/_geeknote completion/bash_completion/_geeknote
exclude *.orig *.pyc
15 changes: 15 additions & 0 deletions completion/bash_completion/_geeknote
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_geeknote_command()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"

SAVE_IFS=$IFS
IFS=" "
args="${COMP_WORDS[*]:1}"
IFS=$SAVE_IFS

COMPREPLY=( $(compgen -W "`geeknote autocomplete ${args}`" -- ${cur}) )

return 0
}
complete -F _geeknote_command geeknote
File renamed without changes.
56 changes: 22 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,51 @@
from __future__ import with_statement
import sys
import os
import shutil
import getpass
import codecs
import geeknote
from setuptools import setup
from setuptools.command.install import install


BASH_COMPLETION = '''
_geeknote_command()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
SAVE_IFS=$IFS
IFS=" "
args="${COMP_WORDS[*]:1}"
IFS=$SAVE_IFS
COMPREPLY=( $(compgen -W "`geeknote autocomplete ${args}`" -- ${cur}) )
return 0
}
complete -F _geeknote_command geeknote
'''

def read(fname):
return codecs.open(os.path.join(os.path.dirname(__file__), fname)).read()

class full_install(install):

user_options = install.user_options + [
('userhome', None, "(Linux only) Set user home directory for"
" bash completion (/home/{0})"
.format(getpass.getuser()))
('bash-completion-dir', None,
"(Linux only) Set bash completion directory (default: /etc/bash_completion.d)"
),
('zsh-completion-dir', None,
"(Linux only) Set zsh completion directory (default: /usr/local/share/zsh/site-functions)"
)
]

def initialize_options(self):
install.initialize_options(self)
self.userhome = ''
self.bash_completion_dir = '/etc/bash_completion.d'
self.zsh_completion_dir = '/usr/local/share/zsh/site-functions'

def run(self):
if sys.platform == 'linux2':
self.install_autocomplite()
if sys.platform.startswith('linux'):
self.install_autocomplete()
install.run(self)

def install_autocomplite(self):
if self.userhome:
self.userhome = '{0}/.bash_completion'.format(self.userhome)
else:
self.userhome = '/home/{0}/.bash_completion'.format(os.getlogin())
def install_autocomplete(self):
def copy_autocomplete(src,dst):
if os.path.exists(dst):
shutil.copy(src,dst)
print('copying %s -> %s' % (src,dst))


print "installing autocomplete"
copy_autocomplete('completion/bash_completion/_geeknote',self.bash_completion_dir)
copy_autocomplete('completion/zsh_completion/_geeknote',self.zsh_completion_dir)



if not os.path.exists(self.userhome) or \
not BASH_COMPLETION in open(self.userhome, 'r').read():
with open(self.userhome, 'a') as completion:
print('Autocomplete was written to {0}'.format(self.userhome))
completion.write(BASH_COMPLETION)


setup(
Expand Down

0 comments on commit 89adef8

Please sign in to comment.