Skip to content

Commit 548199b

Browse files
authored
Improve comfortable-swipe status and trysudo (#85)
1 parent cb018bf commit 548199b

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.2.1
1+
v1.2.2

comfortable-swipe

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,53 @@ function buffer {
173173
##########
174174

175175

176+
function _program_running {
177+
pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1
178+
}
179+
180+
176181
# verbosely show comfortable-swipe status
177182
function status {
178-
# TODO: show configuration status as well
183+
# show autostart status
179184
echo "Autostart is $("$BASENAME" autostart status)"
180-
if pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1; then
185+
# show program status
186+
if _program_running; then
181187
echo "Program is RUNNING"
182188
else
183189
echo "Program is STOPPED"
184190
fi
191+
# show configuration status
192+
echo --------------------
193+
echo "Configuration: $(config path)"
194+
mouse3="$(config get mouse3)"
195+
mouse4="$(config get mouse4)"
196+
for key in $(config keys); do
197+
value="$(config get "$key")"
198+
if [[ -z "$value" ]]; then
199+
vstatus="NOTSET"
200+
else
201+
vstatus="VALID"
202+
if [[ "$key" != mouse* ]]; then
203+
if [[ "$key" == *3 && -n "$mouse3" ]]; then
204+
vstatus="IGNORED"
205+
elif [[ "$key" == *4 && -n "$mouse4" ]]; then
206+
vstatus="IGNORED"
207+
fi
208+
fi
209+
if [[ "$key" == threshold ]]; then
210+
if ! [[ "$value" =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
211+
# not a float
212+
vstatus="INVALID"
213+
fi
214+
fi
215+
fi
216+
echo "$key $vstatus" | awk '{printf "%9s is %7s", $1, $2}'
217+
if [[ ! -z "$value" ]]; then
218+
echo " ($value)"
219+
else
220+
echo
221+
fi
222+
done
185223
}
186224

187225

@@ -291,8 +329,7 @@ function config {
291329
local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")"
292330
echo "$RESULT" > "$CONFIG"
293331
# restart comfortable-swipe if it is running
294-
if [[ "$(status)" == ON ]]; then
295-
stop > /dev/null 2>&1
332+
if _program_running; then
296333
start > /dev/null
297334
fi
298335
fi
@@ -378,8 +415,7 @@ function config {
378415
# show newly set value
379416
echo "$KEY = $(get "$KEY")"
380417
# restart comfortable-swipe if it is running
381-
if [[ "$(status)" == ON ]]; then
382-
stop > /dev/null 2>&1
418+
if _program_running; then
383419
start > /dev/null
384420
fi
385421
}
@@ -451,7 +487,7 @@ function autostart {
451487
#####################################
452488
# toggle to opposite autostart status
453489
function toggle {
454-
[[ $(status) = ON ]] && off || on
490+
[[ $(status) == ON ]] && off || on
455491
}
456492

457493
######################
@@ -495,9 +531,9 @@ else
495531
# try to invoke config set / get depending on number of arguments
496532
if [[ $# -eq 1 ]]; then
497533
# one argument, use shorthand get
498-
"$BASENAME" config get "$1" || abort
534+
config get "$1" || abort
499535
else
500536
# multiple arguments, use shorthand set
501-
"$BASENAME" config set "$@" 2> /dev/null || abort
537+
config set "$@" 2> /dev/null || abort
502538
fi
503539
fi

install

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,10 @@ function install_configuration_file {
9797
#
9898
function install_main_program {
9999
# copy source to target with executable permissions
100-
TRYSUDO=
101-
if ! touch "$TARGET" 2> /dev/null; then
102-
TRYSUDO=sudo
103-
fi
104100
# install to target, with hardcoded version
105-
$TRYSUDO sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET"
101+
trysudo sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET"
106102
# allow execute permissions
107-
$TRYSUDO chmod +x "$TARGET"
103+
trysudo chmod +x "$TARGET"
108104
echo "Installed: $TARGET"
109105
}
110106

@@ -119,13 +115,8 @@ function install_cpp_program {
119115
TMP_TARGET="$(mktemp)"
120116
$COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\""
121117
# compilation ok, now try to install
122-
# eheck permissions maybe if will need sudo
123-
TRYSUDO=
124-
if ! touch "$COMPILE_TARGET" 2> /dev/null; then
125-
TRYSUDO=sudo
126-
fi
127-
# move executable to target
128-
$TRYSUDO mv "$TMP_TARGET" "$COMPILE_TARGET"
118+
# check permissions maybe if will need sudo
119+
trysudo mv "$TMP_TARGET" "$COMPILE_TARGET"
129120
echo "Installed: $COMPILE_TARGET"
130121
}
131122

0 commit comments

Comments
 (0)