mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-01 08:46:40 +02:00
- Experimental caret checking support for Firefox & Chrome
This commit is contained in:
@@ -1,97 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
# silent_background() {
|
||||
# { 2>&3 "$@"& } 3>&2 2>/dev/null
|
||||
# disown &>/dev/null
|
||||
# }
|
||||
|
||||
mkdir -p /tmp/kinto
|
||||
echo "0" > /tmp/kinto/caret
|
||||
# background process that will check
|
||||
# caret status and apply keymap
|
||||
lastcheck=0
|
||||
ww=0
|
||||
while (true);do
|
||||
sleep 0.2
|
||||
check=$(cat /tmp/kinto/caret)
|
||||
if [ "${check}" == "ff ww 1" ] && [ "${lastcheck}" != 1 ]; then
|
||||
echo "firefox wordwise"
|
||||
# echo "$check"
|
||||
# Sets original config
|
||||
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/\$2\$3/g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# End of Line)/\$2\$3/g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Firefox-nw)/ # \$1\$2/g" /tmp/kinto/kinto.py
|
||||
lastcheck=1
|
||||
ww=1
|
||||
elif [ "${check}" == "ff nw" ] && [ "${lastcheck}" != 2 ]; then
|
||||
echo "firefox no wordwise"
|
||||
# echo "$check"
|
||||
# Sets new config
|
||||
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# Firefox-nw)/ \$1\$2/g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py
|
||||
lastcheck=2
|
||||
ww=0
|
||||
elif [ "${check}" == "chrome ww 1" ] && [ "${lastcheck}" != 3 ]; then
|
||||
echo "chrome wordwise"
|
||||
# echo "$check"
|
||||
# Sets original config
|
||||
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/ \$1\$2/g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}#\s(K.*)(# End of Line)/ \$1\$2/g" /tmp/kinto/kinto.py
|
||||
lastcheck=3
|
||||
ww=1
|
||||
elif [ "${check}" == "chrome nw" ] && [ "${lastcheck}" != 4 ]; then
|
||||
echo "chrome no wordwise"
|
||||
# echo "$check"
|
||||
# Sets new config
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2g" /tmp/kinto/kinto.py
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py
|
||||
lastcheck=4
|
||||
ww=0
|
||||
elif [ "${check}" == "reset" ] && [ "${lastcheck}" != 5 ]; then
|
||||
echo "reset"
|
||||
cp /home/{username}/.config/kinto/kinto.py /tmp/kinto/kinto.py
|
||||
lastcheck=5
|
||||
fi
|
||||
# echo "outside loop $check"
|
||||
done &
|
||||
|
||||
lastapp="None"
|
||||
reset=false
|
||||
millitime=`date +%s%3N`
|
||||
echo "$millitime" > /tmp/kinto/millitime
|
||||
|
||||
IBUSADD=$(cat ~/.config/ibus/bus/`ls ~/.config/ibus/bus -1rt | tail -n1` | awk -F'IBUS_ADDRESS=' '{print $2}' | xargs)
|
||||
dbus-monitor --address $IBUSADD "path='/org/freedesktop/IBus/Panel',interface='org.freedesktop.IBus.Panel',member='FocusOut'" 2> /dev/null | grep --line-buffered -o -P '(?<=object path \"/org/freedesktop/IBus/InputContext_).*(?=[\"])' |
|
||||
while read ln
|
||||
do
|
||||
newtime=`date +%s%3N`
|
||||
difftime=$(( newtime - millitime ))
|
||||
millitime="$newtime"
|
||||
echo "$millitime" > /tmp/kinto/millitime
|
||||
appname=$(xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | awk '{print substr($4,2,length($4)-2)}')
|
||||
# Enable wordwise
|
||||
if (( $ln == 1 )); then
|
||||
if [ "${appname}" == "Firefox" ] && [ "${laststatus}" != "1" ]; then
|
||||
printf 'ff ww %s\n' "$ln" > /tmp/kinto/caret
|
||||
reset=false
|
||||
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${laststatus}" != "1" ]; then
|
||||
printf 'chrome ww %s\n' "$ln" > /tmp/kinto/caret
|
||||
reset=false
|
||||
elif ! [ "${appname}" == "Firefox" ] || [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${reset}" == false ]; then
|
||||
if [ "${ln}" == "1" ]; then
|
||||
appname=$(xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | awk '{print substr($4,2,length($4)-2)}')
|
||||
if [ "${appname}" == "Firefox" ]; then
|
||||
# echo "ff ww"
|
||||
printf 'ff ww %s\n' "1" > /tmp/kinto/caret
|
||||
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ]; then
|
||||
# echo "chrome ww"
|
||||
printf 'chrome ww %s\n' "1" > /tmp/kinto/caret
|
||||
else
|
||||
echo "reset" > /tmp/kinto/caret
|
||||
reset=true
|
||||
fi
|
||||
|
||||
lastapp="$appname"
|
||||
laststatus="$ln"
|
||||
#printf '%s\n' "$ln" > /tmp/kinto/caret
|
||||
# disable wordwise
|
||||
else
|
||||
if [ "${appname}" == "Firefox" ] && [ "${laststatus}" == "1" ]; then
|
||||
if [ "${appname}" == "Firefox" ]; then
|
||||
# echo "ff nw"
|
||||
printf 'ff nw\n' > /tmp/kinto/caret
|
||||
reset=false
|
||||
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${laststatus}" == "1" ]; then
|
||||
elif [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ]; then
|
||||
# echo "chrome nw"
|
||||
printf 'chrome nw\n' > /tmp/kinto/caret
|
||||
reset=false
|
||||
elif ! [ "${appname}" == "Firefox" ] || [ "${appname}" == "Chromium" ] || [ "${appname}" == "Chromium-browser" ] || [ "${appname}" == "Google-chrome" ] || [ "${appname}" == "Epiphany" ] && [ "${reset}" == false ]; then
|
||||
else
|
||||
echo "reset" > /tmp/kinto/caret
|
||||
reset=true
|
||||
fi
|
||||
lastapp="$appname"
|
||||
laststatus="$ln"
|
||||
fi
|
||||
|
||||
done&
|
||||
|
||||
while (true);do
|
||||
sleep 0.2
|
||||
appname2=$(xprop -id `xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}'` | grep "WM_CLASS(STRING)" | awk '{print substr($4,2,length($4)-2)}')
|
||||
check=$(cat /tmp/kinto/caret)
|
||||
millitime=$(cat /tmp/kinto/millitime)
|
||||
newtime=`date +%s%3N`
|
||||
difftime=$(( newtime - millitime ))
|
||||
if (( $difftime > 200 )); then
|
||||
if [ "${check}" == "ff nw" ] && [ "${lastcheck}" != 1 ]; then
|
||||
echo "firefox no wordwise"
|
||||
# Sets new config
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Chrome-nw)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Firefox-nw)/ \$1\$2/g;s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
|
||||
lastcheck=1
|
||||
ww=0
|
||||
elif [ "${check}" == "chrome nw" ] && [ "${lastcheck}" != 2 ]; then
|
||||
echo "chrome no wordwise"
|
||||
# Sets new config
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Firefox-nw)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# Beginning of Line)/ # \$1\$2/g;s/[^\n]\s{3}(K.*)(# End of Line)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Chrome-nw)/ \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
|
||||
lastcheck=2
|
||||
ww=0
|
||||
elif ([ "${check}" != "chrome nw" ] && [ "${check}" != "ff nw" ] && [ "${lastcheck}" != 3 ]) || ([ "${appname2}" != "Firefox" ] && [ "${appname2}" != "Chromium" ] && [ "${appname2}" != "Chromium-browser" ] && [ "${appname2}" != "Google-chrome" ] && [ "${appname2}" != "Epiphany" ] && [ "${check}" == "reset" ] && [ "${lastcheck}" != 3 ]); then
|
||||
echo "wordwise"
|
||||
# Sets original config
|
||||
perl -pi -e "s/[^\n]\s{3}(K.*)(# Firefox-nw)/ # \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# Beginning of Line)/ \$1\$2/g;s/[^\n]\s{3}#\s(K.*)(# End of Line)/ \$1\$2/g;s/[^\n]\s{3}(K.*)(# Chrome-nw)/ # \$1\$2/g" /tmp/kinto/kinto.py 2>/dev/null
|
||||
# cp /home/ryan/.config/kinto/kinto.py /tmp/kinto/kinto.py
|
||||
lastcheck=3
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
Reference in New Issue
Block a user