mabox-tools/bin/mb-conkyedit
2020-02-18 17:24:18 +01:00

98 lines
2.9 KiB
Bash
Executable File

#!/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 "
TITLE="Edytor Conky"
WINICON="--window-icon=distributor-logo-mabox"
OK="--button=OK:0"
CANCEL="--button=Anuluj:1"
########## 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" \
--text="Wybierz z listy Conky do edycji\nMożesz wybrać kilka plików konfiguracyjnych" \
--checklist \
--column="Wybór:CHK" --column="Plik konfiguracyjny:TXT" $LISTCONKY --separator=":"\
$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
geany "$f"
fi
done
done
done
fi
exit 0