mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Reduce prezto deps.
This commit is contained in:
44
dotfiles/zshrc.d/gpg.zsh
Normal file
44
dotfiles/zshrc.d/gpg.zsh
Normal file
@@ -0,0 +1,44 @@
|
||||
if ! which gpg-agent >/dev/null 2>&1 ; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Set the default paths to gpg-agent files.
|
||||
_gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf"
|
||||
_gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID"
|
||||
|
||||
# Load environment variables from previous run
|
||||
source "$_gpg_agent_env" 2> /dev/null
|
||||
|
||||
# Start gpg-agent if not started.
|
||||
if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then
|
||||
# Start gpg-agent if not started.
|
||||
if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then
|
||||
eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Inform gpg-agent of the current TTY for user prompts.
|
||||
export GPG_TTY="$(tty)"
|
||||
|
||||
# Integrate with the SSH module.
|
||||
if grep '^enable-ssh-support' "$_gpg_agent_conf" &> /dev/null; then
|
||||
# Load required functions.
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
# Override the ssh-agent environment file default path.
|
||||
_ssh_agent_env="$_gpg_agent_env"
|
||||
|
||||
# Updates the GPG-Agent TTY before every command since SSH does not set it.
|
||||
function _gpg-agent-update-tty {
|
||||
gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null
|
||||
}
|
||||
add-zsh-hook preexec _gpg-agent-update-tty
|
||||
fi
|
||||
|
||||
# Clean up.
|
||||
unset _gpg_agent_{conf,env}
|
||||
|
||||
# Disable GUI prompts inside SSH.
|
||||
if [[ -n "$SSH_CONNECTION" ]]; then
|
||||
export PINENTRY_USER_DATA='USE_CURSES=1'
|
||||
fi
|
||||
150
dotfiles/zshrc.d/jekyll.zsh
Normal file
150
dotfiles/zshrc.d/jekyll.zsh
Normal file
@@ -0,0 +1,150 @@
|
||||
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
|
||||
local EDITOR=${EDITOR:-vim}
|
||||
|
||||
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 | # Everything in lower case
|
||||
tr -d "'" | # Remove single quotes entirely
|
||||
tr -c -s -- a-z0-9 - | # Replace non-alphanums with dashes
|
||||
sed 's/^-*\([^-].*[^-]\)-*$/\1/' # Remove leading and trailing slashes
|
||||
)
|
||||
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."
|
||||
echo " dev Run local server with drafts and incremental."
|
||||
;;
|
||||
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}"
|
||||
${EDITOR} "${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}"
|
||||
${EDITOR} "${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
|
||||
${EDITOR} "${FILENAME}"
|
||||
;;
|
||||
dev)
|
||||
command jekyll serve -D -I "$@"
|
||||
;;
|
||||
*)
|
||||
command jekyll "$@"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
function source_gnupg {
|
||||
GPG_ENV=${HOME}/.gnupg/gpg-agent.env
|
||||
if test -f ${GPG_ENV} ; then
|
||||
eval $(sed 's/^/export /' ${GPG_ENV})
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user