mabox-pipemenus/usr/bin/jgdeskmngr

157 lines
4.9 KiB
Plaintext
Raw Normal View History

2021-05-18 16:48:04 +02:00
#!/bin/bash
2022-12-11 14:08:20 +01:00
# jgdeskmngr - pipemenu (or standalone dynamic menu) for deskmngr
2021-05-18 16:48:04 +02:00
#
2021-05-22 02:00:30 +02:00
2022-02-12 23:20:57 +01:00
SESSIONDIR="$HOME/.config/deskmngr/"
CONFIG_FILE="$SESSIONDIR/deskmngr.conf"
mkdir -p $SESSIONDIR
# If config file not exist create one with defaults
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
waitsec=1
EOF
fi
source <(grep = $CONFIG_FILE)
waittime=${waitsec:-1}
2021-05-22 02:00:30 +02:00
case $LANG in
pl*)
REMOVE="Usuń to menu z panelu"
2021-05-31 15:00:35 +02:00
DESKMNGR="Menadżer sesji desktopowych"
ABOUT="O DeskMngr"
SAVED_SESS="Zapisane sesje"
RESTORE_TO="Przywróć na pulpit..."
2021-10-11 09:28:30 +02:00
OVERWRITE="<b>Nadpisz</b> sesję:"
2021-05-31 15:00:35 +02:00
EDIT="<b>Edytuj</b> sesję:"
DELETE="<b>Usuń</b> sesję:"
OPEN_CNFDIR="Otwórz katalog z sesjami"
ADD="Dodaj nową..."
NEW="<b>Nowa</b> sesja z bieżącego pulpitu jako..."
2022-02-12 23:20:57 +01:00
SETTINGS="Ustawienia"
INTERVAL="Interwał"
2021-05-31 15:00:35 +02:00
title="DeskMngr - zapisuje i przywraca sesje"
help='\nZapisuje rozmiar i pozycję wszystkich okien z bieżącego pulpitu.\n\nSesję możesz otworzyć poźniej na dowolnym pulpicie.\n\n'
2021-06-03 14:06:57 +02:00
LEFTPANEL="Lewy panel"
2021-05-22 02:00:30 +02:00
;;
es*)
REMOVE="Eliminar este menú del panel"
2021-05-31 15:00:35 +02:00
DESKMNGR="Desktop session Manager"
ABOUT="About DeskMngr"
SAVED_SESS="Saved sessions"
RESTORE_TO="Restore to desktop..."
2021-10-11 09:28:30 +02:00
OVERWRITE="<b>Overwrite</b> session:"
2021-05-31 15:00:35 +02:00
EDIT="<b>Edit</b> session:"
DELETE="<b>Delete</b> session:"
OPEN_CNFDIR="Open config directory"
ADD="Add new..."
NEW="<b>New</b> session from current desktop as..."
2022-02-12 23:20:57 +01:00
SETTINGS="Settings"
INTERVAL="Interval"
2021-05-31 15:00:35 +02:00
title="DeskMngr - save and restore sessions"
help='\nSave all opened windows from active desktop as session.\n\nRestore saved session later on desktop of your choice.\n\n'
2021-06-03 14:06:57 +02:00
LEFTPANEL="Left panel"
2021-05-22 02:00:30 +02:00
;;
*)
REMOVE="Remove this menu from panel"
2021-05-31 15:00:35 +02:00
DESKMNGR="Desktop session Manager"
ABOUT="About DeskMngr"
SAVED_SESS="Saved sessions"
RESTORE_TO="Restore to desktop..."
2021-10-11 09:28:30 +02:00
OVERWRITE="<b>Overwrite</b> session:"
2021-05-31 15:00:35 +02:00
EDIT="<b>Edit</b> session:"
DELETE="<b>Delete</b> session:"
OPEN_CNFDIR="Open config directory"
ADD="Add new..."
NEW="<b>New</b> session from current desktop as..."
2022-02-12 23:20:57 +01:00
SETTINGS="Settings"
INTERVAL="Interval"
2021-05-31 15:00:35 +02:00
title="DeskMngr - save and restore sessions"
help='\nSave all opened windows from active desktop as session.\nRestore saved session later on desktop of your choice.\n\n'
2021-06-03 14:06:57 +02:00
LEFTPANEL="Left panel"
2021-05-22 02:00:30 +02:00
;;
esac
2021-06-03 14:06:57 +02:00
me="jgdeskmngr -s"
2021-05-18 16:48:04 +02:00
SESSIONDIR="$HOME/.config/deskmngr/"
mkdir -p $SESSIONDIR
2021-05-31 15:00:35 +02:00
out+=("^sep($DESKMNGR)")
2023-05-18 16:05:29 +02:00
out+=("<big></big> $ABOUT,\"\"\"notify-send.sh -u critical -i mbcc '$title' '$help';$me\"\"\"")
2022-02-12 23:20:57 +01:00
2021-05-31 15:00:35 +02:00
out+=("^sep(<i><small>$SAVED_SESS</small></i>)")
2021-05-18 16:48:04 +02:00
i="0"
while IFS= read -r line
do
name=$(basename $line .desk)
2021-06-09 12:25:27 +02:00
out+=(" ${name//_/ },^checkout(sess${i})")
2021-05-18 16:48:04 +02:00
out2+=("^tag(sess${i})")
2021-05-31 15:00:35 +02:00
out2+=("^sep($RESTORE_TO)")
2021-05-18 16:48:04 +02:00
while IFS= read -r linia || [ -n "$linia" ];
do read -r ID dname< <(echo $linia)
dname=$(wmctrl -d | grep ^${ID} | cut -d' ' -f13-)
2021-06-09 12:25:27 +02:00
out2+=("\"\"\" ${dname/&/&amp;}\"\"\",deskmngr -r $name.desk $ID")
2021-05-18 16:48:04 +02:00
done < <(wmctrl -d|awk '{print $1}')
2021-10-11 09:28:30 +02:00
out2+=("^sep()" "  $OVERWRITE <b>${name//_/ }</b>,deskmngr save $name")
2022-08-17 14:19:31 +02:00
out2+=("^sep()" "  $EDIT <b>${name//_/ }</b>,xdg-open $SESSIONDIR$name.desk")
2021-06-03 14:06:57 +02:00
out2+=("^sep()" "  $DELETE <b>${name//_/ }</b>,rm -f $SESSIONDIR$name.desk;$me")
2021-05-18 16:48:04 +02:00
((i=i+1))
done < <(deskmngr -l)
2021-06-09 12:25:27 +02:00
out+=("^sep()" " $OPEN_CNFDIR,pcmanfm ~/.config/deskmngr/")
2021-05-31 15:00:35 +02:00
out+=("^sep(<i><small>$ADD</small></i>)")
out+=("  $NEW,deskmngr -s")
2022-02-12 23:20:57 +01:00
out+=("^sep($SETTINGS)")
out+=("$INTERVAL: <b>[ $waittime ]</b> ,^checkout(time)")
out2+=("^tag(time)")
out2+=("^sep($INTERVAL)")
for i in 1 2 3 4 5; do out2+=("$(printf "<tt>%3s</tt>,%s" "$i" "mb-setvar waitsec=${i} $CONFIG_FILE;$me")");done
2021-05-18 16:48:04 +02:00
### RUN
2022-12-11 14:08:20 +01:00
if [ "$1" == "-s" ]; then
2021-09-24 01:40:09 +02:00
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
2021-05-18 16:48:04 +02:00
. $HOME/.config/mabox/mabox.conf
2021-06-03 14:06:57 +02:00
out+=("^sep()")
2024-02-25 23:07:28 +01:00
out+=("  $LEFTPANEL,mb-jgtools places")
2021-06-03 14:06:57 +02:00
if [[ $panels_heightpos == "top" ]]; then
MENU_VALIGN="top"
MENU_MARGIN_Y=${panels_topmargin:-0}
elif [[ $panels_heightpos == "bottom" ]]; then
MENU_VALIGN="bottom"
MENU_MARGIN_Y=${panels_topmargin:-0}
else
MENU_VALIGN="center"
fi
2021-05-31 15:00:35 +02:00
MENU_PADDING_TOP=${jgtools_padding:-0}
MENU_HALIGN="left"
2021-05-18 16:48:04 +02:00
jgmenu_icon_size=0
menu_margin_x=${submenu_spacing:-0}
2021-05-18 16:48:04 +02:00
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
mkconfigfile
2021-05-21 23:15:53 +02:00
cat << EOF > ${MENU_ITEMS}
2021-05-18 16:48:04 +02:00
$(printf '%s\n' "${out[@]}")
2022-12-11 14:08:20 +01:00
. ~/.config/mabox/jgdeskmngr.csv
2021-05-18 16:48:04 +02:00
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
2022-12-11 14:08:20 +01:00
cat ~/.config/mabox/jgdeskmngr.csv
2021-05-18 16:48:04 +02:00
if [[ $1 == "-r" ]]; then
printf '%s\n' "^sep()"
2021-05-23 10:20:13 +02:00
printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_jgdeskmngr=false;mb-jgtools places"
2021-05-18 16:48:04 +02:00
fi
2022-12-11 14:08:20 +01:00
2021-05-18 16:48:04 +02:00
printf '%s\n' "${out2[@]}"