Skip to content

Commit

Permalink
Update launcher scripts with file check, docs
Browse files Browse the repository at this point in the history
- Add a check that the relevant JS file exists in the expected location,
  before attempting to execute it. Display a message to stderr, if it's
  not found.
- Add a comment above the code, detailing how to symlink the script
  into a directory on the $PATH.
  • Loading branch information
ferdnyc committed Jun 12, 2024
1 parent ccdca05 commit 37b30f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/gsconnect-preferences.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

# To use this script as a `gsconnect-preferences` command from any
# directory (e.g. $HOME/.local/bin, /usr/local/bin/, or somewhere else
# on your $PATH), you can SYMLINK (do not copy!) it into that location.
#
# e.g:
# D="$HOME/.local/share/gnome-shell/extensions/gsconect@anyholmes.github.io"
# ln -s $D/gsconnect-preferences.sh $HOME/.local/bin/gsconnect-preferences

case "$0" in
*/*) EXTENSION_DIR=$(dirname $(realpath "$0")) ;;
*) EXTENSION_DIR=$(dirname $(realpath $(which $0))) ;;
esac
if [ ! -f "${EXTENSION_DIR}/preferences-app.js" ]; then
>&2 echo "Cannot find preferences-app.js relative to script location!"
>&2 echo "Perhaps you copied the script instead of symlinking it?"
exit -1
fi
exec /bin/env gjs -m "${EXTENSION_DIR}/preferences-app.js" "$@"

14 changes: 13 additions & 1 deletion src/gsconnect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

# To use this script as a `gsconnect` command from any directory
# (e.g. $HOME/.local/bin, /usr/local/bin/, or somewhere else on your
# $PATH), you can SYMLINK (do not copy!) it into that location.
#
# e.g:
# D="$HOME/.local/share/gnome-shell/extensions/gsconect@anyholmes.github.io"
# ln -s $D/gsconnect.sh $HOME/.local/bin/gsconnect

case "$0" in
*/*) EXTENSION_DIR=$(dirname $(realpath "$0")) ;;
*) EXTENSION_DIR=$(dirname $(realpath $(which $0))) ;;
esac
if [ ! -f "${EXTENSION_DIR}/service/daemon.js" ]; then
>&2 echo "Cannot find service/daemon.js relative to script location!"
>&2 echo "Perhaps you copied the script instead of symlinking it?"
exit -1
fi
exec /bin/env gjs -m "${EXTENSION_DIR}/service/daemon.js" "$@"

0 comments on commit 37b30f8

Please sign in to comment.