]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/blobdiff - xdg-ninja.sh
add an unsupported status for gitmoji-cli (#161)
[xdg-ninja.git] / xdg-ninja.sh
index 4783223bea8b119d7b2c2a4d2125538c3898eb63..ed0e8ddda2766f13de74dc9e4fe1dc00618d5db0 100755 (executable)
@@ -5,28 +5,27 @@ has_command() {
     return $?
 }
 
-USE_GLOW=false
-USE_BAT=false
-USE_PYGMENTIZE=false
-USE_HIGHLIGHT=false
-if has_command glow; then
-    USE_GLOW=true
-else
-    if has_command bat; then
-        USE_BAT=true
+auto_set_decoder() {
+    DECODER="cat"
+    if has_command glow; then
+        DECODER="glow -"
+    elif has_command batcat; then
+        DECODER="batcat -pp --decorations=always --color=always --language markdown"
+        printf "Markdown rendering will be done by bat. (Glow is recommended)\n"
+    elif has_command bat; then
+        DECODER="bat -pp --decorations=always --color=always --language markdown"
         printf "Markdown rendering will be done by bat. (Glow is recommended)\n"
     elif has_command pygmentize; then
+        DECODER="pygmentize -l markdown"
         printf "Markdown rendering will be done by pygmentize. (Glow is recommended)\n"
-        USE_PYGMENTIZE=true
     elif has_command highlight; then
+        DECODER="highlight --out-format ansi --syntax markdown"
         printf "Markdown rendering will be done by highlight. (Glow is recommended)\n"
-        USE_HIGHLIGHT=true
     else
-        printf "Markdown rendering not available. (Glow is recommended)\n"
-        printf "Output will be raw markdown and might look weird.\n"
+        printf "Install glow for easier reading & copy-paste.\n"
     fi
-    printf "Install glow for easier reading & copy-paste.\n"
-fi
+}
+auto_set_decoder
 
 unalias -a
 
@@ -164,18 +163,7 @@ log() {
         ;;
 
     HELP)
-        if [ "$USE_GLOW" = true ]; then
-            decode_string "$HELP" | glow -
-        elif [ "$USE_BAT" = true ]; then
-            decode_string "$HELP" | bat -pp --decorations=always --color=always --language markdown
-        elif [ $USE_PYGMENTIZE = true ]; then
-            decode_string "$HELP" | pygmentize -l markdown
-            printf "\n"
-        elif [ $USE_HIGHLIGHT = true ]; then
-            decode_string "$HELP" | highlight --out-format ansi --syntax markdown
-        else
-            decode_string "$HELP"
-        fi
+        decode_string "$HELP" | PAGER="cat" $DECODER
         ;;
 
     esac
@@ -218,7 +206,7 @@ do_check_programs() {
 " read -r name; read -r filename; read -r movable; read -r help; do
         check_file "$name" "$filename" "$movable" "$help"
     done <<EOF
-$(jq 'inputs as $input | $input.files[] as $file | $input.name, $file.path, $file.movable, $file.help' "$(dirname "$0")"/programs/* | sed -e 's/^"//' -e 's/"$//')
+$(jq 'inputs as $input | $input.files[] as $file | $input.name, $file.path, $file.movable, $file.help' "$(realpath "$0" | xargs dirname)"/programs/* | sed -e 's/^"//' -e 's/"$//')
 EOF
 # sed is to trim quotes
 }