]>
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."
15 \e[37;45;1mxdg-ninja\e[0m
17 \e[1;3mCheck your \$HOME for unwanted files.\e[1;0m
19 ────────────────────────────────────
21 \e[3m--help\e[0m \e[1mThis help menu\e[0m
24 \e[3m--no-skip-ok\e[0m \e[1mDisplay messages for all files checked (verbose)\e[0m
27 \e[3m--skip-ok\e[0m \e[1mDon't display anything for files that do not exist (default)\e[0m
33 if [[ $i == "--help" ]] || [[ $i == "-h" ]] ; then
36 elif [[ $i == "--skip-ok" ]] ; then
38 elif [[ $i == "--no-skip-ok" ]] ; then
40 elif [[ $i == "-v" ]] ; then
51 # Function to expand enviornment variables in string
52 # https://stackoverflow.com/a/20316582/11110290
53 apply_shell_expansion
() {
55 declare delimiter
="__apply_shell_expansion_delimiter__"
56 declare command="cat <<$delimiter"$
'\n'"$data"$
'\n'"$delimiter"
60 # Returns 0 if the path doesn't lead anywhere
61 # Return 1 if the path points to a file, 2 if it points to a directory
62 check_not_exists_file
() {
63 FILE_PATH
=$(apply_shell_expansion "$1")
64 if [ -f "$FILE_PATH" ]; then
66 elif [ -d "$FILE_PATH" ]; then
74 # Function to handle the formatting of output
84 printf "[\e[1;31m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
88 printf "[\e[1;33m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
92 printf "[\e[1;36m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
96 if [ "$SKIP_OK" = false
]; then
97 printf "[\e[1;32m$NAME\e[1;0m]: \e[1;3m$FILENAME\e[1;0m\n"
103 echo "$HELP" | glow
-
112 # Checks that the given file does not exist, otherwise outputs help
117 FILENAME
=$(echo -E "$INPUT" | jq -r .path)
118 MOVABLE
=$(echo -E "$INPUT" | jq -r .movable)
119 HELP
=$(echo -E "$INPUT" | jq -r .help)
121 check_not_exists_file
"$FILENAME"
126 log SUCS
"$NAME" "$FILENAME" "$HELP"
131 log ERR
"$NAME" "$FILENAME" "$HELP"
133 log WARN
"$NAME" "$FILENAME" "$HELP"
135 if ! [ -z "$HELP" ]; then
136 log HELP
"$NAME" "$FILENAME" "$HELP"
138 log HELP
"$NAME" "$FILENAME" "_No help available._"
145 # Reads a file from programs/, calls check_file on each file specified for the program
149 NAME
=$(echo "$INPUT" | jq -r .name)
152 while IFS
= read -r file; do
153 check_file
"$file" "$NAME"
154 done <<< "$(echo "$INPUT" | jq -rc '.files[]')"
157 # Loops over all files in the programs/ directory and calls check_program
158 enumerate_programs
() {
159 for prog_filename
in .
/programs
/*; do
160 check_program
"$(cat $prog_filename)"