diff --git a/_cheat b/_cheat new file mode 100644 index 0000000..0ebec18 --- /dev/null +++ b/_cheat @@ -0,0 +1,12 @@ +#compdef cheat + +declare -a cheats cheats_in_this_dir + +for directory in $(cheat --cheat_directories); do + cheats_in_this_dir=($directory/*(N:r:t)) + [[ ${#cheats_in_this_dir} > 0 ]] && cheats+=($cheats_in_this_dir) +done + +_arguments "1:cheats:(${cheats})" + +return 1 diff --git a/cheat b/cheat index 22007a8..04ed89d 100755 --- a/cheat +++ b/cheat @@ -122,7 +122,11 @@ def main(): # create/edit option option = sys.argv[1].lower() - if option in ['-e', '--edit', '-c', '--create']: + if option in ['-e', '--edit', '-c', '--create', '-d', '--cheat_directories']: + # list cheat directories and exit + if option in ['-d', '--cheat_directories']: + print(' '.join(cheat_directories())) + exit() # make sure EDITOR environment variable is set and that at least 3 arguments # are given if 'EDITOR' not in os.environ: diff --git a/setup.py b/setup.py index da974cd..33a18d2 100644 --- a/setup.py +++ b/setup.py @@ -16,5 +16,6 @@ setup(name='cheat', packages=['cheatsheets'], package_data={'cheatsheets': [f for f in os.listdir('cheatsheets') if '.' not in f]}, - scripts=['cheat'] + scripts=['cheat'], + data_files=[('/usr/share/zsh/site-functions', ['_cheat'])] )