@ -6,12 +6,12 @@ trap gracefulexit INT TERM
. " $( dirname " $0 " ) /sxmo_common.sh "
. " $( dirname " $0 " ) /sxmo_common.sh "
gracefulexit( ) {
gracefulexit( ) {
echo " Gracefully exiting $0 " >& 2
printf "Gracefully exiting %s\n" " $0 " >& 2
kill -9 0
kill -9 0
}
}
confirm( ) {
confirm( ) {
PICKED = " $( printf "Yes\nNo\n" | dmenu -p " Confirm $1 " ) "
PICKED = " $( printf "Yes\nNo\n" | sxmo_ dmenu.sh -p " Confirm $1 " ) "
if [ " $PICKED " = "Yes" ] ; then
if [ " $PICKED " = "Yes" ] ; then
return 0
return 0
@ -30,9 +30,9 @@ programchoicesinit() {
XPROPOUT = " $( sxmo_wm.sh focusedwindow) "
XPROPOUT = " $( sxmo_wm.sh focusedwindow) "
WMCLASS = " ${ 1 :- $( printf %s " $XPROPOUT " | grep app: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]' ) } "
WMCLASS = " ${ 1 :- $( printf %s " $XPROPOUT " | grep app: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]' ) } "
if [ -z " $XPROPOUT " ] ; then
if [ -z " $XPROPOUT " ] ; then
echo "sxmo_appmenu: detected no active window, no problem, opening system menu" >& 2
printf "sxmo_appmenu: detected no active window, no problem, opening system menu\n " >& 2
else
else
echo " sxmo_appmenu: opening menu for wmclass $WMCLASS " >& 2
printf "sxmo_appmenu: opening menu for wmclass %s\n" " $WMCLASS " >& 2
fi
fi
case " $WMCLASS " in
case " $WMCLASS " in
@ -188,7 +188,7 @@ programchoicesinit() {
$icon_aru Volume up ^ 1 ^ sxmo_vol.sh up
$icon_aru Volume up ^ 1 ^ sxmo_vol.sh up
$icon_ard Volume down ^ 1 ^ sxmo_vol.sh down
$icon_ard Volume down ^ 1 ^ sxmo_vol.sh down
"
"
WINNAME = " Audio"
WINNAME = Audio
; ;
; ;
power )
power )
# Power menu
# Power menu
@ -200,7 +200,7 @@ programchoicesinit() {
$icon_rld Reboot ^ 0 ^ confirm Reboot && sxmo_terminal.sh sudo reboot
$icon_rld Reboot ^ 0 ^ confirm Reboot && sxmo_terminal.sh sudo reboot
$icon_pwr Poweroff ^ 0 ^ confirm Poweroff && sxmo_terminal.sh sudo poweroff
$icon_pwr Poweroff ^ 0 ^ confirm Poweroff && sxmo_terminal.sh sudo poweroff
"
"
WINNAME = " Power"
WINNAME = Power
; ;
; ;
*mpv* )
*mpv* )
# MPV
# MPV
@ -217,7 +217,7 @@ programchoicesinit() {
$icon_inf Info ^ 1 ^ sxmo_type i
$icon_inf Info ^ 1 ^ sxmo_type i
$icon_inf Seek Info ^ 1 ^ sxmo_type o
$icon_inf Seek Info ^ 1 ^ sxmo_type o
"
"
WINNAME = Mpv && return
WINNAME = Mpv
; ;
; ;
*feh* )
*feh* )
# Feh
# Feh
@ -234,7 +234,7 @@ programchoicesinit() {
$icon_a2x Mirror ^ 1 ^ sxmo_type -k bar
$icon_a2x Mirror ^ 1 ^ sxmo_type -k bar
$icon_inf Toggle filename ^ 1 ^ sxmo_type d
$icon_inf Toggle filename ^ 1 ^ sxmo_type d
"
"
WINNAME = Feh && return
WINNAME = Feh
; ;
; ;
*sxiv* )
*sxiv* )
# Sxiv
# Sxiv
@ -249,7 +249,7 @@ programchoicesinit() {
$icon_a2x Mirror ^ 1 ^ sxmo_type -k bar
$icon_a2x Mirror ^ 1 ^ sxmo_type -k bar
$icon_grd Thumbnail ^ 0 ^ sxmo_type -k Return
$icon_grd Thumbnail ^ 0 ^ sxmo_type -k Return
"
"
WINNAME = Sxiv && return
WINNAME = Sxiv
; ;
; ;
*sthotkeys* )
*sthotkeys* )
# St hotkeys
# St hotkeys
@ -269,7 +269,7 @@ programchoicesinit() {
*foot*| *st* )
*foot*| *st* )
# First we try to handle the app running inside the terminal:
# First we try to handle the app running inside the terminal:
WMNAME = " ${ 1 :- $( printf %s " $XPROPOUT " | grep title: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]' ) } "
WMNAME = " ${ 1 :- $( printf %s " $XPROPOUT " | grep title: | cut -d" " -f2- | tr '[:upper:]' '[:lower:]' ) } "
if echo " $WMNAME " | grep -i -E "(vi|vim|vis|nvim|neovim|kakoune)" ; then
if printf %s " $WMNAME " | grep -q i -E "(vi|vim|vis|nvim|neovim|kakoune)" ; then
#Vim in foot
#Vim in foot
CHOICES = "
CHOICES = "
$icon_aru Scroll up ^ 1 ^ sxmo_type -M Ctrl u
$icon_aru Scroll up ^ 1 ^ sxmo_type -M Ctrl u
@ -286,7 +286,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = Vim
WINNAME = Vim
elif echo " $WMNAME " | grep -i -w "nano" ; then
elif printf %s " $WMNAME " | grep -q i -w "nano" ; then
#Nano in foot
#Nano in foot
CHOICES = "
CHOICES = "
$icon_aru Scroll up ^ 1 ^ sxmo_type -k Prior
$icon_aru Scroll up ^ 1 ^ sxmo_type -k Prior
@ -301,7 +301,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = Nano
WINNAME = Nano
elif echo " $WMNAME " | grep -i -w "tuir" ; then
elif printf %s " $WMNAME " | grep -q i -w "tuir" ; then
#tuir (reddit client) in foot
#tuir (reddit client) in foot
CHOICES = "
CHOICES = "
$icon_aru Previous ^ 1 ^ sxmo_type k
$icon_aru Previous ^ 1 ^ sxmo_type k
@ -319,7 +319,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = tuir
WINNAME = tuir
elif echo " $WMNAME " | grep -i -w "w3m" ; then
elif printf %s " $WMNAME " | grep -q i -w "w3m" ; then
#w3m
#w3m
CHOICES = "
CHOICES = "
$icon_arl Back ^ 1 ^ sxmo_type b
$icon_arl Back ^ 1 ^ sxmo_type b
@ -335,7 +335,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = w3m
WINNAME = w3m
elif echo " $WMNAME " | grep -i -w "ncmpcpp" ; then
elif printf %s " $WMNAME " | grep -q i -w "ncmpcpp" ; then
#ncmpcpp
#ncmpcpp
CHOICES = "
CHOICES = "
$icon_lst Playlist ^ 0 ^ sxmo_type 1
$icon_lst Playlist ^ 0 ^ sxmo_type 1
@ -351,7 +351,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = ncmpcpp
WINNAME = ncmpcpp
elif echo " $WMNAME " | grep -i -w "aerc" ; then
elif printf %s " $WMNAME " | grep -q i -w "aerc" ; then
#aerc
#aerc
CHOICES = "
CHOICES = "
$icon_pau Archive ^ 1 ^ sxmo_type ':archive flat' -k Return
$icon_pau Archive ^ 1 ^ sxmo_type ':archive flat' -k Return
@ -362,7 +362,7 @@ programchoicesinit() {
$icon_trm xdg-open Part ^ 0 ^ sxmo_type ':open' -k Return
$icon_trm xdg-open Part ^ 0 ^ sxmo_type ':open' -k Return
"
"
WINNAME = aerc
WINNAME = aerc
elif echo " $WMNAME " | grep -i -E -w "(less|mless)" ; then
elif printf %s " $WMNAME " | grep -q i -E -w "(less|mless)" ; then
#less
#less
CHOICES = "
CHOICES = "
$icon_arr Page next ^ 1 ^ sxmo_type ':n' -k Return
$icon_arr Page next ^ 1 ^ sxmo_type ':n' -k Return
@ -375,7 +375,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = less
WINNAME = less
elif echo " $WMNAME " | grep -i -w "weechat" ; then
elif printf %s " $WMNAME " | grep -q i -w "weechat" ; then
#weechat
#weechat
CHOICES = "
CHOICES = "
$icon_msg Hotlist Next ^ 1 ^ sxmo_type -M Alt a
$icon_msg Hotlist Next ^ 1 ^ sxmo_type -M Alt a
@ -387,8 +387,8 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = weechat
WINNAME = weechat
elif echo " $WMNAME " | grep -i -w "sms" ; then
elif printf %s " $WMNAME " | grep -q i -w "sms" ; then
number = " $( echo " $WMNAME " | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ' ) "
number = " $( printf %s " $WMNAME " | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ' ) "
#sms
#sms
CHOICES = "
CHOICES = "
$icon_msg Reply ^ 0 ^ sxmo_modemtext.sh sendtextmenu $number
$icon_msg Reply ^ 0 ^ sxmo_modemtext.sh sendtextmenu $number
@ -398,7 +398,7 @@ programchoicesinit() {
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
$icon_mnu Terminal menu ^ 0 ^ sxmo_appmenu.sh $WMCLASS
"
"
WINNAME = sms
WINNAME = sms
elif echo " $WMNAME " | grep -i -w "cmus" ; then
elif printf %s " $WMNAME " | grep -q i -w "cmus" ; then
# cmus
# cmus
# requires `:set set_term_title=false` in cmus to match the application
# requires `:set set_term_title=false` in cmus to match the application
CHOICES = "
CHOICES = "
@ -417,7 +417,7 @@ programchoicesinit() {
case " $WMCLASS " in
case " $WMCLASS " in
*st*)
*st*)
STSELMODEON = " $(
STSELMODEON = " $(
echo " $XPROPOUT " | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' '
printf %s " $XPROPOUT " | grep -E '^_ST_SELMODE.+=' | cut -d= -f2 | tr -d ' '
) "
) "
CHOICES = "
CHOICES = "
$icon_itm Type complete ^ 0 ^ sxmo_type -M Ctrl -M Shift -k u
$icon_itm Type complete ^ 0 ^ sxmo_type -M Ctrl -M Shift -k u
@ -544,7 +544,7 @@ programchoicesinit() {
$icon_phn Dialer ^ 0 ^ sxmo_modemdial.sh
$icon_phn Dialer ^ 0 ^ sxmo_modemdial.sh
$icon_msg Texts ^ 0 ^ sxmo_modemtext.sh
$icon_msg Texts ^ 0 ^ sxmo_modemtext.sh
$icon_usr Contacts ^ 0 ^ sxmo_contactmenu.sh
$icon_usr Contacts ^ 0 ^ sxmo_contactmenu.sh
$( command -v bluetoothctl >/dev/null && echo " $icon_bth Bluetooth ^ 0 ^ sxmo_bluetoothmenu.sh " )
$( command -v bluetoothctl >/dev/null && echo " $icon_bth Bluetooth ^ 1 ^ sxmo_bluetoothmenu.sh " )
$( command -v megapixels >/dev/null && echo " $icon_cam Camera ^ 0 ^ GDK_SCALE=2 megapixels " )
$( command -v megapixels >/dev/null && echo " $icon_cam Camera ^ 0 ^ GDK_SCALE=2 megapixels " )
$icon_net Networks ^ 0 ^ sxmo_networks.sh
$icon_net Networks ^ 0 ^ sxmo_networks.sh
$icon_mus Audio ^ 0 ^ sxmo_appmenu.sh audioout
$icon_mus Audio ^ 0 ^ sxmo_appmenu.sh audioout
@ -584,7 +584,7 @@ getprogchoices() {
done
done
# Decorate menu at bottom w/ system menu entry if not system menu
# Decorate menu at bottom w/ system menu entry if not system menu
echo $WINNAME | grep -v Sys && CHOICES = "
echo $WINNAME | grep -q v Sys && CHOICES = "
$CHOICES
$CHOICES
$icon_mnu System Menu ^ 0 ^ sxmo_appmenu.sh sys
$icon_mnu System Menu ^ 0 ^ sxmo_appmenu.sh sys
"
"
@ -595,7 +595,7 @@ getprogchoices() {
$icon_cls Close Menu ^ 0 ^ quit
$icon_cls Close Menu ^ 0 ^ quit
"
"
PROG CHOICES= " $( echo " $CHOICES " | xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' ) "
CHOICES = " $( printf "%s\n" " $CHOICES " | xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' ) "
}
}
quit( ) {
quit( ) {
@ -603,26 +603,25 @@ quit() {
}
}
mainloop( ) {
mainloop( ) {
getprogchoices " $ARGS "
getprogchoices " $@ "
echo " $PROGCHOICES " |
PICKED = " $(
printf "%s\n" " $CHOICES " |
cut -d'^' -f1 |
cut -d'^' -f1 |
dmenu -i -p " $WINNAME " | (
sxmo_dmenu.sh -i -p " $WINNAME "
PICKED = " $( cat) "
) " || quit
echo " $PICKED " | grep . || quit
LOOP = " $( printf "%s\n" " $CHOICES " | grep -m1 -F " $PICKED " | cut -d '^' -f2) "
LOOP = " $( echo " $PROGCHOICES " | grep -m1 -F " $PICKED " | cut -d '^' -f2) "
CMD = " $( printf "%s\n" " $CHOICES " | grep -m1 -F " $PICKED " | cut -d '^' -f3) "
CMD = " $( echo " $PROGCHOICES " | grep -m1 -F " $PICKED " | cut -d '^' -f3) "
echo " sxmo_appmenu: Eval: < $CMD > from picked < $PICKED > with loop < $LOOP > " >& 2
printf "%s\n" " sxmo_appmenu: Eval: < $CMD > from picked < $PICKED > with loop < $LOOP > " >& 2
if echo " $LOOP " | grep 1; then
if printf %s " $LOOP " | grep -q 1; then
eval " $CMD "
eval " $CMD "
mainloop
mainloop
else
else
eval " $CMD " &
eval " $CMD " &
wait
quit
quit
fi
fi
) & wait
}
}
pgrep -f " $( command -v sxmo_appmenu.sh) " | grep -Ev " ^ ${ $} $" | xargs -r kill -TERM
mainloop " $@ "
PICKED = ""
ARGS = " $* "
mainloop