X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/xdg-ninja.git/blobdiff_plain/79e71eaef3ab8cb2e8ec479a54f735c5b19056e2..8ef1b379b453fdc29094e6ce4a014b93a91c0def:/xdg-ninja.sh diff --git a/xdg-ninja.sh b/xdg-ninja.sh index 4783223..ed0e8dd 100755 --- a/xdg-ninja.sh +++ b/xdg-ninja.sh @@ -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 <