diff --git a/bash_it.sh b/bash_it.sh
index de655e81..bda3407e 100755
--- a/bash_it.sh
+++ b/bash_it.sh
@@ -137,13 +137,6 @@ elif [ -s /Applications/Preview.app ]; then
PREVIEW="/Applications/Preview.app"
fi
-# Load all the Jekyll stuff
-
-if [ -e "$HOME/.jekyllconfig" ]; then
- # shellcheck disable=SC1090
- . "$HOME/.jekyllconfig"
-fi
-
# BASH_IT_RELOAD_LEGACY is set.
if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
case $OSTYPE in
diff --git a/clean_files.txt b/clean_files.txt
index 53765a5f..0e6c39f5 100644
--- a/clean_files.txt
+++ b/clean_files.txt
@@ -97,6 +97,7 @@ plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash
+plugins/available/jekyll.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/node.plugin.bash
diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash
index c340c432..d818b076 100644
--- a/plugins/available/jekyll.plugin.bash
+++ b/plugins/available/jekyll.plugin.bash
@@ -1,367 +1,288 @@
+# shellcheck shell=bash
cite about-plugin
about-plugin 'manage your jekyll site'
-editpost() {
- about 'edit a post'
- param '1: site directory'
- group 'jekyll'
+function editpost() {
+ about 'edit a post'
+ param '1: site directory'
+ group 'jekyll'
- unset SITE
- if [ -z "$1" ]
- then
- echo "Error: no site specified."
- echo "The site is the name of the directory your project is in."
- return 1
- fi
+ local SITE site POST DATE TITLE POSTS
+ local -i COUNTER=1 POST_TO_EDIT ret
+ if [[ -z "${1:-}" ]]; then
+ echo "Error: no site specified."
+ echo "The site is the name of the directory your project is in."
+ return 1
+ fi
- for site in ${SITES[@]}
- do
- if [ "${site##*/}" = "$1" ]
- then
- SITE=$site
- break
- fi
- done
+ for site in "${SITES[@]:-}"; do
+ if [[ "${site##*/}" == "$1" ]]; then
+ SITE="${site}"
+ break
+ fi
+ done
- if [ -z "$SITE" ]
- then
- echo "No such site."
- return 1
- fi
+ if [[ -z "${SITE:-}" ]]; then
+ echo "No such site."
+ return 1
+ fi
- builtin cd "$SITE/_posts"
+ pushd "${SITE}/_posts" > /dev/null || return
- COUNTER=1
- NUMBER="$RANDOM"
- TMPFILE="/tmp/editpost-$NUMBER"
-
- for POST in *
- do
- DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"`
- TITLE=`cat $POST | grep -oE "title: (.+)"`
- TITLE=`echo $TITLE | sed 's/title: //'`
- echo "$COUNTER) $DATE $TITLE" >> "$TMPFILE"
- POSTS[$COUNTER]=$POST
- COUNTER=`expr $COUNTER + 1`
- done
- less $TMPFILE
- read -p "Number of post to edit: " POST_TO_EDIT
- if [ -z "$JEKYLL_EDITOR" ]
- then
- nano "${POSTS[$POST_TO_EDIT]}"
- else
- "$JEKYLL_EDITOR" "${POSTS[$POST_TO_EDIT]}"
- fi
+ for POST in *; do
+ DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
+ TITLE="$(grep -oE "title: (.+)" < "${POST}")"
+ TITLE="${TITLE/title: /}"
+ echo "${COUNTER}) ${DATE} ${TITLE}"
+ POSTS[COUNTER]="$POST"
+ COUNTER="$((COUNTER + 1))"
+ done > >(less)
+ read -rp "Number of post to edit: " POST_TO_EDIT
+ "${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
+ ret="$?"
+ popd > /dev/null || return "$ret"
+ return "$ret"
}
-newpost() {
- about 'create a new post'
- param '1: site directory'
- group 'jekyll'
+function newpost() {
+ about 'create a new post'
+ param '1: site directory'
+ group 'jekyll'
- unset SITE
- if [ -z "$1" ]
- then
- echo "Error: no site specified."
- echo "The site is the name of the directory your project is in."
- return 1
- fi
+ local SITE site FNAME_POST_TITLE FNAME YAML_DATE
+ local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
+ local -i loc=0 ret
+ if [[ -z "${1:-}" ]]; then
+ echo "Error: no site specified."
+ echo "The site is the name of the directory your project is in."
+ return 1
+ fi
- if [ -z "$SITE" ]
- then
- echo "No such site."
- return 1
- fi
+ if [[ -z "${SITE}" ]]; then
+ echo "No such site."
+ return 1
+ fi
- loc=0
+ for site in "${SITES[@]}"; do
+ if [[ "${site##*/}" == "$1" ]]; then
+ SITE="$site"
+ JEKYLL_FORMATTING="${MARKUPS[loc]}"
+ break
+ fi
+ loc=$((loc + 1))
+ done
- for site in ${SITES[@]}
- do
- if [ "${site##*/}" = "$1" ]
- then
- SITE=$site
- JEKYLL_FORMATTING=${MARKUPS[$loc]}
- break
- fi
- loc=$(($loc+1))
- done
+ # Change directory into the local jekyll root
+ pushd "${SITE}/_posts" > /dev/null || return
- # 'builtin cd' into the local jekyll root
+ # Get the date for the new post's filename
+ FNAME_DATE="$(date "+%Y-%m-%d")"
- builtin cd "$SITE/_posts"
+ # If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
+ OPTIONS=('Text' 'Quote' 'Image' 'Audio' 'Video' 'Link')
- # Get the date for the new post's filename
+ if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
+ select OPTION in "${OPTIONS[@]}"; do
+ POST_TYPE="${OPTION}"
+ break
+ done
+ fi
- FNAME_DATE=$(date "+%Y-%m-%d")
+ # Get the title for the new post
+ read -rp "Enter title of the new post: " POST_TITLE
- # If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
+ # Convert the spaces in the title to hyphens for use in the filename
+ FNAME_POST_TITLE="${POST_TITLE/ /-}"
- OPTIONS="Text Quote Image Audio Video Link"
+ # Now, put it all together for the full filename
+ FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
- if [ $JEKYLL_FORMATTING = "markdown" -o $JEKYLL_FORMATTING = "textile" ]
- then
- select OPTION in $OPTIONS
- do
- if [[ $OPTION = "Text" ]]
- then
- POST_TYPE="Text"
- break
- fi
+ # And, finally, create the actual post file. But we're not done yet...
+ {
+ # Write a little stuff to the file for the YAML Front Matter
+ echo "---"
- if [[ $OPTION = "Quote" ]]
- then
- POST_TYPE="Quote"
- break
- fi
+ # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of the file
+ YAML_DATE="$(date "+%B %d %Y %X")"
- if [[ $OPTION = "Image" ]]
- then
- POST_TYPE="Image"
- break
- fi
+ # Echo the YAML Formatted date to the post file
+ echo "date: $YAML_DATE"
- if [[ $OPTION = "Audio" ]]
- then
- POST_TYPE="Audio"
- break
- fi
+ # Echo the original post title to the YAML Front Matter header
+ echo "title: $POST_TITLE"
- if [[ $OPTION = "Video" ]]
- then
- POST_TYPE="Video"
- break
- fi
+ # And, now, echo the "post" layout to the YAML Front Matter header
+ echo "layout: post"
- if [[ $OPTION = "Link" ]]
- then
- POST_TYPE="Link"
- break
- fi
- done
- fi
+ # Close the YAML Front Matter Header
+ echo "---"
- # Get the title for the new post
+ echo
+ } > "${FNAME}"
- read -p "Enter title of the new post: " POST_TITLE
+ # Generate template text based on the post type
+ if [[ $JEKYLL_FORMATTING == "markdown" ]]; then
+ case $POST_TYPE in
+ "Text")
+ true
+ ;;
+ "Quote")
+ echo "> Quote"
+ echo
+ echo "— Author"
+ ;;
+ "Image")
+ echo ""
+ ;;
+ "Audio")
+ echo ""
+ ;;
+ "Video")
+ echo ""
+ ;;
+ "Link")
+ echo "[link][1]"
+ echo
+ echo "> Quote"
+ echo
+ echo "[1]: url"
+ ;;
+ esac
+ elif [[ $JEKYLL_FORMATTING == "textile" ]]; then
+ case $POST_TYPE in
+ "Text")
+ true
+ ;;
+ "Quote")
+ echo "bq. Quote"
+ echo
+ echo "— Author"
+ ;;
+ "Image")
+ echo "!url(alt text)"
+ ;;
+ "Audio")
+ echo ""
+ ;;
+ "Video")
+ echo ""
+ ;;
+ "Link")
+ echo "\"Site\":url"
+ echo
+ echo "bq. Quote"
+ ;;
+ esac
+ fi >> "${FNAME}"
- # Convert the spaces in the title to hyphens for use in the filename
-
- FNAME_POST_TITLE=`echo $POST_TITLE | tr ' ' "-"`
-
- # Now, put it all together for the full filename
-
- FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
-
- # And, finally, create the actual post file. But we're not done yet...
-
- touch "$FNAME"
-
- # Write a little stuff to the file for the YAML Front Matter
-
- echo "---" >> $FNAME
-
- # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of
- # the file
-
- YAML_DATE=$(date "+%B %d %Y %X")
-
- # Echo the YAML Formatted date to the post file
-
- echo "date: $YAML_DATE" >> $FNAME
-
- # Echo the original post title to the YAML Front Matter header
-
- echo "title: $POST_TITLE" >> $FNAME
-
- # And, now, echo the "post" layout to the YAML Front Matter header
-
- echo "layout: post" >> $FNAME
-
- # Close the YAML Front Matter Header
-
- echo "---" >> $FNAME
- echo >> $FNAME
-
- # Generate template text based on the post type
-
- if [[ $JEKYLL_FORMATTING = "markdown" ]]
- then
- if [[ $POST_TYPE = "Text" ]]
- then
- true
- fi
-
- if [[ $POST_TYPE = "Quote" ]]
- then
- echo "> Quote" >> $FNAME
- echo >> $FNAME
- echo "— Author" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Image" ]]
- then
- echo "" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Audio" ]]
- then
- echo "" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Video" ]]
- then
- echo "" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Link" ]]
- then
- echo "[link][1]" >> $FNAME
- echo >> $FNAME
- echo "> Quote" >> $FNAME
- echo >> $FNAME
- echo "[1]: url" >> $FNAME
- fi
- fi
-
- if [[ $JEKYLL_FORMATTING = "textile" ]]
- then
- if [[ $POST_TYPE = "Text" ]]
- then
- true
- fi
-
- if [[ $POST_TYPE = "Quote" ]]
- then
- echo "bq. Quote" >> $FNAME
- echo >> $FNAME
- echo "— Author" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Image" ]]
- then
- echo "!url(alt text)" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Audio" ]]
- then
- echo "" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Video" ]]
- then
- echo "" >> $FNAME
- fi
-
- if [[ $POST_TYPE = "Link" ]]
- then
- echo "\"Site\":url" >> $FNAME
- echo >> $FNAME
- echo "bq. Quote" >> $FNAME
- fi
- fi
-
- # Open the file in your favorite editor
-
- "$JEKYLL_EDITOR" $FNAME
+ # Open the file in your favorite editor
+ "${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
+ ret="$?"
+ popd > /dev/null || return "$ret"
+ return "$ret"
}
function testsite() {
- about 'launches local jekyll server'
- param '1: site directory'
- group 'jekyll'
+ about 'launches local jekyll server'
+ param '1: site directory'
+ group 'jekyll'
- unset SITE
- if [ -z "$1" ]
- then
- echo "Error: no site specified."
- echo "The site is the name of the directory your project is in."
- return 1
- fi
+ local SITE site
+ local -i ret
+ if [[ -z "${1:-}" ]]; then
+ echo "Error: no site specified."
+ echo "The site is the name of the directory your project is in."
+ return 1
+ fi
- for site in ${SITES[@]}
- do
- if [ "${site##*/}" = "$1" ]
- then
- SITE=$site
- break
- fi
- done
+ for site in "${SITES[@]}"; do
+ if [[ "${site##*/}" == "$1" ]]; then
+ SITE="$site"
+ break
+ fi
+ done
- if [ -z "$SITE" ]
- then
- echo "No such site."
- return 1
- fi
+ if [[ -z "${SITE}" ]]; then
+ echo "No such site."
+ return 1
+ fi
- builtin cd $SITE
- jekyll --server --auto
+ pushd "${SITE}" > /dev/null || return
+ jekyll --server --auto
+ ret="$?"
+ popd > /dev/null || return "$ret"
+ return "$ret"
}
function buildsite() {
- about 'builds site'
- param '1: site directory'
- group 'jekyll'
+ about 'builds site'
+ param '1: site directory'
+ group 'jekyll'
- unset SITE
- if [ -z "$1" ]
- then
- echo "Error: no site specified."
- echo "The site is the name of the directory your project is in."
- return 1
- fi
+ local SITE site
+ local -i ret
+ if [[ -z "${1:-}" ]]; then
+ echo "Error: no site specified."
+ echo "The site is the name of the directory your project is in."
+ return 1
+ fi
- for site in ${SITES[@]}
- do
- if [ "${site##*/}" = "$1" ]
- then
- SITE=$site
- break
- fi
- done
+ for site in "${SITES[@]}"; do
+ if [[ "${site##*/}" == "$1" ]]; then
+ SITE="$site"
+ break
+ fi
+ done
- if [ -z "$SITE" ]
- then
- echo "No such site."
- return 1
- fi
+ if [[ -z "${SITE}" ]]; then
+ echo "No such site."
+ return 1
+ fi
- builtin cd $SITE
- rm -rf _site
- jekyll --no-server
+ pushd "${SITE}" > /dev/null || return
+ rm -rf _site
+ jekyll --no-server
+ ret="$?"
+ popd > /dev/null || return "$ret"
+ return "$ret"
}
function deploysite() {
- about 'rsyncs site to remote host'
- param '1: site directory'
- group 'jekyll'
+ about 'rsyncs site to remote host'
+ param '1: site directory'
+ group 'jekyll'
- unset SITE
- if [ -z "$1" ]
- then
- echo "Error: no site specified."
- echo "The site is the name of the directory your project is in."
- return 1
- fi
+ local SITE site REMOTE
+ local -i loc=0 ret
+ if [[ -z "${1:-}" ]]; then
+ echo "Error: no site specified."
+ echo "The site is the name of the directory your project is in."
+ return 1
+ fi
- loc=0
+ for site in "${SITES[@]}"; do
+ if [[ "${site##*/}" == "$1" ]]; then
+ SITE="$site"
+ # shellcheck disable=SC2153 # who knows
+ REMOTE="${REMOTES[loc]}"
+ break
+ fi
+ loc=$((loc + 1))
+ done
- for site in ${SITES[@]}
- do
- if [ "${site##*/}" = "$1" ]
- then
- SITE=$site
- REMOTE=${REMOTES[$loc]}
- break
- fi
- loc=$(($loc+1))
- done
+ if [[ -z "${SITE}" ]]; then
+ echo "No such site."
+ return 1
+ fi
- if [ -z "$SITE" ]
- then
- echo "No such site."
- return 1
- fi
-
- builtin cd $SITE
- rsync -rz $REMOTE
+ pushd "${SITE}" > /dev/null || return
+ rsync -rz "${REMOTE?}"
+ ret="$?"
+ popd > /dev/null || return "$ret"
+ return "$ret"
}
+
+# Load the Jekyll config
+if [[ -s "$HOME/.jekyllconfig" ]]; then
+ source "$HOME/.jekyllconfig"
+fi