mabox-tools/bin/mb-conkyedit

112 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

2020-02-18 17:24:18 +01:00
#!/bin/bash
#
# BunsenLabs Conky Editor
#
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
#
# Repackaged for Manjaro by napcok <napcok@gmail.com>, March 2016
#
########################################################################
#
# Conkys must be in $CONKYPATH
# The name must end with "conky" or "conkyrc"
#
# Checkmarked conkys will be opened in the text editor
# Multiple conkys can be chosen
#
########################################################################
CONKYPATH="$HOME/.config/conky"
### DIALOG VARIABLES
DLGDEC="yad --center --borders=20 --width=400 --height=500 "
2020-08-26 23:15:00 +02:00
WINICON="--window-icon=distributor-logo-mabox --image=conky "
2020-02-18 17:24:18 +01:00
OK="--button=OK:0"
2020-02-29 14:17:05 +01:00
case $LANG in
pl*)
TITLE="Edytor Conky"
CANCEL="--button=Anuluj:1"
2020-08-26 23:15:00 +02:00
CE_DESC="Wybierz z listy Conky do edycji.\nMożesz wybrać kilka plików konfiguracyjnych.\nMożesz dodać własne pliki konfiguracyjne Conky\ndo katalogu <i>$CONKYPATH</i>"
2020-02-29 14:17:05 +01:00
CE_CHOSE="Wybór"
CE_CONFFILE="Plik konfiguracyjny"
;;
*)
TITLE="Conky Editor"
CANCEL="--button=Cancel:1"
2020-08-26 23:15:00 +02:00
CE_DESC="Choose Conky for edit.\nYou can choose multiple files.\nYou can put your own Conky configurations\ninto <i>$CONKYPATH</i> directory."
2020-02-29 14:17:05 +01:00
CE_CHOSE="Choose"
CE_CONFFILE="Configuration file"
;;
esac
2020-02-18 17:24:18 +01:00
########## FUNCTIONS ###################################################
fillArrays(){
num="$1"
conkysPath[$num]="$2" # full filepath to conky
conkysArr[$num]="$3" # displayed name: "directory/*conky(rc)"
}
findConky(){
# search dirs for conkys files - looking for "conky" in the name
# if "*conky(rc)" then display it
num=0
# 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
}
######## END FUNCTIONS #################################################
# get conky directories in .conky, add to array
findConky
# loop through arrays, and build msg text for yad dialog
unset LISTCONKY
for ((j=0; j<${#conkysArr[*]}; j++));do
LISTCONKY="$LISTCONKY FALSE ${conkysArr[j]}"
done
## Populate yad dialog from array, get return value(s)
RET=$($DLGDEC $WINICON --list --title="$TITLE" \
2020-02-29 14:17:05 +01:00
--text="$CE_DESC" \
2020-02-18 17:24:18 +01:00
--checklist \
2020-02-29 14:17:05 +01:00
--column="$CE_CHOSE:CHK" --column="$CE_CONFFILE:TXT" $LISTCONKY --separator=":"\
2020-02-18 17:24:18 +01:00
$OK $CANCEL \
)
if [[ $? == 1 ]]; then # cancel button pressed
exit 0
else
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
# Find the chosen conkys and edit 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
2022-08-17 14:26:41 +02:00
xdg-open "$f"
2020-02-18 17:24:18 +01:00
fi
done
done
done
fi
exit 0