#!/bin/bash
# jgdeskmngr - pipemenu for deskmngr
#
case $LANG in
pl*)
REMOVE="Usuń to menu z panelu"
;;
es*)
REMOVE="Eliminar este menú del panel"
;;
*)
REMOVE="Remove this menu from panel"
;;
esac
SESSIONDIR="$HOME/.config/deskmngr/"
mkdir -p $SESSIONDIR
out+=("^sep(Desktop session Manager)")
out+=("^sep(Saved sessions )")
i="0"
while IFS= read -r line
do
name=$(basename $line .desk)
out+=(" ${name//_/ },^checkout(sess${i})")
out2+=("^tag(sess${i})")
out2+=("^sep(Restore to desktop...)")
while IFS= read -r linia || [ -n "$linia" ];
do read -r ID dname< <(echo $linia)
dname=$(wmctrl -d | grep ^${ID} | cut -d' ' -f13-)
out2+=("\"\"\" ${dname/&/&}\"\"\",deskmngr -r $name.desk $ID")
done < <(wmctrl -d|awk '{print $1}')
out2+=("^sep()" " Edit session: ${name//_/ },geany $SESSIONDIR$name.desk")
out2+=("^sep()" " Delete session: ${name//_/ },rm -f $SESSIONDIR$name.desk")
((i=i+1))
done < <(deskmngr -l)
out+=("^sep()" " Open config directory,pcmanfm ~/.config/deskmngr/")
out+=("^sep(Add new...)")
out+=(" New session from current desktop as ...,deskmngr -s")
### RUN
if [ $1 == "-s" ]; then
. /usr/bin/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
MENU_PADDING_TOP=0
MENU_HALIGN="center"
MENU_VALIGN="center"
jgmenu_icon_size=0
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
mkconfigfile
cat << EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
if [[ $1 == "-r" ]]; then
printf '%s\n' "^sep()"
printf '%s\n' "$REMOVE,mb-setvar places_jgdeskmngr=false;mb-jgtools places"
fi
printf '%s\n' "${out2[@]}"