fixes shellcheck errors
This commit is contained in:
parent
d62085770a
commit
b9769ee028
73
bb.sh
73
bb.sh
|
@ -46,8 +46,6 @@ global_variables() {
|
||||||
# Set this to false for a Twitter button with share count. The cookieless version
|
# Set this to false for a Twitter button with share count. The cookieless version
|
||||||
# is just a link.
|
# is just a link.
|
||||||
global_twitter_cookieless="true"
|
global_twitter_cookieless="true"
|
||||||
# Default search page, where tweets more than a week old are hidden
|
|
||||||
global_twitter_search="twitter"
|
|
||||||
|
|
||||||
# Blog generated files
|
# Blog generated files
|
||||||
# index page of blog (it is usually good to use "index.html" here)
|
# index page of blog (it is usually good to use "index.html" here)
|
||||||
|
@ -152,7 +150,7 @@ global_variables() {
|
||||||
|
|
||||||
# Markdown location. Trying to autodetect by default.
|
# Markdown location. Trying to autodetect by default.
|
||||||
# The invocation must support the signature 'markdown_bin in.md > out.html'
|
# The invocation must support the signature 'markdown_bin in.md > out.html'
|
||||||
[[ -f Markdown.pl ]] && markdown_bin=./Markdown.pl || markdown_bin=$(which Markdown.pl 2>/dev/null || which markdown 2>/dev/null)
|
[[ -f Markdown.pl ]] && markdown_bin=./Markdown.pl || markdown_bin=$(command -v Markdown.pl 2>/dev/null || command -v markdown 2>/dev/null)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for the validity of some variables
|
# Check for the validity of some variables
|
||||||
|
@ -169,11 +167,12 @@ global_variables_check() {
|
||||||
|
|
||||||
# Test if the markdown script is working correctly
|
# Test if the markdown script is working correctly
|
||||||
test_markdown() {
|
test_markdown() {
|
||||||
[[ -n $markdown_bin ]] &&
|
local m1; m1=$("$markdown_bin" <<< $'line 1\n\nline 2')
|
||||||
(
|
local m2; m2=$("$markdown_bin" <<< $'line 1\n\nline 2')
|
||||||
[[ $("$markdown_bin" <<< $'line 1\n\nline 2') == $'<p>line 1</p>\n\n<p>line 2</p>' ]] ||
|
local c1=$'<p>line 1</p>\n\n<p>line 2</p>'
|
||||||
[[ $("$markdown_bin" <<< $'line 1\n\nline 2') == $'<p>line 1</p>\n<p>line 2</p>' ]]
|
local c2=$'<p>line 1</p>\n<p>line 2</p>'
|
||||||
)
|
# shellcheck disable=SC2235 # must enforce order of operations
|
||||||
|
[[ -n $markdown_bin ]] && ( [[ "$m1" == "$c1" ]] || [[ "$m2" == "$c2" ]] )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -216,7 +215,8 @@ get_html_file_content() {
|
||||||
# "full" to edit full HTML, and not only text part (keeps old filename)
|
# "full" to edit full HTML, and not only text part (keeps old filename)
|
||||||
# leave empty for default behavior (edit only text part and change name)
|
# leave empty for default behavior (edit only text part and change name)
|
||||||
edit() {
|
edit() {
|
||||||
[[ ! -f "${1%%.*}.html" ]] && echo "Can't edit post "${1%%.*}.html", did you mean to use \"bb.sh post <draft_file>\"?" && exit -1
|
[[ ! -f "${1%%.*}.html" ]] && \
|
||||||
|
printf "Can't edit post \"%s.html\", did you mean to use \"bb.sh post <draft_file>\"?\\n" "${1%%.*}" && exit 1
|
||||||
# Original post timestamp
|
# Original post timestamp
|
||||||
edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_full" )
|
edit_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_full" )
|
||||||
touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_timestamp")
|
touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_timestamp")
|
||||||
|
@ -226,8 +226,7 @@ edit() {
|
||||||
filename=$1
|
filename=$1
|
||||||
else
|
else
|
||||||
if [[ ${1##*.} == md ]]; then
|
if [[ ${1##*.} == md ]]; then
|
||||||
test_markdown
|
if test_markdown; then
|
||||||
if (($? != 0)); then
|
|
||||||
echo "Markdown is not working, please edit HTML file directly."
|
echo "Markdown is not working, please edit HTML file directly."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
@ -260,7 +259,8 @@ edit() {
|
||||||
echo "Posted $filename"
|
echo "Posted $filename"
|
||||||
tags_after=$(tags_in_post "$filename")
|
tags_after=$(tags_in_post "$filename")
|
||||||
relevant_tags=$(echo "$tags_before $tags_after" | tr ',' ' ' | tr ' ' '\n' | sort -u | tr '\n' ' ')
|
relevant_tags=$(echo "$tags_before $tags_after" | tr ',' ' ' | tr ' ' '\n' | sort -u | tr '\n' ' ')
|
||||||
if [[ ! -z $relevant_tags ]]; then
|
if [[ -n $relevant_tags ]]; then
|
||||||
|
# shellcheck disable=SC2086 # Intended splitting of $relevant_tags
|
||||||
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
|
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
|
||||||
rebuild_tags "$relevant_posts" "$relevant_tags"
|
rebuild_tags "$relevant_posts" "$relevant_tags"
|
||||||
fi
|
fi
|
||||||
|
@ -324,7 +324,7 @@ is_boilerplate_file() {
|
||||||
done
|
done
|
||||||
|
|
||||||
case $name in
|
case $name in
|
||||||
( "$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$global_analytics_file" | "$prefix_tags"* )
|
( "$index_file" | "$archive_index" | "$gophermap" | "$gemini_index" | "$tags_index" | "$footer_file" | "$header_file" | "$prefix_tags"* )
|
||||||
return 0 ;;
|
return 0 ;;
|
||||||
( * ) # Check for excluded
|
( * ) # Check for excluded
|
||||||
for excl in "${html_exclude[@]}"; do
|
for excl in "${html_exclude[@]}"; do
|
||||||
|
@ -489,8 +489,7 @@ write_entry() {
|
||||||
[[ $2 == -html ]] && fmt=html
|
[[ $2 == -html ]] && fmt=html
|
||||||
# Test if Markdown is working before re-posting a .md file
|
# Test if Markdown is working before re-posting a .md file
|
||||||
if [[ $extension == md ]]; then
|
if [[ $extension == md ]]; then
|
||||||
test_markdown
|
if test_markdown; then
|
||||||
if (($? != 0)); then
|
|
||||||
echo "Markdown is not working, please edit HTML file directly."
|
echo "Markdown is not working, please edit HTML file directly."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
@ -560,6 +559,7 @@ EOF
|
||||||
echo "Posted $filename"
|
echo "Posted $filename"
|
||||||
relevant_tags=$(tags_in_post $filename)
|
relevant_tags=$(tags_in_post $filename)
|
||||||
if [[ -n $relevant_tags ]]; then
|
if [[ -n $relevant_tags ]]; then
|
||||||
|
# shellcheck disable=SC2086 # Intended splitting of $relevant_tags
|
||||||
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
|
relevant_posts="$(posts_with_tags $relevant_tags) $filename"
|
||||||
rebuild_tags "$relevant_posts" "$relevant_tags"
|
rebuild_tags "$relevant_posts" "$relevant_tags"
|
||||||
fi
|
fi
|
||||||
|
@ -616,6 +616,7 @@ all_tags() {
|
||||||
{
|
{
|
||||||
echo "<h3>$template_tags_title</h3>"
|
echo "<h3>$template_tags_title</h3>"
|
||||||
echo "<ul>"
|
echo "<ul>"
|
||||||
|
# shellcheck disable=SC2231 # Intended splitting of $prefix_tags
|
||||||
for i in $prefix_tags*.html; do
|
for i in $prefix_tags*.html; do
|
||||||
[[ -f "$i" ]] || break
|
[[ -f "$i" ]] || break
|
||||||
echo -n "." 1>&3
|
echo -n "." 1>&3
|
||||||
|
@ -711,7 +712,8 @@ rebuild_tags() {
|
||||||
all_tags=yes
|
all_tags=yes
|
||||||
else
|
else
|
||||||
# will process only given files and tags
|
# will process only given files and tags
|
||||||
files=$(printf '%s\n' $1 | sort -u)
|
files=$(printf '%s\n' "$1" | sort -u)
|
||||||
|
# shellcheck disable=SC2086 # Intended splitting of $files
|
||||||
files=$(ls -t $files)
|
files=$(ls -t $files)
|
||||||
tags=$2
|
tags=$2
|
||||||
fi
|
fi
|
||||||
|
@ -773,10 +775,12 @@ get_post_author() {
|
||||||
list_tags() {
|
list_tags() {
|
||||||
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi
|
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi
|
||||||
|
|
||||||
ls ./$prefix_tags*.html &> /dev/null
|
if ls ./$prefix_tags*.html > /dev/null; then
|
||||||
(($? != 0)) && echo "No posts yet. Use 'bb.sh post' to create one" && return
|
echo "No posts yet. Use 'bb.sh post' to create one" && return
|
||||||
|
fi
|
||||||
|
|
||||||
lines=""
|
lines=""
|
||||||
|
# shellcheck disable=SC2231 # Intended splitting of $prefix_tags
|
||||||
for i in $prefix_tags*.html; do
|
for i in $prefix_tags*.html; do
|
||||||
[[ -f "$i" ]] || break
|
[[ -f "$i" ]] || break
|
||||||
nposts=$(grep -c "<\!-- text begin -->" "$i")
|
nposts=$(grep -c "<\!-- text begin -->" "$i")
|
||||||
|
@ -796,8 +800,9 @@ list_tags() {
|
||||||
|
|
||||||
# Displays a list of the posts
|
# Displays a list of the posts
|
||||||
list_posts() {
|
list_posts() {
|
||||||
ls ./*.html &> /dev/null
|
if ls ./*.html > /dev/null; then
|
||||||
(($? != 0)) && echo "No posts yet. Use 'bb.sh post' to create one" && return
|
echo "No posts yet. Use 'bb.sh post' to create one" && return
|
||||||
|
fi
|
||||||
|
|
||||||
lines=""
|
lines=""
|
||||||
n=1
|
n=1
|
||||||
|
@ -864,7 +869,7 @@ make_gophermap() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "${HOME}/public_gopher/blog/$gophermap" ]; then
|
if [ ! -f "${HOME}/public_gopher/blog/$gophermap" ]; then
|
||||||
cat <<- 'EOF' > $HOME/public_html/blog/$gophermap
|
cat <<- 'EOF' > "${HOME}/public_html/blog/${gophermap}"
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
printf "my bashblog posts\n"
|
printf "my bashblog posts\n"
|
||||||
user=$(stat -c '%U' .)
|
user=$(stat -c '%U' .)
|
||||||
|
@ -873,9 +878,9 @@ make_gophermap() {
|
||||||
printf "0$post\t/~$user/blog/$post\ttilde.team\t70\n"
|
printf "0$post\t/~$user/blog/$post\ttilde.team\t70\n"
|
||||||
done
|
done
|
||||||
EOF
|
EOF
|
||||||
chmod +x $HOME/public_html/blog/$gophermap
|
chmod +x "${HOME}/public_html/blog/${gophermap}"
|
||||||
fi
|
fi
|
||||||
chmod 644 *.md
|
chmod 644 ./*.md
|
||||||
}
|
}
|
||||||
|
|
||||||
make_gemini() {
|
make_gemini() {
|
||||||
|
@ -889,7 +894,7 @@ make_gemini() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "${HOME}/public_gemini/blog/$gemini_index" ]; then
|
if [ ! -f "${HOME}/public_gemini/blog/$gemini_index" ]; then
|
||||||
cat <<- 'EOF' > $HOME/public_gemini/blog/$gemini_index
|
cat <<- 'EOF' > "${HOME}/public_gemini/blog/${gemini_index}"
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
printf "20 text/gemini\r\n"
|
printf "20 text/gemini\r\n"
|
||||||
printf "my bashblog posts\r\n"
|
printf "my bashblog posts\r\n"
|
||||||
|
@ -899,7 +904,7 @@ make_gemini() {
|
||||||
printf "=> /~$user/blog/$post $post\r\n"
|
printf "=> /~$user/blog/$post $post\r\n"
|
||||||
done
|
done
|
||||||
EOF
|
EOF
|
||||||
chmod +x ${HOME}/public_gemini/blog/$gemini_index
|
chmod +x "${HOME}/public_gemini/blog/${gemini_index}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,15 +1065,13 @@ reset() {
|
||||||
|
|
||||||
# Detects if GNU date is installed
|
# Detects if GNU date is installed
|
||||||
date_version_detect() {
|
date_version_detect() {
|
||||||
date --version >/dev/null 2>&1
|
if ! stat -c"%U" /dev/null >/dev/null 2>&1 ; then
|
||||||
if (($? != 0)); then
|
# BSD environment
|
||||||
# date utility is BSD. Test if gdate is installed
|
if command -v gdate >/dev/null 2>&1 ; then
|
||||||
if gdate --version >/dev/null 2>&1 ; then
|
|
||||||
date() {
|
date() {
|
||||||
gdate "$@"
|
gdate "$@"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# BSD date
|
|
||||||
date() {
|
date() {
|
||||||
if [[ $1 == -r ]]; then
|
if [[ $1 == -r ]]; then
|
||||||
# Fall back to using stat for 'date -r'
|
# Fall back to using stat for 'date -r'
|
||||||
|
@ -1083,7 +1086,7 @@ date_version_detect() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main function
|
# Main function
|
||||||
|
@ -1093,14 +1096,16 @@ date_version_detect() {
|
||||||
# $2 file name of a draft to continue editing (optional)
|
# $2 file name of a draft to continue editing (optional)
|
||||||
do_main() {
|
do_main() {
|
||||||
# make sure we're in the right directory
|
# make sure we're in the right directory
|
||||||
[ $(pwd) != $HOME/public_html/blog ] &&
|
[ "$(pwd)" != "$HOME/public_html/blog" ] &&
|
||||||
echo "you're not in your blog directory. moving you there now" && mkdir -p $HOME/public_html/blog && cd $HOME/public_html/blog
|
echo "you're not in your blog directory. moving you there now" && \
|
||||||
|
mkdir -p "$HOME/public_html/blog" && cd "$HOME/public_html/blog" || exit 1
|
||||||
|
|
||||||
# Detect if using BSD date or GNU date
|
# Detect if using BSD date or GNU date
|
||||||
date_version_detect
|
date_version_detect
|
||||||
# Load default configuration, then override settings with the config file
|
# Load default configuration, then override settings with the config file
|
||||||
global_variables
|
global_variables
|
||||||
[[ -f $global_config ]] && source "$global_config" &> /dev/null
|
# shellcheck disable=SC1090 # variable config file
|
||||||
|
[[ -f "$global_config" ]] && source "$global_config" &> /dev/null
|
||||||
global_variables_check
|
global_variables_check
|
||||||
|
|
||||||
# Check for $EDITOR
|
# Check for $EDITOR
|
||||||
|
|
Loading…
Reference in New Issue