]>
glassweightruler.freedombox.rocks Git - xdg-ninja.git/blob - xdg-ninja.sh
4 if ! command -v glow
&> /dev
/null
6 echo "Glow not found, markdown rendering not available."
18 # Function to expand enviornment variables in string
19 # https://stackoverflow.com/a/20316582/11110290
20 apply_shell_expansion
() {
22 declare delimiter
="__apply_shell_expansion_delimiter__"
23 declare command="cat <<$delimiter"$
'\n'"$data"$
'\n'"$delimiter"
27 # Returns 0 if the path doesn't lead anywhere
28 # Return 1 if the path points to a file, 2 if it points to a directory
29 check_not_exists_file
() {
30 FILE_PATH
=$(apply_shell_expansion "$1")
31 if [ -f "$FILE_PATH" ]; then
33 elif [ -d "$FILE_PATH" ]; then
41 # Function to handle the formatting of output
51 printf "[\e[1;31m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
55 printf "[\e[1;33m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
59 printf "[\e[1;36m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
63 printf "[\e[1;32m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
77 # Checks that the given file does not exist, otherwise outputs help
82 FILENAME
=$(echo -E "$INPUT" | jq -r .path)
83 MOVABLE
=$(echo -E "$INPUT" | jq -r .movable)
84 HELP
=$(echo -E "$INPUT" | jq -r .help)
86 check_not_exists_file
"$FILENAME"
91 log SUCS
"$NAME" "$FILENAME" "$HELP"
96 log ERR
"$NAME" "$FILENAME" "$HELP"
98 log WARN
"$NAME" "$FILENAME" "$HELP"
100 if ! [ -z "$HELP" ]; then
101 log HELP
"$NAME" "$FILENAME" "$HELP"
103 log HELP
"$NAME" "$FILENAME" "_No help available._"
110 # Reads a file from programs/, calls check_file on each file specified for the program
114 NAME
=$(echo "$INPUT" | jq -r .name)
117 while IFS
= read -r file; do
118 check_file
"$file" "$NAME"
119 done <<< "$(echo "$INPUT" | jq -rc '.files[]')"
122 # Loops over all files in the programs/ directory and calls check_program
123 enumerate_programs
() {
124 for prog_filename
in .
/programs
/*; do
125 check_program
"$(cat $prog_filename)"