]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/commitdiff
Switch to using DECODER variable
authorb3nj4m1n <b3nj4m1n@gmx.net>
Tue, 28 Jun 2022 10:03:44 +0000 (12:03 +0200)
committerb3nj4m1n <b3nj4m1n@gmx.net>
Tue, 28 Jun 2022 10:03:44 +0000 (12:03 +0200)
xdg-ninja.sh

index 4783223bea8b119d7b2c2a4d2125538c3898eb63..2005e21234781db97bdcdf0c2267bc07a3baee3d 100755 (executable)
@@ -5,28 +5,24 @@ has_command() {
     return $?
 }
 
     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 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
         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"
         printf "Markdown rendering will be done by pygmentize. (Glow is recommended)\n"
-        USE_PYGMENTIZE=true
     elif has_command highlight; then
     elif has_command highlight; then
+        DECODER="highlight --out-format ansi --syntax markdown"
         printf "Markdown rendering will be done by highlight. (Glow is recommended)\n"
         printf "Markdown rendering will be done by highlight. (Glow is recommended)\n"
-        USE_HIGHLIGHT=true
     else
     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
     fi
-    printf "Install glow for easier reading & copy-paste.\n"
-fi
+}
+auto_set_decoder
 
 unalias -a
 
 
 unalias -a
 
@@ -164,18 +160,7 @@ log() {
         ;;
 
     HELP)
         ;;
 
     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" | $DECODER
         ;;
 
     esac
         ;;
 
     esac