diff --git a/bin/mb-conkyzen b/bin/mb-conkyzen new file mode 100755 index 0000000..eebcec2 --- /dev/null +++ b/bin/mb-conkyzen @@ -0,0 +1,316 @@ +#!/bin/bash +# +# BunsenLabs Conky selection and switcher script +# +# Written by damo for BunsenLabs Linux, April 2015 +# Beta tested and stamped "zen" by +# Rapackaged for Manjaro by napcok , 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 $CONKYPATH/\n\n" + SESS_SAVE="Wybierz pliki Conky, które mają być uruchomione.\nSesja zostanie zachowana w:\n $SESSIONFILE" + 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 $CONKYPATH/\n\n" + SESS_SAVE="Choose Conky file, which you like to start.\nSession will be saved to:\n $SESSIONFILE" + 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 diff --git a/bin/mb-obthemes b/bin/mb-obthemes index f8a72ff..f8a241e 100755 --- a/bin/mb-obthemes +++ b/bin/mb-obthemes @@ -466,7 +466,7 @@ function getConky(){ } function checkConkyzen(){ # see if mb-conky-manager and session file present - if type mb-conky-manager &>/dev/null;then + if type mb-conkyzen &>/dev/null;then if [[ -f $CONKYSESSION ]]; then CZEN=1 # set flag for Restore choice fi @@ -520,7 +520,7 @@ function killTints(){ } function checkTint2zen(){ # see if mb-tint2zen and session file present - if type mb-tint2-manager &>/dev/null;then + if type mb-tint2zen &>/dev/null;then if [[ -f $TINTSESSION ]]; then TZEN=1 # set flag for Restore choice fi diff --git a/bin/mb-tint2zen b/bin/mb-tint2zen new file mode 100755 index 0000000..f4031ca --- /dev/null +++ b/bin/mb-tint2zen @@ -0,0 +1,168 @@ +#!/bin/bash +# +# Mabox tint2 selection and switcher script +# +# Written by damo for BunsenLabs Linux, April 2015 +# Ported to Manjaro by napcok , 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 OK 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 OK 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