mabox-pipemenus/usr/bin/mabox-conky-pipemenu

138 lines
4.0 KiB
Plaintext
Raw Normal View History

2016-03-26 10:18:26 +01:00
#!/bin/bash
# mabox-conky-pipemenu - an Openbox pipemenu for manipulating conky
# Copyright (C) 2015 damo <damo@bunsenlabs.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
MB_COMMON_LIBDIR='/usr/lib/mabox/mabox-common'
CONKYDEFAULT="$HOME/.conkyrc"
CONKYPATH="$HOME/.config/conky"
CSESSIONFILE="$CONKYPATH/conky-sessionfile"
SESSIONS="$CONKYPATH/saved-sessions"
CZEN="mb-conkyzen"
CSESSION="mb-conky-session"
HELPFILE="/usr/share/mabox/mabox-docs/helpfile-conkyzen.txt"
if ! . "$MB_COMMON_LIBDIR/mabox-include.cfg" 2> /dev/null; then
echo "Error: Failed to source mb-include.cfg in $MB_COMMON_LIBDIR" >&2
exit 1
fi
if [ ! -e "$CSESSIONFILE" ] 2> /dev/null ; then
echo "Error: Failed to locate conky-sessionfile in $CONKYPATH" >&2
echo "conky -c $HOME/.conkyrc & sleep 1" > "$CSESSIONFILE"
fi
if [ ! -e "$SESSIONS" ] 2> /dev/null ; then
echo "$0: Failed to locate saved-sessions in $CONKYPATH" >&2
fi
declareDependencies yad
getSessions(){ # read any saved sessions from save-sessions file
menuItem "Default" "$CSESSION $CSESSIONFILE"
if [ -e "$SESSIONS" ]
then
while read -r session ;do
[[ -z $session ]] && continue # skip if line is blank
menuItem "$session" "$CSESSION $session"
done < "$SESSIONS"
else
echo "$0: Failed to locate saved-sessions in $CONKYPATH" >&2
fi
}
loadChooserMenu(){
if type "$CZEN" &>/dev/null;then # mb-conkyzen script found
menuItem "Conky Chooser" "$CZEN"
fi
}
loadNewsessionMenu(){
if type "$CZEN" &>/dev/null;then # mb-conkyzen script found
menuItem "New Conky Session" "$CZEN -z"
fi
}
loadReloadMenu(){
if type "$CSESSION" &>/dev/null;then # mb-conky-session script found
menuItem "Reload Conkys" "$CSESSION"
fi
}
loadSavedsessionSubmenu(){
if type "$CSESSION" &>/dev/null;then # mb-conky-session script found
menuSubmenu "Sessions" "Saved Sessions"
getSessions
menuSubmenuEnd
fi
}
loadPinMenu(){
if type mb-conkypin &>/dev/null;then
menuItem "Pin moveable Conkys" "mb-conkypin"
menuSeparator
fi
}
loadEditMenu(){
menuItem "Default conkyrc" "geany $CONKYDEFAULT"
if [[ $(pidof conky) ]];then
menuSubmenu "RunningConky" "Running Conkys"
while read -r session ;do # get running conkys from sessionfile
[[ -z $session ]] && continue
CPATH=$(echo "$session" | awk '{print $3}')
CONKY=$(echo "$CPATH" | awk -F"/" '{print $(NF-1)"/"$NF }')
menuItem "$CONKY" "geany $CPATH"
done < "$CSESSIONFILE"
menuSubmenuEnd
else
menuItem "No Running Conkys"
fi
}
getConkys(){
menuSubmenu "EditConky" "Edit Conkys"
if type mb-conkyedit &>/dev/null;then # mb-conkyedit script found
menuItem "Conky Editor" "mb-conkyedit"
loadEditMenu
else
loadEditMenu
fi
menuSubmenuEnd
}
checkHelpfile(){
DLG="yad --text-info --center --borders=20 \
--title='BunsenLabs Conky Manager Help' \
--window-icon=distributor-logo-bunsenlabs \
--filename=$HELPFILE --fontname=Monospace \
--width=650 --height=700 \
--button=OK:0"
if [[ -e $HELPFILE ]];then
menuItem "Conky Manager Help" "$DLG"
fi
}
menuStart "Conkymenu" "Conky"
loadChooserMenu
loadReloadMenu
getConkys
menuSeparator
loadPinMenu
loadNewsessionMenu
loadSavedsessionSubmenu
menuSeparator
checkHelpfile
menuEnd