#compdef nb # _nb -- zsh completion functions for nano-blogger, # blog engine using bash and other GNU utilities # Copyleft (C) 2009 Adrian C. # There was no licensing information attached to the original file, # assuming it is public domain I am licensing this copy under the # terms of the GNU GPL: # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # author: Andy Spiegl # edited: Adrian C. # # 2006-06-16: first version # 2006-06-20: --category is respected now (thanks to Ulrich, spamt.net) # 2009-03-23: updated for nanoblogger-3.3 # TODO: (HELP!) # -c,-d,-e,-m accepts multiple ID numbers seperated by commas (e.g. 1,2,3) # --list and --update accepts regular expressions to match entries by date # ( date = YYYY-MM-DD, YYYY-MM, ^YYYY) # --delete accepts categories OR entries but currently only entries are completed local state categories entries ret=1 # find out user specified category integer catind=${words[(i)-c|--category]} if (( catind )); then cat=$words[catind+1] fi #echo -e "\n DEBUG: cat=$cat\n" # -S: no option will be completed after a `--' appearing on its own on the line _arguments -S \ '(--help -h *)'{--help,-h}'[show help message]' \ '(--version -V)'{--version,-V}'[display version information]' \ '--manual[view the manual]' \ '(--add -a)'{--add,-a}'[create new entry, category, or weblog]' \ '(--body -B)'{--body,-B}'[set body of entry (deprecated, use -T)]:body of entry:' \ '(--blogdir -b)'{--blogdir,-b}'[weblog directory]:blogdir:_path_files -/' \ '(--category -c)'{--category,-c}'[category (for add,delete,edit,list,update,update-cache)]:categories:->categories' \ '--cfgfile[alternate configuration file]:cfgfile:_path_files' \ '--configure[configure weblog (for update)]' \ '--datadir[weblogs data directory]:datadir:_path_files -/' \ '(--delete -d)'{--delete,-d}'[delete an entry or category ]:entries:->entries' \ '(--desc -D)'{--desc,-D}'[set text of description (for add,draft,makefile,makepage)]:text of description:' \ '(--edit -e)'{--edit,-e}'[edit entry or category ]:entries:->entries' \ '(--draft -E)'{--draft,-E}'[edit or create a metafile]:_path_files:_path_files' \ '(--file -f)'{--file,-f}'[metafile to import as entry (for add)]:_path_files:_path_files' \ '(--list -l)'{--list,-l}'[list entries or categories]:listtype:((all\:"all entries" cat\:"defined categories" current\:"current entries" DATE\:"e.g. YYYY-MM-DD, YYYY-MM, ^YYYY" max\:max))' \ '(--update -u)'{--update,-u}'[update of weblogs files]:updatetype:((all\:"all entries" current\:"current entries" DATE\:"e.g. YYYY-MM-DD, YYYY-MM, ^YYYY" main\:main))' \ '(--makepage -M)'{--makepage,-M}'[create new weblog page (file2) from metafile (file1)]:_path_files:_path_files' \ '--template[file to load as template (for draft,makepage,makefile)]:_path_files' \ '--templatedir[weblogs template directory]:_path_files -/' \ '(--move -m)'{--move,-m}'[move an entry to a specified category (for category)]:entries:->entries' \ '(--author -n)'{--author,-n}'[set text of author (for add,draft,makefile,makepage)]:text of author:' \ '(--title -t)'{--title,-t}'[set text of title (for add,category,draft,makefile,makepage)]:text of title' \ '(--text -T)'{--text,-T}'[set text of body (for add,draft,makefile,makepage)]:text of body:' \ '(--preview -p)'{--preview,-p}'[run command to preview weblog]' \ '(--publish -P)'{--publish,-P}'[run command to publish weblog]' \ '(--verbose -v)'{--verbose,-v}'[toggle level of verbosity]:verb:((1\:on 0\:off))' case $state in categories) categories=( ${${(M)${(f)"$(nb --list cat 2>/dev/null)"}:# *, *}/ (#b)(*[^ ]) #, (*)/$match[1]:$match[2]}) _describe -t categories "nanoblogger categories" categories && ret=0 ;; entries) if [[ -z $cat ]]; then entries=( ${${(M)${(f)"$(nb --list 2>/dev/null)"}:# *, *}/ (#b)(*[^ ]) #, (*)/$match[1]:$match[2]}) else entries=( ${${(M)${(f)"$(nb --category $cat --list 2>/dev/null)"}:# *, *}/ (#b)(*[^ ]) #, (*)/$match[1]:$match[2]}) fi _describe -t entries "nanoblogger entries" entries && ret=0 ;; esac