mirror of
https://github.com/Matir/skel.git
synced 2026-05-26 13:35:42 -07:00
Fix up prezto.
This commit is contained in:
52
dotfiles/zprezto_custom/jekyll/functions/_jekyll
Normal file
52
dotfiles/zprezto_custom/jekyll/functions/_jekyll
Normal file
@@ -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
|
||||
}
|
||||
140
dotfiles/zprezto_custom/jekyll/init.zsh
Normal file
140
dotfiles/zprezto_custom/jekyll/init.zsh
Normal file
@@ -0,0 +1,140 @@
|
||||
function _jekyll_locate_dir {
|
||||
if [[ -n "${JEKYLL_DIR}" && -f "${JEKYLL_DIR}" ]] ; then
|
||||
echo ${JEKYLL_DIR}
|
||||
elif test -f `pwd`/_config.yml ; then
|
||||
pwd
|
||||
elif test -f ${HOME}/Projects/blog/_config.yml ; then
|
||||
echo ${HOME}/Projects/blog
|
||||
else
|
||||
echo "Jekyll instance not found!" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
function _jekyll_set_date {
|
||||
local FILENAME
|
||||
local DATE
|
||||
FILENAME=${1}
|
||||
DATE=${2}
|
||||
sed -i "2,/---/{s/^date:.*$/date: ${DATE}/;s/---/date: ${DATE}\n---/}" ${FILENAME}
|
||||
}
|
||||
|
||||
function _jekyll_find_post {
|
||||
local files
|
||||
local fname
|
||||
local jekyll_dir
|
||||
|
||||
jekyll_dir="${3}"
|
||||
|
||||
if [ -f "${1}" ] ; then
|
||||
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
|
||||
echo "No post found for ${fname}" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ ${#files} -gt "1" ] ; then
|
||||
echo "Ambiguous results: ${files}" >&2
|
||||
return 1
|
||||
fi
|
||||
printf -- ${files}
|
||||
return 0
|
||||
}
|
||||
|
||||
function jekyll {
|
||||
setopt localoptions nullglob
|
||||
local JTEMPLATE
|
||||
local TITLE
|
||||
local SLUG
|
||||
local FILENAME
|
||||
local DATE
|
||||
local NEWNAME
|
||||
local JEKYLL_DIR
|
||||
|
||||
JEKYLL_DIR=`_jekyll_locate_dir`
|
||||
|
||||
if [ -z "${JEKYLL_DIR}" ] ; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
JTEMPLATE="---\n"
|
||||
JTEMPLATE+="layout: post\n"
|
||||
JTEMPLATE+="title: \"%s\"\n"
|
||||
JTEMPLATE+="category: Blog\n"
|
||||
JTEMPLATE+="---\n\n"
|
||||
TITLE=${@[2,-1]}
|
||||
SLUG=$(echo -n ${TITLE}|tr A-Z a-z|tr -c -s -- a-z0-9 -)
|
||||
DATE=`date +%Y-%m-%d`
|
||||
|
||||
case "${1:-help}" in
|
||||
help|--help)
|
||||
command jekyll help
|
||||
echo "Added by zsh plugin:"
|
||||
echo " draft Create a new draft post."
|
||||
echo " post Create a new post to publish immediately."
|
||||
echo " publish Publish a draft post by name."
|
||||
echo " edit Edit a post."
|
||||
;;
|
||||
draft)
|
||||
if [ -z "${SLUG}" ] ; then
|
||||
echo "slug is required."
|
||||
return 1
|
||||
fi
|
||||
mkdir -p "${JEKYLL_DIR}/_drafts"
|
||||
FILENAME="${JEKYLL_DIR}/_drafts/${SLUG}.md"
|
||||
printf -- "${JTEMPLATE}" "${TITLE}" > "${FILENAME}"
|
||||
vim "${FILENAME}" '+$' '+startinsert'
|
||||
;;
|
||||
post)
|
||||
if [ -z "${SLUG}" ] ; then
|
||||
echo "slug is required."
|
||||
return 1
|
||||
fi
|
||||
FILENAME="${JEKYLL_DIR}/_posts/${DATE}-${SLUG}.md"
|
||||
printf -- "${JTEMPLATE}" "${TITLE}" > "${FILENAME}"
|
||||
_jekyll_set_date "${FILENAME}" "${DATE}"
|
||||
vim "${FILENAME}" '+$' '+startinsert'
|
||||
;;
|
||||
publish)
|
||||
if [ -z "${SLUG}" ] ; then
|
||||
echo "slug is required."
|
||||
return 1
|
||||
fi
|
||||
FILENAME=$(_jekyll_find_post "${TITLE}" "${SLUG}" "${JEKYLL_DIR}")
|
||||
if [ $? -ne 0 ] ; then
|
||||
return 1
|
||||
fi
|
||||
if ! [[ "${FILENAME}" =~ '/_drafts/' ]] ; then
|
||||
echo "${FILENAME} is not a draft." >&2
|
||||
return 1
|
||||
fi
|
||||
NEWNAME=$(echo "${FILENAME}" | sed "s/_drafts\//_posts\/${DATE}-/")
|
||||
mv "${FILENAME}" "${NEWNAME}"
|
||||
_jekyll_set_date "${NEWNAME}" "${DATE}"
|
||||
;;
|
||||
edit)
|
||||
if [ -z "${SLUG}" ] ; then
|
||||
echo "slug is required."
|
||||
return 1
|
||||
fi
|
||||
FILENAME=$(_jekyll_find_post "${TITLE}" "${SLUG}" "${JEKYLL_DIR}")
|
||||
if [ $? -ne 0 ] ; then
|
||||
return
|
||||
fi
|
||||
vim "${FILENAME}"
|
||||
;;
|
||||
*)
|
||||
command jekyll "$@"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
Reference in New Issue
Block a user