From 3071ecd7f7153d6b564d1298c5821fc8bc49dae9 Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Sat, 26 Mar 2016 20:42:12 -0700 Subject: [PATCH] Add some completions for jekyll. --- dotfiles/zsh_custom/plugins/jekyll/_jekyll | 52 +++++++++++++++++++ .../plugins/jekyll/jekyll.plugin.zsh | 8 +++ 2 files changed, 60 insertions(+) create mode 100644 dotfiles/zsh_custom/plugins/jekyll/_jekyll diff --git a/dotfiles/zsh_custom/plugins/jekyll/_jekyll b/dotfiles/zsh_custom/plugins/jekyll/_jekyll new file mode 100644 index 0000000..c3758c1 --- /dev/null +++ b/dotfiles/zsh_custom/plugins/jekyll/_jekyll @@ -0,0 +1,52 @@ +#compdef jekyll + +_jekyll() { + local curcontext="${curcontext}" state line file + typeset -A opt_args + + local -a _subcommands + _subcommands=('docs:list documentation' + 'import:import posts' + 'serve:run server' + 'help:get help' + 'doctor:deprecation warnings' + 'build:compile site' + 'new:create new site' + 'clean:clean output' + 'draft:create new draft' + 'post:create new post' + 'publish:publish draft' + 'edit:edit post') + + _arguments -C \ + "(source)"{-s,--source}"[source]:source dir:_files -/" \ + "(dest)"{-d,--destination}"[dest]:dest dir:_files -/" \ + "--safe[safe mode]" \ + "(plugins)"{-p,--plugins}"[plugins]:plugins dir:_files -/" \ + "--layouts[layouts]:layouts dir:_files -/" \ + "--profile[generate liquid profile]" \ + "(help)"{-h,--help}"[help]" \ + "(version)"{-v,--version}"[version]" \ + "(trace)"{-t,--trace}"[trace]" \ + "1:command:->command" \ + "*: :->args" + + case $state in + command) + _describe -t commands "jekyll subcommand" _subcommands + ;; + args) + case "$line[1]" in + edit) + # TODO: Fix to get --source argument + local -a postpaths + postpaths=("${JEKYLL_DIR}/_posts" "${JEKYLL_DIR}/_drafts") + _files -W postpaths + ;; + publish) + # TODO: Fix to get --source argument + _files -W ${JEKYLL_DIR}/_drafts + esac + ;; + esac +} diff --git a/dotfiles/zsh_custom/plugins/jekyll/jekyll.plugin.zsh b/dotfiles/zsh_custom/plugins/jekyll/jekyll.plugin.zsh index d07773c..d6208f7 100644 --- a/dotfiles/zsh_custom/plugins/jekyll/jekyll.plugin.zsh +++ b/dotfiles/zsh_custom/plugins/jekyll/jekyll.plugin.zsh @@ -15,6 +15,14 @@ function _jekyll_find_post { printf "${1}" return 0 fi + if [ -f "${JEKYLL_DIR}/_posts/${1}" ] ; then + printf "${JEKYLL_DIR}/_posts/${1}" + return 0 + fi + if [ -f "${JEKYLL_DIR}/_drafts/${1}" ] ; then + printf "${JEKYLL_DIR}/_drafts/${1}" + return 0 + fi fname=${2:-${1}} files=(${JEKYLL_DIR}/_posts/*${fname}* ${JEKYLL_DIR}/_drafts/*${fname}*) if [ ${#files} -eq "0" ] ; then