plugin/jekyll: second `shellcheck` pass

pull/1969/head
John D Pell 2021-10-10 00:44:21 -07:00
parent c0aad51afd
commit e38eeefc5f
2 changed files with 56 additions and 64 deletions

View File

@ -97,6 +97,7 @@ plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash plugins/available/hub.plugin.bash
plugins/available/jekyll.plugin.bash
plugins/available/jump.plugin.bash plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash plugins/available/less-pretty-cat.plugin.bash
plugins/available/node.plugin.bash plugins/available/node.plugin.bash

View File

@ -7,8 +7,8 @@ function editpost() {
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
local SITE site POST DATE TITLE POSTS TMPFILE POST_TO_EDIT local SITE site POST DATE TITLE POSTS
local -i COUNTER local -i COUNTER=1 POST_TO_EDIT
if [[ -z "${1:-}" ]]; then if [[ -z "${1:-}" ]]; then
echo "Error: no site specified." echo "Error: no site specified."
echo "The site is the name of the directory your project is in." echo "The site is the name of the directory your project is in."
@ -29,20 +29,16 @@ function editpost() {
builtin cd "${SITE}/_posts" || return builtin cd "${SITE}/_posts" || return
COUNTER=1
TMPFILE="/tmp/editpost-$RANDOM"
for POST in *; do for POST in *; do
DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")" DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
TITLE="$(grep -oE "title: (.+)" < "${POST}")" TITLE="$(grep -oE "title: (.+)" < "${POST}")"
TITLE="${TITLE/title: /}" TITLE="${TITLE/title: /}"
echo "${COUNTER}) ${DATE} ${TITLE}" >> "${TMPFILE}" echo "${COUNTER}) ${DATE} ${TITLE}"
POSTS[COUNTER]="$POST" POSTS[COUNTER]="$POST"
COUNTER="$((COUNTER + 1))" COUNTER="$((COUNTER + 1))"
done done | less
less "${TMPFILE}"
read -rp "Number of post to edit: " POST_TO_EDIT read -rp "Number of post to edit: " POST_TO_EDIT
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[$POST_TO_EDIT]}" "${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
} }
function newpost() { function newpost() {
@ -52,23 +48,22 @@ function newpost() {
local SITE site FNAME_POST_TITLE FNAME YAML_DATE local SITE site FNAME_POST_TITLE FNAME YAML_DATE
local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
if [ -z "$1" ]; then local -i loc=0
if [[ -z "${1:-}" ]]; then
echo "Error: no site specified." echo "Error: no site specified."
echo "The site is the name of the directory your project is in." echo "The site is the name of the directory your project is in."
return 1 return 1
fi fi
if [ -z "$SITE" ]; then if [[ -z "${SITE}" ]]; then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
loc=0
for site in "${SITES[@]}"; do for site in "${SITES[@]}"; do
if [ "${site##*/}" = "$1" ]; then if [[ "${site##*/}" == "$1" ]]; then
SITE=$site SITE="$site"
JEKYLL_FORMATTING=${MARKUPS[$loc]} JEKYLL_FORMATTING="${MARKUPS[loc]}"
break break
fi fi
loc=$((loc + 1)) loc=$((loc + 1))
@ -88,32 +83,32 @@ function newpost() {
if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
select OPTION in "${OPTIONS[@]}"; do select OPTION in "${OPTIONS[@]}"; do
if [[ $OPTION = "Text" ]]; then if [[ $OPTION == "Text" ]]; then
POST_TYPE="Text" POST_TYPE="Text"
break break
fi fi
if [[ $OPTION = "Quote" ]]; then if [[ $OPTION == "Quote" ]]; then
POST_TYPE="Quote" POST_TYPE="Quote"
break break
fi fi
if [[ $OPTION = "Image" ]]; then if [[ $OPTION == "Image" ]]; then
POST_TYPE="Image" POST_TYPE="Image"
break break
fi fi
if [[ $OPTION = "Audio" ]]; then if [[ $OPTION == "Audio" ]]; then
POST_TYPE="Audio" POST_TYPE="Audio"
break break
fi fi
if [[ $OPTION = "Video" ]]; then if [[ $OPTION == "Video" ]]; then
POST_TYPE="Video" POST_TYPE="Video"
break break
fi fi
if [[ $OPTION = "Link" ]]; then if [[ $OPTION == "Link" ]]; then
POST_TYPE="Link" POST_TYPE="Link"
break break
fi fi
@ -133,31 +128,27 @@ function newpost() {
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING" FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
# And, finally, create the actual post file. But we're not done yet... # 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 # Write a little stuff to the file for the YAML Front Matter
echo "---"
echo "---" >> "${FNAME}" # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of the file
# 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")" YAML_DATE="$(date "+%B %d %Y %X")"
# Echo the YAML Formatted date to the post file # Echo the YAML Formatted date to the post file
echo "date: $YAML_DATE"
echo "date: $YAML_DATE" >> "${FNAME}"
# Echo the original post title to the YAML Front Matter header # Echo the original post title to the YAML Front Matter header
echo "title: $POST_TITLE"
echo "title: $POST_TITLE" >> "${FNAME}"
# And, now, echo the "post" layout to the YAML Front Matter header # And, now, echo the "post" layout to the YAML Front Matter header
echo "layout: post"
echo "layout: post" >> "${FNAME}"
# Close the YAML Front Matter Header # Close the YAML Front Matter Header
echo "---"
echo "---" >> "${FNAME}" echo
echo >> "${FNAME}" } > "${FNAME}"
# Generate template text based on the post type # Generate template text based on the post type
@ -167,31 +158,31 @@ function newpost() {
fi fi
if [[ $POST_TYPE == "Quote" ]]; then if [[ $POST_TYPE == "Quote" ]]; then
echo "> Quote" >> "${FNAME}" echo "> Quote"
echo >> "${FNAME}" echo
echo "&mdash; Author" >> "${FNAME}" echo "&mdash; Author"
fi fi
if [[ $POST_TYPE == "Image" ]]; then if [[ $POST_TYPE == "Image" ]]; then
echo "![Alternate Text](/path/to/image/or/url)" >> "${FNAME}" echo "![Alternate Text](/path/to/image/or/url)"
fi fi
if [[ $POST_TYPE == "Audio" ]]; then if [[ $POST_TYPE == "Audio" ]]; then
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> "${FNAME}" echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
fi fi
if [[ $POST_TYPE == "Video" ]]; then if [[ $POST_TYPE == "Video" ]]; then
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> "${FNAME}" echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
fi fi
if [[ $POST_TYPE == "Link" ]]; then if [[ $POST_TYPE == "Link" ]]; then
echo "[link][1]" >> "${FNAME}" echo "[link][1]"
echo >> "${FNAME}" echo
echo "> Quote" >> "${FNAME}" echo "> Quote"
echo >> "${FNAME}" echo
echo "[1]: url" >> "${FNAME}" echo "[1]: url"
fi
fi fi
fi >> "${FNAME}"
if [[ $JEKYLL_FORMATTING == "textile" ]]; then if [[ $JEKYLL_FORMATTING == "textile" ]]; then
if [[ $POST_TYPE == "Text" ]]; then if [[ $POST_TYPE == "Text" ]]; then
@ -199,29 +190,29 @@ function newpost() {
fi fi
if [[ $POST_TYPE == "Quote" ]]; then if [[ $POST_TYPE == "Quote" ]]; then
echo "bq. Quote" >> "${FNAME}" echo "bq. Quote"
echo >> "${FNAME}" echo
echo "&mdash; Author" >> "${FNAME}" echo "&mdash; Author"
fi fi
if [[ $POST_TYPE == "Image" ]]; then if [[ $POST_TYPE == "Image" ]]; then
echo "!url(alt text)" >> "${FNAME}" echo "!url(alt text)"
fi fi
if [[ $POST_TYPE == "Audio" ]]; then if [[ $POST_TYPE == "Audio" ]]; then
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> "${FNAME}" echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
fi fi
if [[ $POST_TYPE == "Video" ]]; then if [[ $POST_TYPE == "Video" ]]; then
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> "${FNAME}" echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
fi fi
if [[ $POST_TYPE == "Link" ]]; then if [[ $POST_TYPE == "Link" ]]; then
echo "\"Site\":url" >> "${FNAME}" echo "\"Site\":url"
echo >> "${FNAME}" echo
echo "bq. Quote" >> "${FNAME}" echo "bq. Quote"
fi
fi fi
fi >> "${FNAME}"
# Open the file in your favorite editor # Open the file in your favorite editor
@ -299,7 +290,7 @@ function deploysite() {
fi fi
for site in "${SITES[@]}"; do for site in "${SITES[@]}"; do
if [ "${site##*/}" == "$1" ]; then if [[ "${site##*/}" == "$1" ]]; then
SITE="$site" SITE="$site"
REMOTE="${REMOTES[loc]}" REMOTE="${REMOTES[loc]}"
break break