Compare commits

...

2 Commits

Author SHA1 Message Date
Rico Tiongson
09225f318c Merge branch 'master' of https://github.com/Hikari9/comfortable-swipe into improve-status 2020-05-07 22:39:04 +08:00
Rico Tiongson
cbf267b1f4 Improve comfortable-swipe status and trysudo 2020-05-07 22:37:24 +08:00
3 changed files with 50 additions and 23 deletions

View File

@ -1 +1 @@
v1.2.1 v1.2.2

View File

@ -173,15 +173,53 @@ function buffer {
########## ##########
function _program_running {
pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1
}
# verbosely show comfortable-swipe status # verbosely show comfortable-swipe status
function status { function status {
# TODO: show configuration status as well # show autostart status
echo "Autostart is $("$BASENAME" autostart status)" echo "Autostart is $("$BASENAME" autostart status)"
if pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1; then # show program status
if _program_running; then
echo "Program is RUNNING" echo "Program is RUNNING"
else else
echo "Program is STOPPED" echo "Program is STOPPED"
fi fi
# show configuration status
echo --------------------
echo "Configuration: $(config path)"
mouse3="$(config get mouse3)"
mouse4="$(config get mouse4)"
for key in $(config keys); do
value="$(config get "$key")"
if [[ -z "$value" ]]; then
vstatus="NOTSET"
else
vstatus="VALID"
if [[ "$key" != mouse* ]]; then
if [[ "$key" == *3 && -n "$mouse3" ]]; then
vstatus="IGNORED"
elif [[ "$key" == *4 && -n "$mouse4" ]]; then
vstatus="IGNORED"
fi
fi
if [[ "$key" == threshold ]]; then
if ! [[ "$value" =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
# not a float
vstatus="INVALID"
fi
fi
fi
echo "$key $vstatus" | awk '{printf "%9s is %7s", $1, $2}'
if [[ ! -z "$value" ]]; then
echo " ($value)"
else
echo
fi
done
} }
@ -291,8 +329,7 @@ function config {
local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")" local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")"
echo "$RESULT" > "$CONFIG" echo "$RESULT" > "$CONFIG"
# restart comfortable-swipe if it is running # restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then if _program_running; then
stop > /dev/null 2>&1
start > /dev/null start > /dev/null
fi fi
fi fi
@ -378,8 +415,7 @@ function config {
# show newly set value # show newly set value
echo "$KEY = $(get "$KEY")" echo "$KEY = $(get "$KEY")"
# restart comfortable-swipe if it is running # restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then if _program_running; then
stop > /dev/null 2>&1
start > /dev/null start > /dev/null
fi fi
} }
@ -451,7 +487,7 @@ function autostart {
##################################### #####################################
# toggle to opposite autostart status # toggle to opposite autostart status
function toggle { function toggle {
[[ $(status) = ON ]] && off || on [[ $(status) == ON ]] && off || on
} }
###################### ######################
@ -495,9 +531,9 @@ else
# try to invoke config set / get depending on number of arguments # try to invoke config set / get depending on number of arguments
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
# one argument, use shorthand get # one argument, use shorthand get
"$BASENAME" config get "$1" || abort config get "$1" || abort
else else
# multiple arguments, use shorthand set # multiple arguments, use shorthand set
"$BASENAME" config set "$@" 2> /dev/null || abort config set "$@" 2> /dev/null || abort
fi fi
fi fi

17
install
View File

@ -97,14 +97,10 @@ function install_configuration_file {
# #
function install_main_program { function install_main_program {
# copy source to target with executable permissions # copy source to target with executable permissions
TRYSUDO=
if ! touch "$TARGET" 2> /dev/null; then
TRYSUDO=sudo
fi
# install to target, with hardcoded version # install to target, with hardcoded version
$TRYSUDO sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET" trysudo sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET"
# allow execute permissions # allow execute permissions
$TRYSUDO chmod +x "$TARGET" trysudo chmod +x "$TARGET"
echo "Installed: $TARGET" echo "Installed: $TARGET"
} }
@ -119,13 +115,8 @@ function install_cpp_program {
TMP_TARGET="$(mktemp)" TMP_TARGET="$(mktemp)"
$COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\"" $COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\""
# compilation ok, now try to install # compilation ok, now try to install
# eheck permissions maybe if will need sudo # check permissions maybe if will need sudo
TRYSUDO= trysudo mv "$TMP_TARGET" "$COMPILE_TARGET"
if ! touch "$COMPILE_TARGET" 2> /dev/null; then
TRYSUDO=sudo
fi
# move executable to target
$TRYSUDO mv "$TMP_TARGET" "$COMPILE_TARGET"
echo "Installed: $COMPILE_TARGET" echo "Installed: $COMPILE_TARGET"
} }