]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/commitdiff
Merge pull request #23 from fourchettes/fix/dash
authorb3nj5m1n <47924309+b3nj5m1n@users.noreply.github.com>
Sun, 15 May 2022 10:38:41 +0000 (12:38 +0200)
committerGitHub <noreply@github.com>
Sun, 15 May 2022 10:38:41 +0000 (12:38 +0200)
xdg-ninja: change jq json source

1  2 
xdg-ninja.sh

diff --combined xdg-ninja.sh
index d873df2b11d60a0f13b7b6ab19d6d6372d43d886,d3e43d801a1f181122e8ede1bf56de607cf2005d..56b970e1c96d28649a468c28d778a0a38c6063d1
@@@ -1,18 -1,12 +1,18 @@@
  #!/usr/bin/env sh
  # shellcheck disable=SC2016
  
 -USE_GLOW=true
 -if ! command -v glow >/dev/null 2>/dev/null; then
 -    printf "Glow not found, markdown rendering not available.\n"
 +USE_GLOW=false
 +USE_BAT=false
 +if command -v glow >/dev/null 2>/dev/null; then
 +    USE_GLOW=true
 +elif command -v bat >/dev/null 2>/dev/null; then
 +    USE_BAT=true
 +    printf "Glow not found, markdown rendering will be done by bat.\n"
 +    printf "Install glow for easier reading & copy-paste.\n"
 +else
 +    printf "Glow or bat not found, markdown rendering not available.\n"
      printf "Output will be raw markdown and might look weird.\n"
      printf "Install glow for easier reading & copy-paste.\n"
 -    USE_GLOW=false
  fi
  
  unalias -a
@@@ -128,11 -122,9 +128,11 @@@ log() 
  
      HELP)
          if $USE_GLOW; then
 -            printf "%s" "$HELP" | glow -
 +            printf "%s\n" "$HELP" | glow -
 +        elif $USE_BAT; then
 +            printf "%s\n" "$HELP" | bat -pp -f --language markdown
          else
 -            printf "%s" "$HELP"
 +            printf "%s\n" "$HELP"
          fi
          ;;
  
@@@ -174,14 -166,14 +174,14 @@@ check_file() 
  
  # Reads a file from programs/, calls check_file on each file specified for the program
  check_program() {
-     INPUT=$1
+     PROGRAM=$1
  
-     NAME=$(printf "%s" "$INPUT" | jq -r .name)
+     NAME=$(jq -r .name "$PROGRAM")
  
      while IFS= read -r file; do
          check_file "$file" "$NAME"
      done <<EOF
- $(echo "$INPUT" | jq -rc '.files[]')
+ $(jq -rc '.files[]' "$PROGRAM")
  EOF
  }
  
@@@ -190,7 -182,7 +190,7 @@@ enumerate_programs() 
      printf "\e[1;3mStarting to check your \e[1;36m\$HOME.\e[1;0m\n"
      printf "\n"
      for prog_filename in "${0%/*}"/programs/*; do
-         check_program "$(cat "$prog_filename")"
+         check_program "$prog_filename"
      done
      printf "\e[1;3mDone checking your \e[1;36m\$HOME.\e[1;0m\n"
      printf "\n"