conky/tint2 manager updated from Bunsenlabs

master
Daniel Napora 2020-08-29 10:04:06 +02:00
parent 346120347c
commit a28558bc1d
5 changed files with 601 additions and 486 deletions

View File

@ -0,0 +1,355 @@
#!/bin/bash
#
# bl-conky-manager: BunsenLabs Conky selection and switcher script
# Copyright (C) 2015-2019 damo <damo@bunsenlabs.org>
# 2019-2020 John Crawley <john@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/>.
#
########################################################################
#
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
# Beta tested and stamped "zen" by <Sector11>
#
# Adapted, rapackaged for Mabox by napcok <napcok@gmail.com>, August 2020
#
########################################################################
#
# Conkys must be in $CONKYPATH
# The name must end with "conky", conkyrc or be "*conky*.conf"
#
# When the dialog opens, any running conkys will be checkmarked.
#
# Click "OK" and all running conkys are stopped, and all checkmarked
# conkys are started
#
# To stop a conky just uncheck it, and "OK"
#
# Running conkys are saved to a session file, and can be run with
# the "bl-conky-session" script. To start the default conky session at
# login, add the following line to autostart:
#
# mb-conky-session --autostart &
#
# Different saved-session files can be used by running the script with:
#
# mb-conky-manager -f /path/to/sessionfile &
# mb-conky-manager -z (opens gui entry dialog for filepath)
#
########################################################################
CONKYPATH="$HOME/.config/conky"
SESSIONFILE="$CONKYPATH/conky-sessionfile"
SESSIONS="$CONKYPATH/saved-sessions" # to be used by a pipemenu
CONKYDEFAULT="$CONKYPATH/conky.conf"
BLDEFAULT="$CONKYPATH/manjaro_JWM.conkyrc"
USAGE1='
USAGE: mb-conky-manager [OPTION]...FILES
With no command option the script runs the gui
-h,--help : The full USAGE help
-f,--file : FILEPATH : specify file to save session to
-z : Run gui filename entry dialog for new saved session
'
USAGE2='mb-conky-manager is a Conky selection and switcher script
which uses yad to generate a graphical user interface.
Usage: mb-conky-manager [OPTION]...FILES
With no command option the script runs the gui
Optional arguments:
-h,--help : This USAGE help
-f,--file : FILEPATH : specify file to save session to
-z : Run gui filename entry dialog for new saved session
When the dialog opens, any running conkys will be checkmarked.
Click "OK" and all running conkys are stopped, and all
checkmarked conkys are started.
To stop a conky just uncheck it, and click "OK"
Examples:
Save session to a new saved-session file with:
mb-conky-manager -f sessionfile-name
To start the default conky session at login, add the
following line to autostart:
mb-conky-session --autostart &
'
### DIALOG VARIABLES
case $LANG in
pl*)
TITLE="Menedżer Conky"
CONKY_SESSIONFILE="Plik sesji Conky"
FILENAME_IN_USE="Nazwa pliku już jest używana.\n\nNadpisać?"
SAVE_SESSION="Zapisz sesję Conky"
NEW_FILE="Nowy plik zapisanej sesji:"
FILE_TO_SAVE="Plik do zapisania w <b>$CONKYPATH/</b>\n\n"
SESS_SAVE="Wybierz pliki Conky, które mają być uruchomione.\nSesja zostanie zachowana w:\n <i>$SESSIONFILE</i>"
SELECT="Wybór:CHK"
CONF_FILE="Plik konfiguracyjny:TXT"
NOTHING_SELECTED="Nic nie wybrano.\n\nWyłączyć działające Conky\ni wyjść?"
OK="--button=OK:2"
APPLY="--button=Zastosuj:0"
CANCEL="--button=Anuluj:1"
CLOSE="--button=Zamknij:1"
;;
*)
TITLE="Conky Manager"
CONKY_SESSIONFILE="Conky sessionfile"
FILENAME_IN_USE="Filename already in use\n\nOverwrite it?"
SAVE_SESSION="Save Conky sessionfile"
NEW_FILE="New saved session file:"
FILE_TO_SAVE="File to be saved in <b>$CONKYPATH/</b>\n\n"
SESS_SAVE="Choose Conky file, which you like to start.\nSession will be saved to:\n <i>$SESSIONFILE</i>"
SELECT="Select:CHK"
CONF_FILE="Conky Name:TXT"
NOTHING_SELECTED="Nothing chosen.\n\nKill any running Conkys\nand exit?"
OK="--button=OK:2"
APPLY="--button=Apply:0"
CANCEL="--button=Cancel:1"
CLOSE="--button=Close:1"
;;
esac
DLG="yad --center --undecorated --borders=20 "
DLGDEC="yad --center --borders=20 "
WINICON="--window-icon=distributor-logo-mabox --image=conky"
########## FUNCTIONS ###################################################
CPATH_REGEX='.*(conky.*\.conf|conky|\.conkyrc)'
getRunning(){
local pid cmd args CPATH
while read -r pid cmd args; do
if [[ $args =~ (-c |--config=)($CPATH_REGEX) ]]; then
CPATH=${BASH_REMATCH[2]}
[[ $CPATH = "$HOME"/* ]] || CPATH="$HOME/$CPATH"
else
CPATH=$CONKYDEFAULT
fi
[[ -f $CPATH ]] || {
echo "$0: pgrep conky parsing failed: $CPATH not a file" >&2
continue
}
runningConkys+=("$CPATH")
done < <(pgrep -ax conky)
}
# $1 holds full path to config file
# return 0 if a running conky is using that file
isRunning(){
local file=$1
for running in "${runningConkys[@]}"
do
[[ $running = "$file" ]] && return 0
done
return 1
}
fillArrays(){
local num
num="$1" # 1st arg: array index
conkysPath[$num]="$2" # full filepath
conkysArr[$num]="$3" # displayed name
if isRunning "$2"; then
checkArr[$num]="TRUE" # make checkmark in dialog
else
checkArr[$num]="FALSE"
fi
}
findConky(){
local file num display
num=0
shopt -s globstar
for file in "$CONKYPATH"/**;do
[[ -f $file ]] || continue
[[ $file =~ ${CPATH_REGEX}$ ]] || continue # ignore other than conky config files
display=${file#$CONKYPATH/}
fillArrays $num "$file" "$display"
num=$((num+1))
done
shopt -u globstar
}
writeSessions(){ # save a new sessionfile name for use by a menu
SESSIONFILE="$CONKYPATH/$1"
echo "sessionfile= $SESSIONFILE"
if ! [[ -f $SESSIONS ]];then
:> "$SESSIONS"
fi
if grep -qx "$SESSIONFILE" "$SESSIONS";then # session was previously saved
if [[ $2 = "-z" ]];then # input was from input dialog, so ask OK?
$DLG $WINICON --title="$CONKY_SESSIONFILE" --text="$FILENAME_IN_USE" $CANCEL $OK
if (( $? == 1 ));then
exit 0
fi
else # commandline is being used
echo "Session was previously saved with the same name. Overwrite it? (y|N)"
read -r ans
case "$ans" in
y|Y ) : #break
;;
* ) exit 0
;;
esac
fi
fi
cp "$SESSIONS" "$SESSIONS.bkp"
echo "$SESSIONFILE" >> "$SESSIONS"
}
loadDialog() {
local -a retConky
## Populate dialog from array, get return value(s)
RET=$($DLGDEC $WINICON --list --title="$TITLE" \
--text="$SESS_SAVE" \
--checklist --width=400 --height=500 --multiple \
--column="$SELECT" --column="$CONF_FILE" "${LISTCONKY[@]}" \
--separator=":" \
$APPLY $CLOSE \
)
# For OK button, add to last line of yad command:
# $APPLY $OK $CLOSE \
retval=$?
if (( retval == 1 )); then # close button pressed
# if session file is empty remove it, and restore previous saved-sessions file
if [[ ! -s "$SESSIONFILE" ]];then
rm "$SESSIONFILE"
if [[ -f $SESSIONS.bkp ]]; then
mv "$SESSIONS.bkp" "$SESSIONS"
fi
fi
exit 0
fi
if ! [[ $RET ]];then # No conkys chosen
MSG="$NOTHING_SELECTED"
$DLG $WINICON --title="$TITLE" --text="$MSG" $OK $CANCEL
if [[ $? = 1 ]];then
return
fi
fi
# loop through returned choices, add to array
i=0
OIFS=$IFS # save Internal Field Separator
IFS=":" # separator is ":" in returned choices
for name in $RET; do
retConky[$i]="$name"
i=$((i+1))
done
IFS=$OIFS # reset IFS back to default
# kill all conkys
if [[ $(pidof conky) ]];then
killall conky
fi
:> "$SESSIONFILE" # Create empty session file
# Find the chosen conkys and start them
for name in "${retConky[@]}";do # loop through checkmarked conky names
for ((j=0; j<${#conkysPath[*]}; j++));do
file=${conkysPath[j]}
display=${conkysArr[j]}
# compare with choice from dialog
if [[ $display = "$name" ]];then
echo "conky -c '$file' & sleep 1s" >> "$SESSIONFILE"
set -m # enable job control so forked conky is immune to signals
#start the conky (adjust the sleep time if required)
conky -c "$file" >/dev/null 2>&1 &
disown
set +m
sleep 1s
fi
done
done
# if there is an $OK button that returns 2, it will apply changes and exit
(( retval == 2 )) && exit 0
}
######## END FUNCTIONS #################################################
# get args passed to script (session can be saved to a different file)
while [[ -n $1 ]];do
case "$1" in
-h|--help ) echo -e "$USAGE2"
echo
exit 0
;;
-f|--files ) if [[ -n $2 ]];then
SESSIONFILE="$2" # sessionfile has been specified
writeSessions "$SESSIONFILE" # if sessionfile is new, write name to saved-sessions
break
else
echo
echo -e "\tNo saved-session file specified!"
echo -e "$USAGE1"
echo
exit 1
fi
;;
-z ) SPATH=$($DLGDEC $WINICON --entry \
--title="Save Conky sessionfile" \
--entry-label="New saved session file:" \
--text="File to be saved in <b>$CONKYPATH/</b>\n\n" \
$OK $CANCEL \
)
(( $? == 1 )) && exit 0
if [[ -z $SPATH ]];then # entry was empty
$DLG $WINICON --title="Conky sessionfile" --text="No file specified for new saved session\n\nExiting..." $OK
exit 1
else
writeSessions "$SPATH" "-z" # saved session file from input dialog
break
fi
;;
* ) echo -e "$USAGE1"
exit 1
;;
esac
shift
done
# test for ~/.config/conky/conky.conf, create a link to the default conky if necessary
if ! [[ -e $CONKYDEFAULT ]];then
if [[ -e $BLDEFAULT ]];then
ln -s "$BLDEFAULT" "$CONKYDEFAULT"
else
echo "Default conky.conf not found"
fi
fi
while true;do
runningConkys=()
getRunning
# get conky directories in .conky, add to array
findConky
LISTCONKY=()
# loop through arrays, and build list text for yad dialog
for ((j=0; j<${#conkysArr[*]}; j++));do
LISTCONKY+=("${checkArr[j]}" "${conkysArr[j]}")
done
loadDialog # LISTCONKY is global array
done
exit 0

View File

@ -1,316 +0,0 @@
#!/bin/bash
#
# BunsenLabs Conky selection and switcher script
#
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
# Beta tested and stamped "zen" by <Sector11>
# Rapackaged for Manjaro by napcok <napcok@gmail.com>, March 2016
#
########################################################################
#
# Conkys must be in $CONKYPATH
# The name must end with "conky" or "conkyrc"
#
# When the dialog opens, any running conkys will be checkmarked.
#
# Click "OK" and all running conkys are stopped, and all checkmarked
# conkys are started
#
# To stop a conky just uncheck it, and "OK"
#
# Running conkys are saved to a session file, and can be run with
# the "bl-conky-session" script. To start the default conky session at
# login, add the following line to autostart:
#
# (sleep 2s && bl-conky-session --autostart) &
#
# Different saved-session files can be used by running the script with:
#
# bl-conkyzen -f /path/to/sessionfile &
# bl-conkyzen -z (opens gui entry dialog for filepath)
#
########################################################################
CONKYPATH="$HOME/.config/conky"
SESSIONFILE="$CONKYPATH/conky-sessionfile"
SESSIONS="$CONKYPATH/saved-sessions" # to be used by a pipemenu
CRC="$HOME/.conkyrc"
BLDEFAULT="$CONKYPATH/MB-Default.conkyrc"
USAGE1="\v\tUSAGE:\tmb-conkyzen [OPTION]...FILES
\v\tWith no command option the script runs the gui
\v\t-h,--help : this USAGE help
\t-f,--file : FILEPATH : specify file to save session to
\t-z : Run gui filename entry dialog for new saved session"
USAGE2="\v\tUSAGE:\tmb-conkyzen [OPTION]...FILES
\v\tWith no command option the script runs the gui
\v\t-h,--help : this USAGE help
\t-f,--file : FILEPATH : specify file to save session to
\t-z : Run gui filename entry dialog for new saved session
\v\tWhen the dialog opens, any running conkys will be checkmarked.
\tClick \"OK\" and all running conkys are stopped, and all
\tcheckmarked conkys are started.
\v\tTo stop a conky just uncheck it, and \"OK\"
\v\tEXAMPLES:
\tSave session to a new saved-session file with:
\v\t\tbl-conkyzen -f sessionfile-name
\v\tTo start the default conky session at login, add the
\tfollowing line to autostart:
\v\t\t(sleep 2s && mb-conky-session --autostart) &\v"
### DIALOG VARIABLES
case $LANG in
pl*)
TITLE="Menedżer Conky"
CANCEL="--button=Anuluj:1"
CONKY_SESSIONFILE="Plik sesji Conky"
FILENAME_IN_USE="Nazwa pliku już jest używana.\n\nNadpisać?"
SAVE_SESSION="Zapisz sesję Conky"
NEW_FILE="Nowy plik zapisanej sesji:"
FILE_TO_SAVE="Plik do zapisania w <b>$CONKYPATH/</b>\n\n"
SESS_SAVE="Wybierz pliki Conky, które mają być uruchomione.\nSesja zostanie zachowana w:\n <i>$SESSIONFILE</i>"
SELECT="Wybór:CHK"
CONF_FILE="Plik konfiguracyjny:TXT"
NOTHING_SELECTED="Nic nie wybrano.\n\nWyłączyć działające Conky\ni wyjść?"
;;
*)
TITLE="Conky Manager"
CANCEL="--button=Cancel:1"
CONKY_SESSIONFILE="Conky sessionfile"
FILENAME_IN_USE="Filename already in use\n\nOverwrite it?"
SAVE_SESSION="Save Conky sessionfile"
NEW_FILE="New saved session file:"
FILE_TO_SAVE="File to be saved in <b>$CONKYPATH/</b>\n\n"
SESS_SAVE="Choose Conky file, which you like to start.\nSession will be saved to:\n <i>$SESSIONFILE</i>"
SELECT="Select:CHK"
CONF_FILE="Conky Name:TXT"
NOTHING_SELECTED="Nothing chosen.\n\nKill any running Conkys\nand exit?"
;;
esac
DLG="yad --center --undecorated --borders=20 --image=conky "
DLGDEC="yad --center --borders=20 "
WINICON="--window-icon=distributor-logo-mabox --image=conky "
OK="--button=OK:0"
########## FUNCTIONS ###################################################
conkyRunning(){ # find running conkys
# make blank tempfile, to save running conky paths
TEMPFILE=$(mktemp --tmpdir conky.XXXX)
if [[ $(pidof conky) ]];then
# test if default conky was started
for ARG in $(ps aux | grep [c]onky | awk '{print $(NF-1)}');do
if [[ $ARG = "conky" ]]; then
echo "$CRC" >> "$TEMPFILE" # 'conky -q' probably used
else # send conky filepath to tempfile
for ARG in $(ps aux | grep [c]onkyrc | awk '{print $(NF)}');do
if [[ $ARG != "-q" ]];then
echo "$ARG" >> "$TEMPFILE"
fi
done
fi
done
fi
# remove any duplicates in tempfile
TEMPFILE2=$(mktemp --tmpdir conky.XXXX)
awk '!x[$0]++' "$TEMPFILE" > "$TEMPFILE2" && mv "$TEMPFILE2" "$TEMPFILE"
}
fillArrays(){
if (( $1 != 0 ));then
num="$1" # 1st arg: array index
else
num=0 # '~/.conkyrc' added to array
fi
if (( $num == 0 ));then
cPATH="$CRC"
cARR="$USER/.conkyrc"
else
cPATH="$2" # 2nd arg: full filepath to conky
cARR="$3" # 3rd arg: displayed name: "directory/*conky(rc)"
fi
conkysPath[$num]="$cPATH"
conkysArr[$num]="$cARR"
if grep -qx "$cPATH" "$TEMPFILE";then # if conky is running (read from tempfile)
checkArr[$num]="TRUE" # make checkmark in dialog
else
checkArr[$num]="FALSE"
fi
}
findConky(){
# search dirs for conkys files - looking for "conky" in the name
# if "*conky(rc)" then display it
num=0 # added default .conkyrc
fillArrays $num "$CRC" "$USER/.conkyrc"
num=1
# find files in CONKYPATH with conky in the name
for x in $(find "$CONKYPATH" -type f );do
f=$(basename "$x") # filename from filepath
if [[ $f = *conkyrc ]] || [[ $f = *conky ]];then # filename ends with *conky or *conkyrc
# get directory/conkyname to display in list
CONKY=$( echo "$x" | awk -F"/" '{print $(NF-1)"/"$NF}')
fillArrays $num "$x" "$CONKY"
num=$(($num+1))
fi
done
}
writeSessions(){ # save a new sessionfile name for use by a menu
SESSIONFILE="$CONKYPATH/$1"
echo "sessionfile= $SESSIONFILE"
if ! [[ -f $SESSIONS ]];then
> "$SESSIONS"
fi
if grep -qx "$SESSIONFILE" "$SESSIONS";then # session was previously saved
if [[ $2 = "-z" ]];then # input was from input dialog, so ask OK?
$DLG $WINICON --title="$CONKY_SESSIONFILE" --text="$FILENAME_IN_USE" $CANCEL $OK
if (( $? == 1 ));then
exit 0
fi
else # commandline is being used
echo "Session was previously saved with the same name. Overwrite it? (y|N)"
read ans
case "$ans" in
y|Y ) break
;;
* ) exit 0
;;
esac
fi
else
cp "$SESSIONS" "$SESSIONS.bkp"
echo "$SESSIONFILE" >> "$SESSIONS"
fi
}
######## END FUNCTIONS #################################################
# get args passed to script (session can be saved to a different file)
for arg in "$@";do
case "$arg" in
-h|--help ) echo -e "$USAGE2"
echo
exit 0
;;
-f|--files ) if [[ $2 ]];then
SESSIONFILE="$2" # sessionfile has been specified
writeSessions "$SESSIONFILE" # if sessionfile is new, write name to saved-sessions
break
else
echo
echo -e "\tNo saved-session file specified!"
echo -e "$USAGE1"
echo
exit 1
fi
;;
-z ) SPATH=$($DLGDEC $WINICON --entry \
--title="$SAVE_SESSION" \
--entry-label="$NEW_FILE" \
--text="$FILE_TO_SAVE" \
$OK $CANCEL \
)
(( $? == 1 )) && exit 0
if [[ -z $SPATH ]];then # entry was empty
$DLG $WINICON --title="Conky sessionfile" --text="No file specified for new saved session\n\nExiting..." $OK
exit 1
else
writeSessions "$SPATH" "-z" # saved session file from input dialog
fi
;;
* ) if ! [[ $arg ]];then
SESSIONFILE="$SESSIONFILE" # sessionfile is default
break
else
echo -e "$USAGE1"
exit 1
fi
;;
esac
done
# test for ~/.conkyrc, create a link to the default conky if necessary
if ! [[ -e $CRC ]];then
if [[ -e $BLDEFAULT ]];then
ln -s "$BLDEFAULT" "$CRC"
else
echo "Default conkyrc not found"
fi
fi
# get conky directories in .conky, add to array
conkyRunning
findConky
# loop through arrays, and build list text for yad dialog
unset LISTCONKY
for ((j=0; j<${#conkysArr[*]}; j++));do
LISTCONKY="$LISTCONKY${checkArr[j]} ${conkysArr[j]} "
done
while ! [[ $RET ]];do
## Populate dialog from array, get return value(s)
RET=$($DLGDEC $WINICON --list --title="$TITLE" \
--text="$SESS_SAVE" \
--checklist --width=400 --height=500 --multiple \
--column="$SELECT" --column="$CONF_FILE" $LISTCONKY \
--separator=":" \
$CANCEL $OK \
)
if [[ $? == 1 ]]; then # cancel button pressed
# restore previous saved-sessions file
[[ -f $SESSIONS.bkp ]] && mv "$SESSIONS.bkp" "$SESSIONS"
rm "$TEMPFILE"
exit 0
fi
if ! [[ $RET ]];then # No conkys chosen
MSG="$NOTHING_SELECTED"
$DLG $WINICON --title="$TITLE" --text="$MSG" $OK $CANCEL
if [[ $? = 1 ]];then
# restore previous saved-sessions file
mv "$SESSIONS.bkp" "$SESSIONS"
rm "$TEMPFILE"
continue
else
killall conky
exit 0
fi
else
> "$SESSIONFILE" # Create new session file
# loop through returned choices, add to array
i=0
OIFS=$IFS # save Internal Field Separator
IFS=":" # separator is ":" in returned choices
for name in $RET; do
retConky[$i]="$name"
i=$(($i+1))
done
IFS=$OIFS # reset IFS back to default
# kill all conkys
if [[ $(pidof conky) ]];then
killall conky
fi
# Find the chosen conkys and start them
for name in ${retConky[*]};do # loop through checkmarked conky names
for ((j=0; j<${#conkysPath[*]}; j++));do # traverse through elements
for f in ${conkysPath[j]};do # compare with choice from dialog
display=$( echo "$f" | awk -F"/" '{print $(NF-1)"/"$NF}')
if [[ $display = $name ]];then
echo -e "conky -c $f & sleep 1s" >> "$SESSIONFILE"
#start the conky (adjust the sleep time if required)
conky -c "$f" & sleep 1s
fi
done
done
done
fi
done
rm "$TEMPFILE"
exit 0

View File

@ -0,0 +1,244 @@
#!/bin/bash
#
# bl-tint2-manager: a BunsenLabs tint2 selection and switcher script
# Copyright (C) 2015-2019 damo <damo@bunsenlabs.org>
# 2019-2020 John Crawley <john@bunsenlabs.org>
# Ported to Mabox by napcok <napcok@gmail.com>, August 2020
#
# 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/>.
#
########################################################################
#
# Tint2 config files must be in $TINT2PATH
#
# When the dialog opens, any running tint2s will be checkmarked.
#
# Click "Apply" and all running tint2s are stopped,
# and all checkmarked tint2s are started.
#
# To stop a tint2 just uncheck it, and "Apply".
#
# Running tint2s are saved to a session file, and can be run with
# the "tint2-session" script. To start them at login, add the
# following line to autostart:
#
# mb-tint2-session
#
########################################################################
TINT2PATH="$HOME/.config/tint2"
TINT2DEFAULT="$TINT2PATH/tint2rc" # tint2 will create this if it doesn't exist
SESSIONFILE="$TINT2PATH/tint2-sessionfile"
USAGE='mb-tint2-manager is a tint2 selection and switcher script
which uses yad to generate a graphical user interface.
Usage: mb-tint2-manager
or: mb-tint2-manager -h|--help
Optional arguments:
-h | --help Show this message (no other options are supported at this time)
Use:
With no command option the script runs the gui
Tint2 config files must be in HOME/.config/tint2/
When the dialog opens, any running tint2s will be checkmarked.
Click "Apply" or "OK" and all running tint2s are stopped,
and all checkmarked tint2s are started.
To stop a tint2 just uncheck it, and click "Apply" or "OK".
Click "Apply" to return to the dialog after applying changes,
click "OK" to close the window after applying changes,
click "Close" to close the window without applying any more changes.
Running tint2s are saved to a session file, and can be run with
the "tint2-session" script. To start them at login, add the
following line to autostart:
mb-tint2-session
'
### DIALOG VARIABLES
DLGDEC="yad --center --borders=20 "
WINICON="--window-icon=distributor-logo-mabox --image=tint2conf"
case $LANG in
pl*)
TITLE="Menedżer paneli Tint2"
OK="--button=OK:2"
APPLY="--button=Zastosuj:0"
CANCEL="--button=Anuluj:1"
CLOSE="--button=Zamknij:1"
SELECT_TINT="Wybierz Tint2 z listy, po kliknięcu <b>Zastosuj</b> wszystkie zaznaczone zostaną uruchomione."
SELECT="Wybór"
TINT_CONF_FILE="plik konfiguracji tint2"
;;
*)
TITLE="Tint2 Panels Manager"
OK="--button=OK:2"
APPLY="--button=Apply:0"
CANCEL="--button=Cancel:1"
CLOSE="--button=Close:1"
SELECT_TINT="Select Tint2s from the list. Click <b>Apply</b> to start all selected."
SELECT="Select"
TINT_CONF_FILE="tint2 Name"
;;
esac
########################################################################
getRunning(){
local pid cmd args TPATH
while read -r pid cmd args; do
TPATH=${args#-c } # tint2 will start even without -c before filepath
if [[ -z $TPATH ]]; then
TPATH=$TINT2DEFAULT
elif [[ $TPATH != "$HOME"/* ]]; then
TPATH="$HOME/$TPATH"
fi
[[ -f $TPATH ]] || {
echo "$0: pgrep tint2 parsing failed: $TPATH not a file" >&2
continue
}
runningTints+=("$TPATH")
done < <(pgrep -ax tint2)
}
# $1 holds full path to config file
# return 0 if a running tint2 is using that file
isRunning(){
local file=$1
for running in "${runningTints[@]}"
do
[[ $running = "$file" ]] && return 0
done
return 1
}
fillArrays(){
num="$1"
tintsPath[$num]="$2" # full filepath to the tint2
tintsArr[$num]="$3" # displayed name
# see if config file matches one of the running tints
if isRunning "$2";then
checkArr[$num]="TRUE" # make checkmark in dialog
else
checkArr[$num]="FALSE"
fi
}
findTint(){
# search dirs for tint2 config files
local file num display
num=0
shopt -s globstar
#for file in "$TINT2PATH"/**;do
for file in $(find $TINT2PATH -type f -name *tint2rc);do
[[ -f $file ]] || continue
[[ $file = *~ ]] && continue # ignore backups
grep -q "panel_monitor" "$file" || continue # not a tint2rc file
display=${file#$TINT2PATH/}
fillArrays $num "$file" "$display"
num=$((num+1))
done
shopt -u globstar
}
loadDialog() {
local RET retval i pid cmd name file display
declare -a retTint
## Populate dialog from array, get return value(s)
RET=$($DLGDEC $WINICON --list --title="$TITLE" \
--text="$SELECT_TINT" \
--checklist --width=400 --height=500 \
--column="$SELECT" --column="$TINT_CONF_FILE" "${LISTTINT[@]}" --separator=":" \
$APPLY $CLOSE \
)
# For OK button, add to last line of yad command:
# $APPLY $OK $CLOSE \
retval=$?
if (( retval == 1 )); then # close button pressed
exit 0
fi
:> "$SESSIONFILE" # Create new session file
# loop through returned choices, add to array
i=0
OIFS=$IFS # copy original IFS
IFS=":" # separator is ":" in returned choices
for name in $RET; do
retTint[$i]=$name
i=$((i+1))
done
IFS=$OIFS # reset IFS
# kill all tint2s
pgrep -a tint2 | while read -r pid cmd; do
if [[ ${cmd%% *} = tint2 ]]; then
kill "$pid"
fi
done
for name in "${retTint[@]}";do # loop through checkmarked tint2 names
for ((j=0; j<${#tintsPath[*]}; j++));do # traverse through elements
file=${tintsPath[j]}
display=${tintsArr[j]}
# see if it matches the returned name
if [[ $display = "$name" ]];then
echo "$file" >> "$SESSIONFILE"
set -m # enable job control so forked tint2 is immune to signals
# start the tint2 (adjust the sleep time if required)
tint2 -c "$file" >/dev/null 2>&1 &
disown
set +m
sleep 1s
fi
done
done
# if there is an $OK button that returns 2, it will apply changes and exit
(( retval == 2 )) && exit 0
}
# get any commandline arguments
if ! (( $# == 0 ));then
for arg in "$@";do
if [[ $1 = "-h" ]] || [[ $1 = "--help" ]];then
echo -e "$USAGE"
exit 0
else
echo -e "\tERROR: sorry I don't understand \"${arg}\""
echo -e "$USAGE"
exit 1
fi
done
fi
while true;do
runningTints=()
# get tint2 directories in .tint2, add to array
getRunning
findTint
LISTTINT=()
# loop through arrays, and build list text for yad dialog
for ((j=0; j<${#tintsArr[*]}; j++));do
LISTTINT+=("${checkArr[j]}" "${tintsArr[j]}")
done
loadDialog #"$LISTTINT" now a global array
done
exit 0

View File

@ -1,168 +0,0 @@
#!/bin/bash
#
# Mabox tint2 selection and switcher script
#
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
# Ported to Manjaro by napcok <napcok@gmail.com>, March 2016
########################################################################
#
# Tint2 config files must be in $TINT2PATH
#
# When the dialog opens, any running tint2s will be checkmarked.
#
# Click "OK" and all running tint2s are stopped, and all checkmarked
# tint2s are started
#
# To stop a tint2 just uncheck it, and "OK"
#
# Running tint2s are saved to a session file, and can be run with
# the "tint2-session" script. To start them at login, add the
# following line to autostart:
#
# (sleep 2s && mb-tint2-session) &
#
########################################################################
DEBUGFILE="$HOME/.config/mb-tint2-debug.txt"
TINT2PATH="$HOME/.config/tint2"
SESSIONFILE="$TINT2PATH/tint2-sessionfile"
USAGE="\v\tUSAGE:\n\tWith no command argument, the script uses the chosen
\tTint2 session file \"$TINT2PATH/tint2-sessionfile\",
\tif it exists, otherwise the default tint2rc is used
\v\tTo start them at login, add the following line to autostart:
\v\t\t(sleep 2s && mb-tint2-session) &"
### DIALOG VARIABLES
DLGDEC="yad --center --borders=20"
OK="--button=OK:0"
WINICON="--window-icon=distributor-logo-mabox --image=tint2conf"
case $LANG in
pl*)
TITLE="Menedżer paneli Tint2"
CANCEL="--button=Anuluj:1"
SELECT_TINT="Wybierz Tint2 z listy, po kliknięcu <b>OK</b> wszystkie zaznaczone zostaną uruchomione."
SELECT="Wybór"
TINT_CONF_FILE="plik konfiguracji tint2"
;;
*)
TITLE="Tint2 Panels Manager"
CANCEL="--button=Cancel:1"
SELECT_TINT="Select Tint2s from the list. Click <b>OK</b> to start all selected."
SELECT="Select"
TINT_CONF_FILE="tint2 Name"
;;
esac
########################################################################
tintRunning(){
# make blank tempfile, to save running tint2 paths
TEMPFILE=$(mktemp --tmpdir tint2.XXXX)
pgrep -a tint2 | while read pid cmd; do
if [[ ${cmd%% *} = tint2 ]]; then
TPATH=$(echo $cmd | awk '{print $NF}')
echo $TPATH >> $TEMPFILE
fi
done
}
fillArrays(){
num="$1"
tintsPath[$num]="$2" # full filepath to the tint2
tintsArr[$num]="$3" # displayed name
# see if name matches one of the running tints
if grep -qx "$2" "$TEMPFILE";then # if tint2 is running (read from tempfile)
checkArr[$num]="TRUE" # make checkmark in dialog
else
checkArr[$num]="FALSE"
fi
}
findTint(){
# search dirs for tint2 config files
num=0
for x in $(find $TINT2PATH -type f -name *tint2rc);do
# check if likely tint2 config file
pm=$(grep "panel_monitor" "$x")
if [[ $pm ]];then
TINT2=$( echo $x | awk -F"/" '{print $(NF-1)"/"$NF}')
fillArrays $num $x $TINT2
num=$(($num+1))
fi
done
}
# get any commandline arguments
if ! (( $# == 0 ));then
for arg in "$@";do
if [[ $1 = "-h" ]] || [[ $1 = "--help" ]];then
echo -e "$USAGE"
exit 0
else
echo -e "\tERROR: sorry I don't understand the input"
echo -e "$USAGE"
exit 0
fi
done
fi
# get tint2 directories in .tint2, add to array
tintRunning
findTint
# loop through arrays, and build msg text for yad dialog
unset LISTTINT
for ((j=0; j<${#tintsArr[*]}; j++));do
LISTTINT="$LISTTINT ${checkArr[j]} ${tintsArr[j]}"
done
## Populate dialog from array, get return value(s)
RET=$($DLGDEC $WINICON --list --title="$TITLE" \
--text="$SELECT_TINT" \
--checklist --width=350 --height=500 --multiple \
--column="$SELECT" --column="$TINT_CONF_FILE" $LISTTINT --separator=":" \
$CANCEL $OK \
)
if (( $? == 1 )); then # cancel button pressed
exit 0
else
> $SESSIONFILE # Create new session file
# loop through returned choices, add to array
i=0
OIFS=$IFS # copy original IFS
IFS=":" # separator is ":" in returned choices
for name in $RET; do
retTint[$i]=$name
i=$(($i+1))
done
IFS=$OIFS # reset IFS
# kill all tint2s
pgrep -a tint2 | while read pid cmd; do
if [[ ${cmd%% *} = tint2 ]]; then
kill "$pid"
fi
done
for name in ${retTint[*]};do # loop through checkmarked tint2 names
for ((j=0; j<${#tintsPath[*]}; j++));do # traverse through elements
for f in ${tintsPath[j]};do
display=$( echo $f | awk -F"/" '{print $(NF-1)"/"$NF}')
path=$( echo $f | awk -F"/" '{print "/"$(NF-2)"/"$(NF-1)"/"$NF}')
# see if it matches the returned name
if [[ $display = $name ]];then
#DEBUG
#echo "mb-tint2zen: path=$path" >> $DEBUGFILE
#echo "mb-tint2zen: f=$f" >> $DEBUGFILE
#DEBUG_KONIEC
echo -e "$path" >> $SESSIONFILE
tint2 -c "$f" & #start the tint2
sleep 1s
fi
done
done
done
mabox-compositor --restart & # restart compositor
fi
rm -r $TEMPFILE
exit 0

View File

@ -239,7 +239,7 @@ yad --plug=$KEY --tabnum=4 --text="$LOOK_DESC" --icons --read-dir=/usr/share/mcc
yad --plug=$KEY --tabnum=5 --borders=20 \
--text="$TINT_DESC" \
--columns=1 --form \
--field="$T_CHOOSE:FBTN" "mb-tint2zen" \
--field="$T_CHOOSE:FBTN" "mb-tint2-manager" \
--field="$T_CONF:FBTN" "tint2conf" \
--field="$T_RESTART:FBTN" "mb-tint2restart" \
--field=":LBL" "" \
@ -250,7 +250,7 @@ yad --plug=$KEY --tabnum=5 --borders=20 \
yad --plug=$KEY --tabnum=6 --borders=20 \
--text="$CONKY_DESC" \
--form \
--field="$CONKY_CHOOSE:FBTN" "mb-conkyzen" \
--field="$CONKY_CHOOSE:FBTN" "mb-conky-manager" \
--field="$CONKY_RESTART:FBTN" "mb-conky-session" \
--field="$CONKY_EDIT:FBTN" "mb-conkyedit" \
--field="$OPEN_CONKYDIR:FBTN" "exo-open $HOME/.config/conky/" \