From e0cf58430b936a22d2b67b0146995e67a512f69d Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sun, 4 Apr 2021 16:04:22 +0100 Subject: [PATCH] Many changes including introduction to menu system THe main addition here is the menu system that is used to contoll the phone. THere are also some small helper scripts for calls etc. --- bin/.bin/contact-numbers | 14 ++++++-- bin/.bin/dmenu/menu-phone | 21 +++++++++++ bin/.bin/dmenu/menu-st | 21 +++++++++++ bin/.bin/dmenu/menu-system | 37 +++++++++++++++++++ bin/.bin/dmenu/rofi-volume | 58 ++++++++++++++++++++++++++++++ bin/.bin/dmenu/spawn-phone-menu | 27 ++++++++++++++ bin/.bin/dmenu/trofi | 12 +++++++ bin/.bin/notifications/phoneStatus | 10 ++++++ bin/.bin/toggleKeyboard | 7 ++++ bin/.bin/volume | 1 + 10 files changed, 206 insertions(+), 2 deletions(-) create mode 100755 bin/.bin/dmenu/menu-phone create mode 100755 bin/.bin/dmenu/menu-st create mode 100755 bin/.bin/dmenu/menu-system create mode 100755 bin/.bin/dmenu/rofi-volume create mode 100755 bin/.bin/dmenu/spawn-phone-menu create mode 100755 bin/.bin/dmenu/trofi create mode 100755 bin/.bin/notifications/phoneStatus create mode 100755 bin/.bin/toggleKeyboard diff --git a/bin/.bin/contact-numbers b/bin/.bin/contact-numbers index 26812e2a..0a2497a0 100755 --- a/bin/.bin/contact-numbers +++ b/bin/.bin/contact-numbers @@ -2,6 +2,15 @@ addressbook="$HOME/.abook/addressbook" +filter(){ + if [ -n "$1" ]; then + local str="$(echo "$1" | tr -d ' ' | sed 's/^0/+44/')" + grep -i "$str" + else + cat - + fi +} + cat "$addressbook" | grep -E '(\[[0-9]+\]|^$|name|phone|mobile)' | awk -v RS="\n\n" -v ORS="\n" '{gsub("\n","\t",$0); print $0}' | @@ -9,8 +18,9 @@ cat "$addressbook" | name="$(echo "$line" | cut -d ' ' -f 2 | cut -d '=' -f 2)" echo "$line" | tr '\t' '\n' | grep -E '(phone|mobile)' | while read -r numLine; do - num="$(echo "$numLine" | cut -d '=' -f 2 | tr -d ' ' | sed 's/+44(0)/+44/')" + num="$(echo "$numLine" | cut -d '=' -f 2 | tr -d ' ' | + sed 's/+44(0)/+44/' | sed 's/^0/+44/')" numType="$(echo "$numLine" | cut -d '=' -f 1)" echo -e "$name\t$num\t$numType" done - done + done | filter "$*" diff --git a/bin/.bin/dmenu/menu-phone b/bin/.bin/dmenu/menu-phone new file mode 100755 index 00000000..d302b8e7 --- /dev/null +++ b/bin/.bin/dmenu/menu-phone @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +options="End All Calls +Check for Calls +Check for Texts +Dialer" + +while true ; do + choice="$(echo "$options" | trofi)" + case "$choice" in + "End All Calls") + modem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)" + mmcli -m "$modem" --voice-hangup-all + break ;; + "Check for Calls") checkCall ;; + "Check for Texts") checkSMS ;; + "Dialer") (dialer &); break ;; + "Back") break;; + esac +done + diff --git a/bin/.bin/dmenu/menu-st b/bin/.bin/dmenu/menu-st new file mode 100755 index 00000000..0b559b8a --- /dev/null +++ b/bin/.bin/dmenu/menu-st @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +options="Zoom In +Zoom Out +Paste +System Menu +Exit" + +choice="" +while : ; do + choice="$(echo "$options" | trofi)" + case "$choice" in + "Zoom In") sleep 0.3; xdotool key --clearmodifiers "ctrl+shift+j" ;; + "Zoom Out") sleep 0.3; xdotool key --clearmodifiers "ctrl+shift+k" ;; + "Paste") sleep 0.3; xdotool key --clearmodifiers "ctrl+shift+v" ;; + "System Menu") menu-system; break ;; + "Exit") sleep 0.3; xdotool key --clearmodifiers "Super_L+q"; break ;; + "") break ;; + esac +done + diff --git a/bin/.bin/dmenu/menu-system b/bin/.bin/dmenu/menu-system new file mode 100755 index 00000000..985cf2de --- /dev/null +++ b/bin/.bin/dmenu/menu-system @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +options="Terminal +Browser +Phone +Podcasts +Go To Workspace +Move To Workspace +Power Menu +Exit" + +chooseWorkspace(){ + seq 1 10 | trofi +} + +goToWorkspace(){ + xdotool key --clearmodifiers "Super_L+$(chooseWorkspace)" +} +moveToWorkspace(){ + xdotool key --clearmodifiers "Super_L+Shift+$(chooseWorkspace)" +} + +while true ; do + choice="$(echo "$options" | trofi)" + case "$choice" in + "Terminal") (folder-shell &); break ;; + "Browser") (firefox &); break ;; + "Podcasts") (gnome-podcasts &); break ;; + "Phone") spawn-phone-menu phone ; break ;; + "Go To Workspace") goToWorkspace ; break ;; + "Move To Workspace") moveToWorkspace ; break ;; + "Power Menu") (rofi-shutdown &); break ;; + "Exit") sleep 0.3; xdotool key --clearmodifiers "Super_L+q"; break ;; + "") break;; + esac +done + diff --git a/bin/.bin/dmenu/rofi-volume b/bin/.bin/dmenu/rofi-volume new file mode 100755 index 00000000..b54ddb90 --- /dev/null +++ b/bin/.bin/dmenu/rofi-volume @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +up="" +down="" +mute="ﱝ" + + +while : ; do + active="" + urgent="" + + + if type -p pulseaudio-ctl 2> /dev/null; then + volume="$(pulseaudio-ctl full-status | cut -d ' ' -f1)" + speakerStatus="$(pulseaudio-ctl full-status | cut -d ' ' -f2 | + sed 's/no/on/g')" + else + volume="$(amixer -D default sget Master | grep -o '\[.*\%' | + head -n 1 | tr -d '[%')" + speakerStatus="$(amixer -D default sget Master | grep -o '\[\(on\|off\)' | + head -n 1 | tr -d '[')" + fi + + if [ "$speakerStatus" = "off" ]; then + volume="Muted" + urgent="-u 2" + else + active="-a 2" + fi + + choice="$(echo -e "$up\n$down\n$mute" | + rofi -dmenu -theme 'themes/volume.rasi' -p "$volume" $urgent $active)" + case "$choice" in + "$up") + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl up + else + amixer -q -D default sset Master 5%+ unmute + fi + ;; + "$down") + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl down + else + amixer -q -D default sset Master 5%- unmute + fi + ;; + "$mute") + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl mute + else + amixer -q -D default sset Master toggle + fi + ;; + "") break + esac + +done diff --git a/bin/.bin/dmenu/spawn-phone-menu b/bin/.bin/dmenu/spawn-phone-menu new file mode 100755 index 00000000..6ded8b21 --- /dev/null +++ b/bin/.bin/dmenu/spawn-phone-menu @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# This script creates menus for applications running on my phone + +error(){ + echo "$@" > /dev/stderr + exit 1 +} + +windowFocus="$(xdotool getwindowfocus)" +if [ -n "$1" ]; then + menu="menu-$1" +else + class="$(xprop -id "$windowFocus" | grep "WM_CLASS" | cut -d '"' -f 2)" + case "$class" in + "xterm-256color") menu="menu-st" ;; + *) menu="menu-$class" ;; + esac +fi + + +type "$menu" > /dev/null 2>&1 || menu="menu-system" + +"$menu" + + + diff --git a/bin/.bin/dmenu/trofi b/bin/.bin/dmenu/trofi new file mode 100755 index 00000000..04ffa097 --- /dev/null +++ b/bin/.bin/dmenu/trofi @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# THis is a simple wrapper around rofi which makes it nicer to use with touch screens + + +input="$(cat -)" + +lines="$(echo "$input" | wc -l )" + +[ "$lines" -gt 15 ] && lines=15 + +echo "$input" | rofi -dmenu -me-accept-entry '!MousePrimary' -theme "themes/touch-dmenu.rasi" -lines "$lines" diff --git a/bin/.bin/notifications/phoneStatus b/bin/.bin/notifications/phoneStatus new file mode 100755 index 00000000..1dc8d2ec --- /dev/null +++ b/bin/.bin/notifications/phoneStatus @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +battery="$(cat /sys/class/power_supply/axp20x-battery/capacity)" +batteryStatus="$(cat /sys/class/power_supply/axp20x-battery/status)" +[ "$batteryStatus" = "Charging" ] && batteryIcon="🔌" || batteryIcon="🔋" + +time="$(date "+%H:%M")" + +notify-send "$(hostname)" "$batteryIcon ${battery}%\nTime $time" + diff --git a/bin/.bin/toggleKeyboard b/bin/.bin/toggleKeyboard new file mode 100755 index 00000000..009a783f --- /dev/null +++ b/bin/.bin/toggleKeyboard @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +if pidof svkbd-colemak || pidof svkbd-numbers; then + pkill "svkbd-*" +else + svkbd-colemak & disown +fi diff --git a/bin/.bin/volume b/bin/.bin/volume index 57e35039..d8eb5b4c 100755 --- a/bin/.bin/volume +++ b/bin/.bin/volume @@ -43,6 +43,7 @@ case "$1" in else amixer -q -D default sset Master toggle fi + ;; esac if type -p pulseaudio-ctl 2> /dev/null; then