]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/commitdiff
xdg-ninja: allow custom programs/ dir via XN_PROGRAMS_DIR
authorAsperatus <thomas@ballasi.com>
Sat, 22 Apr 2023 13:33:15 +0000 (09:33 -0400)
committerAsperatus <thomas@ballasi.com>
Sat, 22 Apr 2023 13:43:04 +0000 (09:43 -0400)
In order to foresee the work on the unified packaging process, the
programs/ directory (which should be located in /usr/share/xdg-ninja or
/usr/local/share/xdg-ninja) is automatically found depending on where
the xdg-ninja executable is located.

This also allows for backwards compatibility as when the xdg-ninja
script is located in a working directory (not in a bin/), xdg-ninja
automatically picks the programs/ folder in the current working
directory, just like previously.

If the directory fails to find the programs/ dir, the user can override
the variable XN_PROGRAMS_DIR through environment variables.

This change is to prevent people from packaging xdg-ninja with the
programs/ directory within /usr(/local)/bin or by modifying the script
in place.

README.md
xdg-ninja.sh

index d650c1faac70f85e1a8b994b0e07c1210cdc4242..4e132016b884306eb58341bac3f52aebc5ef2ec0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ To install xdg-ninja with [Homebrew](https://brew.sh), run `brew install xdg-nin
 
 ## Configuration
 
 
 ## Configuration
 
-The configuration is done in the _programs/_ directory.
+The configuration is done in the _programs/_ directory, which should be located in the same working directory as the xdg-ninja.sh script. This can be overriden with the `XN_PROGRAMS_DIR` environment variable.
 
 You define a program, and then a list of files and directories which this program ruthlessly puts into your _$HOME_ directory.
 
 
 You define a program, and then a list of files and directories which this program ruthlessly puts into your _$HOME_ directory.
 
index 8a0ff98ca6c48af2a5c02d4de6cb34cc0fbfe9b1..8780de7a2e26f4880ac30e4d15749b7e3a2f4c43 100755 (executable)
@@ -218,7 +218,7 @@ do_check_programs() {
 " read -r name; read -r filename; read -r movable; read -r help; do
         check_file "$name" "$filename" "$movable" "$help"
     done <<EOF
 " read -r name; read -r filename; read -r movable; read -r help; do
         check_file "$name" "$filename" "$movable" "$help"
     done <<EOF
-$(jq 'inputs as $input | $input.files[] as $file | $input.name, $file.path, $file.movable, $file.help' "$(realpath "$0" | xargs dirname)"/programs/* | sed -e 's/^"//' -e 's/"$//')
+$(jq 'inputs as $input | $input.files[] as $file | $input.name, $file.path, $file.movable, $file.help' "$XN_PROGRAMS_DIR"/* | sed -e 's/^"//' -e 's/"$//')
 EOF
 # sed is to trim quotes
 }
 EOF
 # sed is to trim quotes
 }
@@ -233,6 +233,9 @@ check_programs() {
     printf "\n"
 }
 
     printf "\n"
 }
 
+[ "$XN_PROGRAMS_DIR" ] ||
+    XN_PROGRAMS_DIR="$(realpath "$0" | xargs dirname | sed 's:/bin$:/share/xdg-ninja:g')/programs"
+
 check_programs
 if [ $FIXABLE -gt 100 ]; then
     exit 101
 check_programs
 if [ $FIXABLE -gt 100 ]; then
     exit 101