#!/bin/zsh VIEWER='wvit' VIEWER_QUIT=':q' LAST_WT_PATH=/var/tmp/.last_work_time CURRENT_WORKTIME_PATH=/var/tmp/.worktime_filter TWUI_CFG_LINE='report.next.filter' define_values() { local CURRENT_WT CURRENT_WT=$(cat /var/tmp/current_work_time) echo "$1 -> $4" > /var/tmp/current_work_time echo "$2" > /var/tmp/current_polybar_b_wt_color echo "$3" > /var/tmp/current_polybar_f_wt_color echo "$CURRENT_WT" > "$LAST_WT_PATH" notify-send -u critical "HorĂ¡rio de Trabalho:" "$1" update_filters "$4" } update_filters() { local WT local FINAL_TIME=$1 WT=$WORKTIME FINAL_TIME=$1 update() { local WORKTIME_FILTER local HABIT_FILTER local MAIN_FILTER local FINAL_FILTER local REGEX mount_wt_filter() { local WT local BASESTR local SCHDSTR local GOALSTR local ALARMSTR GOALSTR="(GOAL.after:$(date +%Y-%m-01) and GOAL.before:now and TYPE:Objective)" ESSENTSTR='(+TODAY and +INSTANCE)' ALARMSTR="(ALARM.after:now and ALARM.before:$FINAL_TIME)" WT=$1 BASESTR="(WT:$WT or WT:AllDay) and ($ESSENTSTR or $GOALSTR or $ALARMSTR)" echo "($BASESTR)" } if [[ "$WT" == "Break" ]] || [[ "$WT" == "PreSleep" ]]; then FILTER1=$(mount_wt_filter Break) FILTER2=$(mount_wt_filter PreSleep) if [[ ! "$WT" == "PreSleep" ]]; then WORKTIME_FILTER="$FILTER1" else WORKTIME_FILTER="$FILTER1 or $FILTER2" fi else WORKTIME_FILTER="$(mount_wt_filter "$WT")" fi HABIT_FILTER="($DUE_FILTER and WT:AllDay and (status.not:recurring and status.not:waiting))" MAIN_FILTER="($TW_FILTER or $WORKTIME_FILTER) and status:pending" FINAL_FILTER="($MAIN_FILTER) or $HABIT_FILTER" REGEX="s/$TWUI_CFG_LINE.*/$TWUI_CFG_LINE=$FINAL_FILTER/" sed -i "$REGEX" ~/.taskrc echo "$FINAL_FILTER" > $CURRENT_WORKTIME_PATH #update-vit-taskrc } update } update_vit_twui_session() { if tmux has-session -t TaskWarrior 2>/dev/null; then tmux send-keys -t TaskWarrior:0.0 "$VIEWER_QUIT" C-m sleep 1 tmux send-keys -t TaskWarrior:0.0 "$VIEWER" C-m else xdotool mousemove 2400 450 bspc desktop -f "^5" taopen > /dev/null 2& disown %1 fi } WKT_ERR="Avaiable worktimes: PreWork, General, Essentials, Calm, PreSleep, Break" if [[ -z "$1" ]]; then echo "$WKT_ERR" exit 1 else export WORKTIME=$1 fi # ------------------- # # Change this based on your worktimes and actions to do at each worktime case $1 in "PreWork") define_values "PreWork" "#999" "#111" "08:00" ;; "Essentials") define_values "Essentials" "#f90" "#111" "10:00" killall Discord ;; "General") define_values "General" "#e00" "#111" "14:00" ;; "Calm") define_values "Calm" "#00e" "#eee" "18:00" ;; "PreSleep") define_values "PreSleep" "#999" "#111" "19:00" killall Discord killall DiscordPTB ;; "Sleep") define_values "Sleep" "#fff" "#111" "06:00" killall Discord killall DiscordPTB ;; "Break") define_values "Break" "#fff" "#111" ;; "last") worktime $(cat "$LAST_WT_PATH") exit 0 ;; *) echo "$WKT_ERR" exit 1 esac # ------------------- # update_vit_twui_session polybar-msg cmd restart