]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/blobdiff - xdg-ninja.sh
Normalize number of trailing newlines in markdown to 2 (#70)
[xdg-ninja.git] / xdg-ninja.sh
index 6c8a2f200daff1e819659bd4fc10206c8d2a6522..94a8969674fd020713e75807d5f389c37ff97f3e 100755 (executable)
@@ -98,8 +98,10 @@ check_if_file_exists() {
 }
 
 decode_string() {
-    printf "%s\n" "$1" | sed -e 's/\\n/\
-/g' -e 's/\\\"/\"/g' # Replace \n with literal newline and \" with "
+    printf "%s" "$1" | sed -e 's/\\n/\
+/g' -e 's/\\\"/\"/g' -e '$ s/\n*$/\
+\
+/' # Replace \n with literal newline and \" with ", normalize number of trailing newlines to 2
 }
 
 # Function to handle the formatting of output
@@ -129,9 +131,9 @@ log() {
         ;;
 
     HELP)
-        if $USE_GLOW; then
+        if [ "$USE_GLOW" = true ]; then
             decode_string "$HELP" | glow -
-        elif $USE_BAT; then
+        elif [ "$USE_BAT" = true ]; then
             decode_string "$HELP" | bat -pp --decorations=always --color=always --language markdown
         else
             decode_string "$HELP"
@@ -157,7 +159,7 @@ check_file() {
         ;;
 
     1)
-        if "$MOVABLE"; then
+        if [ "$MOVABLE" = true ]; then
             log ERR "$NAME" "$FILENAME" "$HELP"
         else
             log WARN "$NAME" "$FILENAME" "$HELP"