167 lines
4.4 KiB
Bash
Executable File
167 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# mabox-todo.sh - conky widget + menus to interact with todo.sh
|
|
|
|
|
|
# Config file
|
|
CFG_FILE=~/.config/mabox/mabox-todo.conf
|
|
if [ ! -f "$CFG_FILE" ];then
|
|
cat <<EOF > ${CFG_FILE}
|
|
# Currently active filename with tasks without .txt extension
|
|
filename=todo
|
|
# Filter by: +project_name or @context_name
|
|
filter=
|
|
# Display: project names (-+), context names (-@), priority labels (-P)
|
|
hide_project=
|
|
hide_context=
|
|
hide_priority=
|
|
hide_done=y
|
|
EOF
|
|
fi
|
|
source <(grep = $CFG_FILE)
|
|
|
|
|
|
TODO_DIR=~/.todo
|
|
TODO_NAME="$filename"
|
|
|
|
export TODO_FILE="$TODO_DIR/${TODO_NAME}.txt"
|
|
export DONE_FILE="$TODO_DIR/done_${TODO_NAME}.txt"
|
|
export REPORT_FILE="$TODO_DIR/report_${TODO_NAME}.txt"
|
|
|
|
to_conky(){
|
|
action=${action:-ls}
|
|
filter=${filter:-}
|
|
filterlabel=${filter:-none}
|
|
prettyname=${filename//_/ }
|
|
[[ "$hide_project" == "y" ]] && options+=("-+")
|
|
[[ "$hide_context" == "y" ]] && options+=("-@")
|
|
[[ "$hide_priority" == "y" ]] && options+=("-P")
|
|
|
|
#header="Project:$filename \${alignc}TODO.txt (click me!)\${alignr}Filter:\${voffset 8}"
|
|
header="\${color0}\${alignc}TODO List
|
|
\${alignc}${prettyname}\${alignr}#[filter: $filterlabel]
|
|
\${voffset 8}"
|
|
#declare -a cmd=(todo.sh ${options[@]} -d ~/.config/todo/config-conky ${action} ${filter})
|
|
#out+=$(${cmd[@]})
|
|
if [ "${hide_done}" == "y" ];then
|
|
out+=$(todo.sh ${options[@]} -d ~/.config/todo/config-conky ${action} -'[0-9] x ' ${filter})
|
|
else
|
|
out+=$(todo.sh ${options[@]} -d ~/.config/todo/config-conky ${action} ${filter})
|
|
fi
|
|
printf "${header}\n"
|
|
printf '%s\n' "${out[@]}"
|
|
}
|
|
|
|
listfiles(){
|
|
shopt -s extglob
|
|
allfiles=($TODO_DIR/*.txt)
|
|
for entry in "${allfiles[@]}"
|
|
do
|
|
filename="${entry##*/}"
|
|
name="${filename%.*}"
|
|
[[ "$name" =~ ^done ||"$name" =~ ^report ]] && : || echo $name
|
|
done
|
|
}
|
|
switchfile(){
|
|
if [ "$1" = "" ];then
|
|
echo "Missing argument. Specify one of:"
|
|
listfiles
|
|
else
|
|
names=($(listfiles))
|
|
if [[ " ${names[*]} " =~ [[:space:]]${1}[[:space:]] ]]; then
|
|
# whatever you want to do when array contains value
|
|
mb-setvar filename=${1} ${CFG_FILE}
|
|
clearfilter
|
|
else
|
|
echo "Wrong file. Use one of: ${names[@]}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
filter(){
|
|
mb-setvar filter="${1}" ${CFG_FILE}
|
|
}
|
|
clearfilter(){
|
|
sd "filter.*$" "filter=" ${CFG_FILE}
|
|
}
|
|
addtask(){
|
|
task=$(yad --width=400 --center --border=40 --undecorated --no-buttons --close-on-unfocus --text-align=center --text "<big><b>Add new task...</b></big>\n <b>Enter</b> - add | <b>Esc</b> - abort" --entry --entry-text="Task description +Projest @Context" --ricon=gtk-clear)
|
|
if [ ! -z "${task}" ];then
|
|
#notify-send.sh "okej" "${task}"
|
|
pass_to_todo_sh add "${task}"
|
|
else
|
|
:
|
|
fi
|
|
}
|
|
addfile(){
|
|
file=$(yad --skip-taskbar --width=400 --center --border=40 --undecorated --no-buttons --text-align=center --text "Add new TODO list..." --entry --entry-text="List name" --ricon=gtk-clear)
|
|
if [ ! -z "${file}" ];then
|
|
#Remove spaces
|
|
file=${file// /_}
|
|
file=${file%.*}
|
|
if [ -f "$HOME/.todo/${file}.txt" ];then
|
|
notify-send.sh "Wrong project name!" "Project ${file} already exist!"
|
|
else
|
|
touch "$HOME/.todo/${file}.txt"
|
|
switchfile "${file}"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
addmenu(){
|
|
cat <<EOF > ${TODO_DIR}/${1}.csv
|
|
### Custom menu for TODO list: ${1}
|
|
### Syntax (comma separated):
|
|
### LABEL,command
|
|
### Example commands - modify to your needs, uncomment or write your own
|
|
##
|
|
# Browse files,^pipe(jgbrowser ~/Projects/)
|
|
# Open project in Geany,geany ~/projects/${1}.geany
|
|
EOF
|
|
xdg-open ${TODO_DIR}/${1}.csv
|
|
}
|
|
addnotes(){
|
|
#notify-send.sh "filename" "${1}"
|
|
CHERRYFILE=/usr/share/mabox-todolist/empty.ctb
|
|
cp "${CHERRYFILE}" "${TODO_DIR}/${1}.ctb"
|
|
cherrytree "${TODO_DIR}/${1}.ctb"
|
|
}
|
|
|
|
removeproject() {
|
|
rm -f "$HOME/.todo/${1}.txt"
|
|
rm -f "$HOME/.todo/${1}.txt.bak"
|
|
rm -f "$HOME/.todo/done_${1}.txt"
|
|
rm -f "$HOME/.todo/report_${1}.txt"
|
|
# maybe also csv file and cherrytree ctb
|
|
switchfile todo
|
|
}
|
|
|
|
pass_to_todo_sh(){
|
|
todo.sh "$@"
|
|
}
|
|
init() {
|
|
mkdir ~/.config/todo
|
|
rsync -a /usr/share/mabox-todolist/confi* $HOME/.config/todo/
|
|
|
|
rsync -a /usr/share/mabox-todolist/TODOlist_mbcolor.conkyrc $HOME/.config/conky/
|
|
rsync -a /usr/share/mabox-todolist/TODOlist.csv $HOME/.config/conky/menuscripts/
|
|
|
|
conkyctl startone $HOME/.config/conky/TODOlist_mbcolor.conkyrc
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
"") to_conky;;
|
|
init|-i)init;;
|
|
listfiles|l)listfiles;; #list task files
|
|
switchfile|s)switchfile "$2";; #switch to tasks file
|
|
filter)filter "$2";;
|
|
clearfilter) clearfilter;;
|
|
addtask)addtask;;
|
|
addfile)addfile;;
|
|
addmenu)addmenu "$2";;
|
|
addnotes)addnotes "$2";;
|
|
removeproject) removeproject "$2";;
|
|
*)pass_to_todo_sh "$@";;
|
|
esac
|