dotfiles/lib/lib.sh

33 lines
525 B
Bash
Raw Normal View History

2022-12-16 14:23:28 +01:00
#!/bin/sh
2022-12-16 15:33:59 +01:00
. ./sync.conf || . ../sync.conf
2022-12-16 14:23:28 +01:00
DRY_RUN=${DRY_RUN:-no}
bool() {
case "$1" in
1|true|yes|on|TRUE|YES|ON) return 0 ;;
*) return 1 ;;
esac
}
run() {
2023-01-26 15:13:35 +01:00
# Check if command starts with NO_RUN ($*) and remove it
if echo "$*" | grep -q "^NO_RUN"; then
return 0
fi
2022-12-16 14:23:28 +01:00
if bool "$DRY_RUN"; then
echo "DRY: + $*"
else
echo "+ $*"
"$@"
fi
}
2022-12-16 15:33:59 +01:00
is_graphical() {
2023-01-26 15:13:35 +01:00
command -v $PREF_TERM > /dev/null && return 0 || return 1
2022-12-18 21:51:53 +01:00
}
2023-01-26 15:13:35 +01:00
command -v $SYS_SUDO > /dev/null || SYS_SUDO="NO_RUN"