Skip to content

Commit

Permalink
xdg-ninja: allow custom programs/ dir via XN_PROGRAMS_DIR
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ballasi committed Apr 22, 2023
1 parent 4644d40 commit 5d5a66a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ To install xdg-ninja with [Homebrew](https://brew.sh), run `brew install xdg-nin

## 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.

Expand Down
5 changes: 4 additions & 1 deletion xdg-ninja.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
$(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
}
Expand All @@ -233,6 +233,9 @@ check_programs() {
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
Expand Down

0 comments on commit 5d5a66a

Please sign in to comment.