Source scripts directly instead of using "which"
Changes since v1: - source directly instead of using "command -v" as much as possible, I couldn't get the sources in deviceprofile cases to return a proper exit code so they still use "command -v". - avoid leaving deviceprofile var set in interactive shells from sxmo_init.sh - small fixup to warning message if deviceprofile not found This allows Sxmo to drop an external dependency on which. Anjan's note: This is also faster due to being a shell built-in Signed-off-by: Jami Kettunen <jami.kettunen@protonmail.com> Signed-off-by: Anjandev Momi <anjan@momi.ca>
This commit is contained in:

committed by
Anjandev Momi

parent
000ca3219a
commit
a813bafc01
@@ -8,7 +8,9 @@
|
||||
# WARNING: if you remove an entry, be sure to run `sxmo_mutex.sh can_suspend
|
||||
# free "entry name"` afterwards.
|
||||
|
||||
. "$(which sxmo_common.sh)"
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
lock_suspend_mutex() {
|
||||
if ! sxmo_mutex.sh can_suspend lockedby "$1"; then
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
|
||||
. sxmo_hook_icons.sh
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
LISGD_THRESHOLD="${SXMO_LISGD_THRESHOLD:-125}"
|
||||
LISGD_THRESHOLD_PRESSED="${SXMO_LISGD_THRESHOLD_PRESSED:-60}"
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# This hook is called when the ModemManager1.Modem signals a StateChanged
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
# see networkmanager documentation for state names
|
||||
oldstate="$1"
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
# in case of weird crash
|
||||
echo "unlock" > "$SXMO_STATE"
|
||||
|
@@ -9,7 +9,7 @@
|
||||
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
|
||||
. sxmo_hook_icons.sh
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
VPNDEVICE="$(nmcli con show 2>/dev/null | grep -E 'wireguard|vpn' | awk '{ print $1 }')"
|
||||
|
||||
|
@@ -4,11 +4,12 @@
|
||||
|
||||
# This hook displays the sms log for a numbers passed as $1
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
NUMBER="$1"
|
||||
CONTACTNAME="$(sxmo_contacts.sh | grep ": ${NUMBER}$" | cut -d: -f1)"
|
||||
[ "???" = "$CONTACTNAME" ] && CONTACTNAME="$CONTACTNAME ($NUMBER)"
|
||||
|
||||
TERMNAME="$NUMBER SMS" sxmo_terminal.sh sh -c "tail -n9999 -f \"$SXMO_LOGDIR/$NUMBER/sms.txt\" | sed \"s|$NUMBER|$CONTACTNAME|g\""
|
||||
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
sxmo_log "transitioning to stage lock"
|
||||
printf lock > "$SXMO_STATE"
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
sxmo_daemons.sh stop periodic_blink
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
# This hook is called when the system reaches a off state (screen off)
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
# This hook is called when the system becomes unlocked again
|
||||
|
||||
|
@@ -72,14 +72,15 @@ _sxmo_load_environments() {
|
||||
SXMO_DEVICE_NAME="$(tr -c '\0[:alnum:].,-' '_' < /proc/device-tree/compatible |
|
||||
tr '\0' '\n' | head -n1)"
|
||||
export SXMO_DEVICE_NAME
|
||||
deviceprofile="$(which "sxmo_deviceprofile_$SXMO_DEVICE_NAME.sh")"
|
||||
deviceprofile="$(command -v "sxmo_deviceprofile_$SXMO_DEVICE_NAME.sh")"
|
||||
# shellcheck disable=SC1090
|
||||
if [ -f "$deviceprofile" ]; then
|
||||
. "$deviceprofile"
|
||||
printf "deviceprofile file %s loaded.\n" "$deviceprofile"
|
||||
else
|
||||
printf "WARNING: deviceprofile file %s not found.\n" "$deviceprofile"
|
||||
printf "WARNING: deviceprofile file not found for %s.\n" "$SXMO_DEVICE_NAME"
|
||||
fi
|
||||
unset deviceprofile
|
||||
fi
|
||||
|
||||
if [ -n "$SXMO_DEVICE_NAME" ]; then
|
||||
|
@@ -3,7 +3,7 @@
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
ROTATION_GRAVITY="${SXMO_ROTATION_GRAVITY:-"16374"}"
|
||||
ROTATION_THRESHOLD="${SXMO_ROTATION_THRESHOLD:-"400"}"
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# Must be run as root
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
# see sxmo_common.sh
|
||||
if [ -e /etc/os-release ]; then
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
#prevent infinite recursion:
|
||||
unalias bemenu
|
||||
|
@@ -3,7 +3,7 @@
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
free_mutex() {
|
||||
sxmo_mutex.sh can_suspend free "Playing with leds"
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
. /etc/profile.d/sxmo_init.sh
|
||||
_sxmo_load_environments
|
||||
|
@@ -2,7 +2,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
if [ "$1" = clear ]; then
|
||||
rm -f "$XDG_RUNTIME_DIR"/sxmo.multikey.count.*
|
||||
|
@@ -9,7 +9,7 @@
|
||||
if [ -e /proc/device-tree/compatible ]; then
|
||||
device="$(tr -c '\0[:alnum:].,-' '_' < /proc/device-tree/compatible |
|
||||
tr '\0' '\n' | head -n1)"
|
||||
deviceprofile="$(which "sxmo_deviceprofile_$device.sh")"
|
||||
deviceprofile="$(command -v "sxmo_deviceprofile_$device.sh")"
|
||||
# shellcheck disable=SC1090
|
||||
[ -f "$deviceprofile" ] && . "$deviceprofile"
|
||||
fi
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
monitor="${SXMO_MONITOR:-"DSI-1"}"
|
||||
pwr="${SXMO_POWER_BUTTON:-"0:0:axp20x-pek"}"
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# Note: this script should be run as root via doas
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
on() {
|
||||
rfkill unblock wlan
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
useable_width="$(swaymsg -t get_outputs -r | jq '.[] | select(.focused == true) | .rect.width')"
|
||||
wob_sock="$XDG_RUNTIME_DIR"/sxmo.wobsock
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
info() {
|
||||
sxmo_log "$*"
|
||||
|
@@ -6,7 +6,7 @@
|
||||
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
|
||||
. sxmo_hook_icons.sh
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
|
||||
set -e
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# small utility to prompt user for PIN and unlock mode
|
||||
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. "$(which sxmo_common.sh)"
|
||||
. sxmo_common.sh
|
||||
# shellcheck source=configs/default_hooks/sxmo_hook_icons.sh
|
||||
. sxmo_hook_icons.sh
|
||||
|
||||
|
Reference in New Issue
Block a user