From 49be67f604b2355ccea96ba841e7f1dfbdff6fb0 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 10:53:29 +0200 Subject: [PATCH 01/29] add start and stop tasks feature --- completion.sh | 4 ++-- nul | 1 + setup.sh | 2 +- y.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 nul diff --git a/completion.sh b/completion.sh index 8abde2c..3034dd8 100644 --- a/completion.sh +++ b/completion.sh @@ -6,9 +6,9 @@ _y() { COMREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="do done procrastinate proc superprocrastinate prio prioritize vanish rm later feierabend" + opts="do done procrastinate proc superprocrastinate prio prioritize vanish rm later feierabend start stop" case "${prev}" in - done|procrastinate|superprocrastinate|proc|prio|prioritize) + done|procrastinate|superprocrastinate|proc|prio|prioritize|start) IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) COMPREPLY=( "${tmp[@]// /\ }" ) return 0 diff --git a/nul b/nul new file mode 100644 index 0000000..f46afa3 --- /dev/null +++ b/nul @@ -0,0 +1 @@ +/mnt/c/Program Files/Git/cmd/start-ssh-agent.cmd: line 4: @VERIFY: command not found diff --git a/setup.sh b/setup.sh index 23b0f59..6203b74 100755 --- a/setup.sh +++ b/setup.sh @@ -50,7 +50,7 @@ case $yn in cd "$DATADIR" printf "Creating daily directories...\n" - for d in today tomorrow later done archive; do + for d in today tomorrow later done archive started; do if ! [[ -d "$d" ]]; then mkdir "$d" printf " Directory '$d' created.\n" diff --git a/y.sh b/y.sh index 11514d2..8f5537d 100755 --- a/y.sh +++ b/y.sh @@ -20,6 +20,7 @@ if [[ ! "$DOLLARNULL" == *nocolor* ]]; then GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[1;34m' + MAGENTA='\033[1;35m' BOLD='\033[1m' NC='\033[0m' # No Color fi @@ -88,6 +89,15 @@ add_task() { echo -e "'$TASK' added for ${GREEN}$DAY!${NC}" } +# helper functions, wow! +_check_if_task_started() { + if [ -z "$( ls -A $DATADIR/started )" ]; then + return 1 + else + return 0 + fi + } + prioritize() { if ! [[ -e $DATADIR/today/"$TASK" ]]; then echo "No such task!" @@ -226,6 +236,33 @@ show_usage() { exit 0 } +# main script starts here! +# first: check if work has been started on anything / "focus mode" +if _check_if_task_started; then + if [ -z $1 ]; then + echo -e ${BOLD}Focus!${NC} + print_tasks started "Currently working on: " $MAGENTA + exit 0 + else + case "$1" in + do|edit) + echo "tbd: edit tasks or add new ones while in focus mode" + exit 1 + ;; + stop) + mv $DATADIR/started/* $DATADIR/today/ + echo "Stopped working on all tasks." + exit 0 + ;; + *) + echo "Not a valid command." + echo "You're currently working on a task. Use \`y stop\` to stop work on it." + exit 1 + esac + fi +fi + +# now for "normal mode" where no task has been started if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow # use the following syntax: directory name, day in "readable case" and name of color variable HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} @@ -233,10 +270,11 @@ if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow print_tasks today Today: $GREEN print_tasks tomorrow Tomorrow: $BLUE print_tasks done Done: $YELLOW -# print_tasks later Later $RED # in case one wants that... + # print_tasks later Later $RED # in case one wants that... exit 0 fi +### "normal" mode without any started tasks case "$1" in do) @@ -278,6 +316,26 @@ case "$1" in print_motivation ;; + start) + if _check_if_task_started; then + echo "You're already working on a task!" + exit 1 + fi + if [ -z "$2" ]; then + echo "Error: no task name given" + show_usage + exit 1 + fi + shift; TASK="$@" + # create and start task if it doesn't exist + if ! [[ -e $DATADIR/today/"$TASK" ]]; then + add_task today "$TASK" + fi + mv $DATADIR/today/"$TASK" $DATADIR/started/ + printf \\n + echo "Started work on task $TASK." + ;; + prioritize|prio) # still janky and beta shift; TASK="$@" prioritize From 9c9490ac1214538030c70a774a04bb8123d58593 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 11:13:23 +0200 Subject: [PATCH 02/29] start work on completely removing the "later" feature --- y.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/y.sh b/y.sh index 8f5537d..523fe0e 100755 --- a/y.sh +++ b/y.sh @@ -346,15 +346,6 @@ case "$1" in procrastinate tomorrow exit 0 ;; - superprocrastinate) - shift; TASK="$@" - procrastinate later - exit 0 - ;; - later) - print_tasks later Later: $RED - exit 0 - ;; feierabend) feierabend exit 0 From 47052206552e4371d40967eb43f8c15dc71121ba Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 11:18:11 +0200 Subject: [PATCH 03/29] disable motivation, demotivation, headlines for now --- y.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/y.sh b/y.sh index 8f5537d..93768d3 100755 --- a/y.sh +++ b/y.sh @@ -123,7 +123,7 @@ feierabend() { fi if [[ ! $(find . -maxdepth 1 -type f) ]]; then echo "u did absolutely nothing today." - print_demotivation + # print_demotivation else echo -e "${GREEN}here's what u did today${NC}" printf \\n # show all files from 'done' @@ -138,7 +138,7 @@ feierabend() { sleep 0.5s fi done - print_motivation + # print_motivation fi find "$DATADIR/tomorrow" -type f ! -name ".*" -exec mv "{}" "$DATADIR/today/" \; 2> /dev/null # move task from tomorrow to today @@ -196,7 +196,7 @@ procrastinate() { if [[ ! -e $DATADIR/$TARGETDAY/"$TASK" ]]; then mv $DATADIR/$SOURCEDAY/"$TASK" $DATADIR/$TARGETDAY/"$TASK" echo -e "'$TASK' procrastinated until ${BLUE}$TARGETDAY.${NC}" - print_demotivation + # print_demotivation else echo "'$TASK' already exists $TARGETDAY!" fi @@ -265,8 +265,8 @@ fi # now for "normal mode" where no task has been started if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow # use the following syntax: directory name, day in "readable case" and name of color variable - HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} - echo -e ${BOLD}$HEADLINEOUT${NC} + #HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} + #echo -e ${BOLD}$HEADLINEOUT${NC} print_tasks today Today: $GREEN print_tasks tomorrow Tomorrow: $BLUE print_tasks done Done: $YELLOW @@ -313,7 +313,7 @@ case "$1" in mv $DATADIR/today/"$TASK" $DATADIR/done/ printf \\n echo "Done: $TASK." - print_motivation + # print_motivation ;; start) From fbeb4cdd3d7f6e921bca3654bceca4a5f7602ffd Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 11:23:01 +0200 Subject: [PATCH 04/29] remove 'later' from completion and setup scripts --- completion.sh | 6 +++--- setup.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/completion.sh b/completion.sh index 3034dd8..63ab9cd 100644 --- a/completion.sh +++ b/completion.sh @@ -6,9 +6,9 @@ _y() { COMREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="do done procrastinate proc superprocrastinate prio prioritize vanish rm later feierabend start stop" + opts="do done procrastinate proc prio prioritize vanish rm feierabend start stop" case "${prev}" in - done|procrastinate|superprocrastinate|proc|prio|prioritize|start) + done|procrastinate|proc|prio|prioritize|start) IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) COMPREPLY=( "${tmp[@]// /\ }" ) return 0 @@ -19,7 +19,7 @@ _y() { return 0 ;; vanish) # extremely ghetto - opts="today tomorrow later" + opts="today tomorrow" case "${prev}" in today) IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) diff --git a/setup.sh b/setup.sh index 6203b74..49cee5c 100755 --- a/setup.sh +++ b/setup.sh @@ -50,7 +50,7 @@ case $yn in cd "$DATADIR" printf "Creating daily directories...\n" - for d in today tomorrow later done archive started; do + for d in today tomorrow done archive started; do if ! [[ -d "$d" ]]; then mkdir "$d" printf " Directory '$d' created.\n" From 64f6ddbf2be3683fd63ee0b19900ac7ca5eaf311 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 13:25:48 +0200 Subject: [PATCH 05/29] rework procrastinate function to not use later / backlog anymore --- y.sh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/y.sh b/y.sh index 523fe0e..4c30418 100755 --- a/y.sh +++ b/y.sh @@ -187,15 +187,11 @@ feierabend() { procrastinate() { SOURCEDAY="today" - TARGETDAY=$1 - if [[ ! -e $DATADIR/today/"$TASK" ]] && [[ -e $DATADIR/tomorrow/"$TASK" ]]; then # if task doesn't exist today but only tomorrow, move from tomorrow to later - SOURCEDAY="tomorrow" - TARGETDAY="later" - fi + TARGETDAY="tomorrow" if [[ -e $DATADIR/$SOURCEDAY/"$TASK" ]]; then if [[ ! -e $DATADIR/$TARGETDAY/"$TASK" ]]; then mv $DATADIR/$SOURCEDAY/"$TASK" $DATADIR/$TARGETDAY/"$TASK" - echo -e "'$TASK' procrastinated until ${BLUE}$TARGETDAY.${NC}" + echo -e "'$TASK' moved to ${BLUE}$TARGETDAY.${NC}" print_demotivation else echo "'$TASK' already exists $TARGETDAY!" @@ -224,14 +220,12 @@ clean() { show_usage() { echo "y - the existentialist task manager" echo "Usage: y -> show all tasks" - echo " y do (today|tomorrow|later]) Fix printer -> Create new task, defaults to 'today'." + echo " y do (today|tomorrow) Fix printer -> Create new task, defaults to 'today'." echo " y done Fix printer -> mark task as done" echo " y do Fix printer (if task already exists) -> open task in Vim to add notes" echo " y procrastinate Fix printer -> move task to tomorrow" - echo " y superprocrastinate Fix printer -> move task to backlog" echo " y prioritize Fix printer -> toggle mark task as important" - echo " y vanish today|tomorrow|later Fix printer -> delete task" - echo " y later -> take a look at your backlog" + echo " y vanish today|tomorrow Fix printer -> delete task" echo " y feierabend -> done for the day" exit 0 } @@ -343,7 +337,7 @@ case "$1" in ;; procrastinate|proc) shift; TASK="$@" - procrastinate tomorrow + procrastinate exit 0 ;; feierabend) From 83ccd242cf578935b41bc636dab68be722b05158 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 13:39:35 +0200 Subject: [PATCH 06/29] remove backlog from procrastinate function --- y.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/y.sh b/y.sh index 261d2fc..b5671a1 100755 --- a/y.sh +++ b/y.sh @@ -186,15 +186,12 @@ feierabend() { } procrastinate() { - SOURCEDAY="today" - TARGETDAY="tomorrow" - if [[ -e $DATADIR/$SOURCEDAY/"$TASK" ]]; then - if [[ ! -e $DATADIR/$TARGETDAY/"$TASK" ]]; then - mv $DATADIR/$SOURCEDAY/"$TASK" $DATADIR/$TARGETDAY/"$TASK" - echo -e "'$TASK' moved to ${BLUE}$TARGETDAY.${NC}" - print_demotivation + if [[ -e $DATADIR/today/"$TASK" ]]; then + if [[ ! -e $DATADIR/tomorrow/"$TASK" ]]; then + mv $DATADIR/today/"$TASK" $DATADIR/tomorrow/"$TASK" + echo -e "'$TASK' moved to ${BLUE}tomorrow${NC}." else - echo "'$TASK' already exists $TARGETDAY!" + echo "'$TASK' already exists tomorrow!" fi else show_usage From bbbae1f40b1177c9979a07385a1090e2375dee60 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 17:22:51 +0200 Subject: [PATCH 07/29] remove old backlog feature from Readme --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ed4e9e..77d721a 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,11 @@ ## Usage + `y` -> show all tasks -+ `y do (today|tomorrow|later) Fix printer` -> Create new task, defaults to 'today', or move to today if it exists tomorrow or later ++ `y do (today|tomorrow) Fix printer` -> Create new task, defaults to 'today', or move to today if it exists tomorrow + `y done Fix printer` -> mark task as done + `y do Fix printer` (if task already exists) -> open task in Vim to add notes (absolutely not compatible with any other editor, nu-uh, sorry) (not sorry) + `y procrastinate Fix printer` -> move task to tomorrow -+ `y superprocrastinate Fix printer` -> move task to backlog + `y prioritize Fix printer` -> toggle mark task as important - -+ `y later` -> take a look at your backlog + `y feierabend` -> done for the day ## Setup From 4f2ead58a3633ea54e0bc28ce6504c6898bb6be6 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 29 Jul 2024 17:35:39 +0200 Subject: [PATCH 08/29] finish removing later feature --- README.md | 12 ++++++++++++ y.sh | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 77d721a..50e0be0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,18 @@ ![Screenshot](https://i.imgur.com/HjUO133.png) +## You're on the v2 development branch! +Notice: this branch is unstable and likely to change. Here's the v2 roadmap: + +- [x] add "focus mode" to keep track of the task you're currently working on +- [x] remove "later" / "backlog" feature that no one used +- [x] remove cringey motivation / demotivation / headline +- [ ] maybe: add new motivation? +- [ ] maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism +- [ ] refactor entire codebase, make shellcheck report _nothing_ +- [ ] clean up other youth sins +- [ ] add better comments, remove bad comments + ## Features + Ask yourself: "y the hell am I doing this?" with every new task + Semi-functional bash completion diff --git a/y.sh b/y.sh index b5671a1..0f110b3 100755 --- a/y.sh +++ b/y.sh @@ -74,12 +74,10 @@ add_task() { vi $DATADIR/$DAY/"$TASK" exit 0 fi - for SOURCEDAY in "tomorrow" "later"; do - if [[ $DAY == "today" ]] && [[ -e $DATADIR/$SOURCEDAY/"$TASK" ]]; then # if tasks exists in tomorrow or later, move to today - echo "Task exists in $SOURCEDAY - moving it to today" - mv $DATADIR/$SOURCEDAY/"$TASK" $DATADIR/today/"$TASK" - fi - done + if [[ $DAY == "today" ]] && [[ -e $DATADIR/tomorrow/"$TASK" ]]; then # if tasks exists in tomorrow, move to today + echo "Task exists tomorrow - moving it to today" + mv $DATADIR/tomorrow/"$TASK" $DATADIR/today/"$TASK" + fi # experimental ghetto input validation if [[ "$TASK" =~ ^\. ]] || [[ "$TASK" =~ [\*\/\;] ]]; then echo "Error: a task name can not start with a . or contain any of the following characters: * / ;. Exiting." @@ -203,7 +201,7 @@ procrastinate() { clean() { read -p "Are you SURE you want to irrecoverably delete ALL of your entries? (yes/no) " cleanyn case $cleanyn in - [Yy]*) for i in today tomorrow later done; do rm -rf "$DATADIR"/$i/*; done + [Yy]*) for i in today tomorrow done archive started; do rm -rf "$DATADIR"/$i/*; done rm $BASEDIR/git.log echo "All entries deleted." exit 0 @@ -240,9 +238,13 @@ if _check_if_task_started; then echo "tbd: edit tasks or add new ones while in focus mode" exit 1 ;; + done) + echo "tbd: mark task as done and stop focus mode" + exit 1 + ;; stop) mv $DATADIR/started/* $DATADIR/today/ - echo "Stopped working on all tasks." + echo "Stopped working on your task." exit 0 ;; *) @@ -261,7 +263,6 @@ if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow print_tasks today Today: $GREEN print_tasks tomorrow Tomorrow: $BLUE print_tasks done Done: $YELLOW - # print_tasks later Later $RED # in case one wants that... exit 0 fi @@ -270,7 +271,7 @@ case "$1" in do) case "$2" in - today|tomorrow|later) # parse day + today|tomorrow) # parse day DAY=$2 shift; shift add_task $DAY "$@" @@ -352,7 +353,7 @@ case "$1" in exit 0 ;; vanish|rm) # unfinished - do not use - if [[ "$2" == "today" || "$2" == "tomorrow" || "$2" == "later" ]]; then + if [[ "$2" == "today" || "$2" == "tomorrow" ]]; then DAY="$2" shift; shift TASK="$@" From 2440ef910f4fd8ad47654258fc8f5c782c6e0668 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Wed, 31 Jul 2024 11:57:07 +0200 Subject: [PATCH 09/29] read EDITOR variable --- README.md | 1 + y.sh | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50e0be0..2acb185 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [x] remove cringey motivation / demotivation / headline - [ ] maybe: add new motivation? - [ ] maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism +- [x] read EDITOR variable, default to vi - [ ] refactor entire codebase, make shellcheck report _nothing_ - [ ] clean up other youth sins - [ ] add better comments, remove bad comments diff --git a/y.sh b/y.sh index 0f110b3..e425d8b 100755 --- a/y.sh +++ b/y.sh @@ -70,8 +70,11 @@ add_task() { shift TASK="$@" if [[ -e $DATADIR/$DAY/"$TASK" ]]; then # open in editor if task already exists - echo "Task '$TASK' exists, opening in editor..." - vi $DATADIR/$DAY/"$TASK" + if [[ -z $EDITOR ]]; then + EDITOR=vi + fi + echo "Task '$TASK' exists, opening in $EDITOR..." + $EDITOR $DATADIR/$DAY/"$TASK" exit 0 fi if [[ $DAY == "today" ]] && [[ -e $DATADIR/tomorrow/"$TASK" ]]; then # if tasks exists in tomorrow, move to today From 2e53541ce3f6d719617093d1579167c394aede91 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 1 Aug 2024 11:10:39 +0200 Subject: [PATCH 10/29] create cringe mode and make cringe stuff only appear if it's enabled --- y.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/y.sh b/y.sh index e425d8b..46fbc99 100755 --- a/y.sh +++ b/y.sh @@ -1,5 +1,6 @@ #!/bin/bash +# Constants MOTIVATION=("u should be proud of urself" "u r da man, man" "u da best" "look at u go" "nice work, yay" "u amazinggggggg" "u did good, kid" "this shit is bananas, B-A-N-A-N-A-S!" "the best there ever was" "u the real mvp" "now go treat yoself") DEMOTIVATION=("u lazy piece of shit" "weeeell done *slow clap*" "son i am disappoint" "lauch" "u suck" "all you had to do was follow the damn train!" "the fuck is wrong with you" "try harder, pal" "congratulations on your spectacular failure" "hope ur proud of urself") HEADLINE=("Frisch ans Werk, Freund!" "Morgenstund hat Gold im Mund!" "Wer wagt, gewinnt!" "Müßiggang ist aller Laster Anfang!" "Wer wagt, gewinnt!" "Den Tüchtigen gehört die Welt!" "Gib jedem Tag die Chance, der produktivste deines Lebens zu werden!" "Ich arbeite gern für meinen Konzern!" "You gotta do what you gotta do 👍" "Wir haben uns alle lieb im Betrieb!" "Der frühe Vogel fängt den Wurm!" "Die schönste Zeit... ist die Arbeit!" "Frage nicht, was dein Arbeitsplatz für dich tun kann - frage, was du für deinen Arbeitsplatz tun kannst!" "Die schönste Musik? - Der Sound der Fabrik!") @@ -25,6 +26,10 @@ if [[ ! "$DOLLARNULL" == *nocolor* ]]; then NC='\033[0m' # No Color fi +# Configuration +## turn on cringe mode if you want the cringey motivational thingsies +CRINGE_MODE=0 + print_tasks() { if [[ ! -d "$DATADIR/$1" ]]; then echo "Directory '$1' not found! Exiting." @@ -52,10 +57,12 @@ print_tasks() { } print_motivation() { - MOTIVOUT=${MOTIVATION[$(shuf -i 0-$((${#MOTIVATION[@]}-1)) -n 1)]} - printf \\n - echo -e ${YELLOW}$MOTIVOUT${NC} - printf \\n + if [[ $CRINGE_MODE != 0 ]] then + MOTIVOUT=${MOTIVATION[$(shuf -i 0-$((${#MOTIVATION[@]}-1)) -n 1)]} + printf \\n + echo -e ${YELLOW}$MOTIVOUT${NC} + printf \\n + fi } print_demotivation() { @@ -123,8 +130,8 @@ feierabend() { mkdir $DATADIR/archive/$TODAYSDATE fi if [[ ! $(find . -maxdepth 1 -type f) ]]; then - echo "u did absolutely nothing today." - # print_demotivation + echo "u did absolutely nothing $1." + print_demotivation else echo -e "${GREEN}here's what u did today${NC}" printf \\n # show all files from 'done' @@ -261,8 +268,10 @@ fi # now for "normal mode" where no task has been started if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow # use the following syntax: directory name, day in "readable case" and name of color variable - #HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} - #echo -e ${BOLD}$HEADLINEOUT${NC} + if [[ $CRINGE_MODE != 0 ]] then + HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} + echo -e ${BOLD}$HEADLINEOUT${NC} + fi print_tasks today Today: $GREEN print_tasks tomorrow Tomorrow: $BLUE print_tasks done Done: $YELLOW @@ -308,7 +317,7 @@ case "$1" in mv $DATADIR/today/"$TASK" $DATADIR/done/ printf \\n echo "Done: $TASK." - # print_motivation + print_motivation ;; start) From 4d75477e74bce6b15a4129eca59b5aa122076b4a Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 1 Aug 2024 11:11:47 +0200 Subject: [PATCH 11/29] change feierabend() to next_day() and add gumo keyword --- y.sh | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/y.sh b/y.sh index 46fbc99..140c219 100755 --- a/y.sh +++ b/y.sh @@ -123,17 +123,23 @@ prioritize() { fi } -feierabend() { +#feierabend() { +next_day() { + # $1 for "today" or "yesterday" cd $DATADIR/done - TODAYSDATE=$(date --iso-8601) - if [[ ! -d $DATADIR/archive/$TODAYSDATE ]]; then - mkdir $DATADIR/archive/$TODAYSDATE + if [[ "$1" == "yesterday" ]] then + DATE_OF_WORKDAY=$(date --date yesterday --iso-8601) + else + DATE_OF_WORKDAY=$(date --iso-8601) + fi + if [[ ! -d $DATADIR/archive/$DATE_OF_WORKDAY ]]; then + mkdir $DATADIR/archive/$DATE_OF_WORKDAY fi if [[ ! $(find . -maxdepth 1 -type f) ]]; then echo "u did absolutely nothing $1." print_demotivation else - echo -e "${GREEN}here's what u did today${NC}" + echo -e "${GREEN}here's what u did ${1}${NC}" printf \\n # show all files from 'done' for f in *; do if ! [[ -d $f ]]; then @@ -142,26 +148,16 @@ feierabend() { sleep 0.05 done printf \\n - mv "$f" $DATADIR/archive/$TODAYSDATE + mv "$f" $DATADIR/archive/$DATE_OF_WORKDAY sleep 0.5s fi done - # print_motivation + print_motivation fi find "$DATADIR/tomorrow" -type f ! -name ".*" -exec mv "{}" "$DATADIR/today/" \; 2> /dev/null # move task from tomorrow to today -# unfinished 'show task age' thing -# the idea is to mark all tasks as important that are older than a week. this could be done on feierabend. -# CURRTIME=$(date +%s) -# for f in $DATADIR/today/*; do -# if [[ ! "$f" == "! *" ]]; then -# CHANGETIME=$(stat -c %Y "$f") -# echo "last change: $CHANGETIME, now: $CURRTIME" -# fi -# done - cd $DATADIR - COMMITMESSAGE="Feierabend $(date '+%F %T')" + COMMITMESSAGE="End of day $(date '+%F %T')" echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log git add --all >> $BASEDIR/git.log printf "+ git commit... " @@ -189,8 +185,12 @@ feierabend() { fi echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log printf \\n - echo "Remember to stop your timetracking." - echo "Good night!" + if [[ "$1" == "yesterday" ]] then + echo "Have a great day! 🌞" + else + echo "Remember to stop your timetracking." + echo "Good night!" + fi } procrastinate() { @@ -231,6 +231,7 @@ show_usage() { echo " y procrastinate Fix printer -> move task to tomorrow" echo " y prioritize Fix printer -> toggle mark task as important" echo " y vanish today|tomorrow Fix printer -> delete task" + echo " y gumo -> starting the day" echo " y feierabend -> done for the day" exit 0 } @@ -351,7 +352,11 @@ case "$1" in exit 0 ;; feierabend) - feierabend + next_day today + exit 0 + ;; + gumo) + next_day yesterday exit 0 ;; clean) From 9f0d94aaf9159cd5acc377a9a29f46a10cf54c26 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 1 Aug 2024 11:12:09 +0200 Subject: [PATCH 12/29] add GuMo feature to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2acb185..5adaf7b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [ ] maybe: add new motivation? - [ ] maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism - [x] read EDITOR variable, default to vi +- [ ] add GuMo syntax to Feierabend - [ ] refactor entire codebase, make shellcheck report _nothing_ - [ ] clean up other youth sins - [ ] add better comments, remove bad comments From 1bd433a73439f021a4d262ebc8976cd2302b954f Mon Sep 17 00:00:00 2001 From: colorchestra Date: Mon, 12 Aug 2024 10:46:46 +0200 Subject: [PATCH 13/29] no longer add tasks using "done" --- y.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/y.sh b/y.sh index 140c219..e440bc7 100755 --- a/y.sh +++ b/y.sh @@ -189,7 +189,7 @@ next_day() { echo "Have a great day! 🌞" else echo "Remember to stop your timetracking." - echo "Good night!" + echo "Good night! 🌙" fi } @@ -313,7 +313,8 @@ case "$1" in fi shift; TASK="$@" if ! [[ -e $DATADIR/today/"$TASK" ]]; then - add_task today "$TASK" + echo "Error: task '"${TASK}"' doesn't exist" + exit 1 fi mv $DATADIR/today/"$TASK" $DATADIR/done/ printf \\n From 26007d7a54b6963a92ee8ac85d39adeffd824881 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 19 Sep 2024 14:28:38 +0200 Subject: [PATCH 14/29] remove unnecessary linefeed --- y.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/y.sh b/y.sh index e440bc7..40f0231 100755 --- a/y.sh +++ b/y.sh @@ -317,7 +317,6 @@ case "$1" in exit 1 fi mv $DATADIR/today/"$TASK" $DATADIR/done/ - printf \\n echo "Done: $TASK." print_motivation ;; @@ -338,11 +337,9 @@ case "$1" in add_task today "$TASK" fi mv $DATADIR/today/"$TASK" $DATADIR/started/ - printf \\n echo "Started work on task $TASK." ;; - - prioritize|prio) # still janky and beta + prioritize|prio) shift; TASK="$@" prioritize exit 0 From 9715f097d0bf7ca94bd476c86ed5a483c70033bb Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 19 Sep 2024 14:28:58 +0200 Subject: [PATCH 15/29] add some more tasks to readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5adaf7b..88cd87f 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,15 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [x] remove cringey motivation / demotivation / headline - [ ] maybe: add new motivation? - [ ] maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism +- [x] remove instant creation of non-existant tasks with "done" - [x] read EDITOR variable, default to vi -- [ ] add GuMo syntax to Feierabend +- [x] add GuMo syntax to Feierabend - [ ] refactor entire codebase, make shellcheck report _nothing_ - [ ] clean up other youth sins - [ ] add better comments, remove bad comments +- [ ] rename y.sh to y +- [ ] move things to proper directories (~/.local/bin, ~/.config/something?) +- [ ] fix vanish/rm ## Features + Ask yourself: "y the hell am I doing this?" with every new task From 3031f3c951e64dc69be303cf0eb2d3799df4e5e3 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 20 Sep 2024 14:57:27 +0200 Subject: [PATCH 16/29] add helper functions to check if task exists and exit if it doesn't --- y.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/y.sh b/y.sh index 40f0231..ff9582a 100755 --- a/y.sh +++ b/y.sh @@ -106,6 +106,28 @@ _check_if_task_started() { fi } +_check_if_task_exists() { + # $1 is the day, rest is task name + DAY="$1" + shift + TASK="$*" + + if [[ -e "$DATADIR"/"$DAY"/"$TASK" ]]; then + return 0 + else + return 1 + fi +} + +_error_task_doesnt_exist() { + if [ -z "$1" ]; then + echo -e "${RED}Error${NC}: task doesn't exist!" + else + echo -e "${RED}Error${NC}: task '$*' doesn't exist!" + fi + exit 1 +} + prioritize() { if ! [[ -e $DATADIR/today/"$TASK" ]]; then echo "No such task!" @@ -311,12 +333,9 @@ case "$1" in show_usage exit 1 fi - shift; TASK="$@" - if ! [[ -e $DATADIR/today/"$TASK" ]]; then - echo "Error: task '"${TASK}"' doesn't exist" - exit 1 - fi - mv $DATADIR/today/"$TASK" $DATADIR/done/ + shift; TASK="$*" + _check_if_task_exists 'today' "$TASK" || _error_task_doesnt_exist "$TASK" + mv "$DATADIR"/today/"$TASK" "$DATADIR"/done/ echo "Done: $TASK." print_motivation ;; From 1e3b1af55e2d6d18008610cf422c99f0384ff874 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 20 Sep 2024 15:02:17 +0200 Subject: [PATCH 17/29] fix most shellcheck findings --- README.md | 4 +- setup.sh | 14 +++--- y.sh | 129 ++++++++++++++++++++++++++---------------------------- 3 files changed, 72 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 88cd87f..2dd7e73 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,14 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [x] remove instant creation of non-existant tasks with "done" - [x] read EDITOR variable, default to vi - [x] add GuMo syntax to Feierabend -- [ ] refactor entire codebase, make shellcheck report _nothing_ +- [x] refactor entire codebase, make shellcheck report _nothing_ +- [ ] fix remaining shellcheck todos - [ ] clean up other youth sins - [ ] add better comments, remove bad comments - [ ] rename y.sh to y - [ ] move things to proper directories (~/.local/bin, ~/.config/something?) - [ ] fix vanish/rm +- [ ] fix behaviour of deprioritizing (make callable without !) ## Features + Ask yourself: "y the hell am I doing this?" with every new task diff --git a/setup.sh b/setup.sh index 49cee5c..548abf7 100755 --- a/setup.sh +++ b/setup.sh @@ -17,22 +17,20 @@ sed -i '/y\/completion.sh/d' ~/.bashrc # todo: feedback printf "Writing new aliases to .bashrc... " -echo "alias y='$BASEDIR/y.sh'" >> ~/.bashrc -if [ $? -eq 0 ]; then +if echo "alias y='$BASEDIR/y.sh'" >> ~/.bashrc; then printf "Successful.\n" else printf "Error!\n" fi printf "Writing completion stuff to .bashrc... " -echo "source $BASEDIR/completion.sh" >> ~/.bashrc -if [ $? -eq 0 ]; then +if echo "source $BASEDIR/completion.sh" >> ~/.bashrc; then printf "Successful.\n" else printf "Error!\n" fi -read -p "Do you have an existing y data directory, e.g. in a Git repo? (yes/no) " yn +read -rp "Do you have an existing y data directory, e.g. in a Git repo? (yes/no) " yn case $yn in [Yy]* ) echo "Please manually copy/clone your data directory now." # to do: automatically clone if repo link is inserted ;; @@ -47,10 +45,10 @@ case $yn in printf "Directory already exists!\n" fi - cd "$DATADIR" + cd "$DATADIR" || exit 1 printf "Creating daily directories...\n" - for d in today tomorrow done archive started; do + for d in 'today' 'tomorrow' 'done' 'archive' 'started'; do if ! [[ -d "$d" ]]; then mkdir "$d" printf " Directory '$d' created.\n" @@ -60,7 +58,7 @@ case $yn in fi done git init - cd "$BASEDIR" + cd "$BASEDIR" || exit 1 ;; esac diff --git a/y.sh b/y.sh index ff9582a..7c6bb9c 100755 --- a/y.sh +++ b/y.sh @@ -8,7 +8,7 @@ HEADLINE=("Frisch ans Werk, Freund!" "Morgenstund hat Gold im Mund!" "Wer wagt, BASEDIR=~/y DEFAULTDATADIR=$BASEDIR/data -if [ -z $DATADIR ]; then +if [ -z "$DATADIR" ]; then DATADIR="$DEFAULTDATADIR" fi @@ -35,13 +35,13 @@ print_tasks() { echo "Directory '$1' not found! Exiting." exit 1 fi - cd $DATADIR/$1 + cd "$DATADIR"/"$1" || exit 1 for f in *; do NAME=$f COMMENTSTRING="" if [[ ! -d $f ]]; then if [[ $NAME == "! "* ]]; then - NAME=$(echo $NAME | cut -c3-) + NAME=$(echo "$NAME" | cut -c3-) OUTPUTSTRING=$(printf "%s%-10s${RED}! ${NC}%s\n" "$3" "$2" "$NAME") else OUTPUTSTRING=$(printf "%s%-12s${NC}%s\n" "$3" "$2" "$NAME") @@ -52,15 +52,15 @@ print_tasks() { fi fi echo -e "$OUTPUTSTRING" - if [ ! -z "$COMMENTSTRING" ]; then echo -e "$COMMENTSTRING"; fi + if [ -n "$COMMENTSTRING" ]; then echo -e "$COMMENTSTRING"; fi done } print_motivation() { - if [[ $CRINGE_MODE != 0 ]] then + if [[ $CRINGE_MODE != 0 ]]; then MOTIVOUT=${MOTIVATION[$(shuf -i 0-$((${#MOTIVATION[@]}-1)) -n 1)]} printf \\n - echo -e ${YELLOW}$MOTIVOUT${NC} + echo -e "${YELLOW}""$MOTIVOUT""${NC}" printf \\n fi } @@ -68,38 +68,38 @@ print_motivation() { print_demotivation() { DEMOTIVOUT=${DEMOTIVATION[$(shuf -i 0-$((${#DEMOTIVATION[@]}-1)) -n 1)]} printf \\n - echo -e ${RED}$DEMOTIVOUT${NC} + echo -e "${RED}""$DEMOTIVOUT""${NC}" printf \\n } add_task() { DAY="$1" shift - TASK="$@" + TASK="$*" if [[ -e $DATADIR/$DAY/"$TASK" ]]; then # open in editor if task already exists if [[ -z $EDITOR ]]; then - EDITOR=vi + export EDITOR=vi fi echo "Task '$TASK' exists, opening in $EDITOR..." - $EDITOR $DATADIR/$DAY/"$TASK" + $EDITOR "$DATADIR"/"$DAY"/"$TASK" exit 0 fi if [[ $DAY == "today" ]] && [[ -e $DATADIR/tomorrow/"$TASK" ]]; then # if tasks exists in tomorrow, move to today echo "Task exists tomorrow - moving it to today" - mv $DATADIR/tomorrow/"$TASK" $DATADIR/today/"$TASK" + mv "$DATADIR"/tomorrow/"$TASK" "$DATADIR"/today/"$TASK" fi # experimental ghetto input validation if [[ "$TASK" =~ ^\. ]] || [[ "$TASK" =~ [\*\/\;] ]]; then echo "Error: a task name can not start with a . or contain any of the following characters: * / ;. Exiting." exit 1 fi - touch $DATADIR/$DAY/"$TASK" # create task + touch "$DATADIR"/"$DAY"/"$TASK" # create task echo -e "'$TASK' added for ${GREEN}$DAY!${NC}" } # helper functions, wow! _check_if_task_started() { - if [ -z "$( ls -A $DATADIR/started )" ]; then + if [ -z "$(ls -A "$DATADIR"/started)" ]; then return 1 else return 0 @@ -134,30 +134,29 @@ prioritize() { exit 1 else if [[ "$TASK" == "! "* ]]; then - mv "$DATADIR/today/$TASK" "$DATADIR/today/$(echo $TASK | cut -c3-)" - echo "De-prioritized task '$(echo $TASK | cut -c3-)'." - exit 0 + mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/"$(echo "$TASK" | cut -c3-)" + echo "De-prioritized task '$(echo "$TASK" | cut -c3-)'." else - mv "$DATADIR/today/$TASK" "$DATADIR/today/! $TASK" + # TODO can this be nicened up without a shellcheck finding? + mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/!\ "$TASK" echo "Prioritized task '! $TASK'." - exit fi fi } -#feierabend() { next_day() { # $1 for "today" or "yesterday" - cd $DATADIR/done - if [[ "$1" == "yesterday" ]] then - DATE_OF_WORKDAY=$(date --date yesterday --iso-8601) + cd "$DATADIR"/done || exit 1 + if [[ "$1" == "yesterday" ]]; then + DATE_OF_WORKDAY="$(date --date yesterday --iso-8601)" else - DATE_OF_WORKDAY=$(date --iso-8601) + DATE_OF_WORKDAY="$(date --iso-8601)" fi - if [[ ! -d $DATADIR/archive/$DATE_OF_WORKDAY ]]; then - mkdir $DATADIR/archive/$DATE_OF_WORKDAY + if [[ ! -d "$DATADIR"/archive/"$DATE_OF_WORKDAY" ]]; then + mkdir "$DATADIR"/archive/"$DATE_OF_WORKDAY" fi - if [[ ! $(find . -maxdepth 1 -type f) ]]; then + # TODO: find here vs ls above? + if [[ ! "$(find . -maxdepth 1 -type f)" ]]; then echo "u did absolutely nothing $1." print_demotivation else @@ -166,11 +165,13 @@ next_day() { for f in *; do if ! [[ -d $f ]]; then for (( c=0; c < ${#f}; c++ )); do # super flashy magic effect thingy + # TODO shellcheck + # shellcheck disable=SC2059 printf "${f:$c:1}" sleep 0.05 done printf \\n - mv "$f" $DATADIR/archive/$DATE_OF_WORKDAY + mv "$f" "$DATADIR"/archive/"$DATE_OF_WORKDAY" sleep 0.5s fi done @@ -178,12 +179,14 @@ next_day() { fi find "$DATADIR/tomorrow" -type f ! -name ".*" -exec mv "{}" "$DATADIR/today/" \; 2> /dev/null # move task from tomorrow to today - cd $DATADIR + cd "$DATADIR" || exit 1 COMMITMESSAGE="End of day $(date '+%F %T')" echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log git add --all >> $BASEDIR/git.log printf "+ git commit... " COMMITOUTPUT=$(git commit -m "$COMMITMESSAGE") + # TODO + # shellcheck disable=SC2181 if [[ $? -eq 0 ]]; then printf "${GREEN}%12s${NC}\n" "Successful" echo "$COMMITOUTPUT" >> $BASEDIR/git.log @@ -207,7 +210,7 @@ next_day() { fi echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log printf \\n - if [[ "$1" == "yesterday" ]] then + if [[ "$1" == "yesterday" ]]; then echo "Have a great day! 🌞" else echo "Remember to stop your timetracking." @@ -218,25 +221,23 @@ next_day() { procrastinate() { if [[ -e $DATADIR/today/"$TASK" ]]; then if [[ ! -e $DATADIR/tomorrow/"$TASK" ]]; then - mv $DATADIR/today/"$TASK" $DATADIR/tomorrow/"$TASK" + mv "$DATADIR"/today/"$TASK" "$DATADIR"/tomorrow/"$TASK" echo -e "'$TASK' moved to ${BLUE}tomorrow${NC}." else echo "'$TASK' already exists tomorrow!" fi else show_usage + exit 1 fi - exit 0 - } clean() { - read -p "Are you SURE you want to irrecoverably delete ALL of your entries? (yes/no) " cleanyn + read -rp "Are you SURE you want to irrecoverably delete ALL of your entries? (yes/no) " cleanyn case $cleanyn in - [Yy]*) for i in today tomorrow done archive started; do rm -rf "$DATADIR"/$i/*; done + [Yy]*) for i in 'today' 'tomorrow' 'done' 'archive' 'started'; do rm -rf "${DATADIR:?}"/"${i}"/*; done rm $BASEDIR/git.log echo "All entries deleted." - exit 0 ;; *) echo "Aborting." exit 1 @@ -255,15 +256,14 @@ show_usage() { echo " y vanish today|tomorrow Fix printer -> delete task" echo " y gumo -> starting the day" echo " y feierabend -> done for the day" - exit 0 } # main script starts here! # first: check if work has been started on anything / "focus mode" if _check_if_task_started; then - if [ -z $1 ]; then - echo -e ${BOLD}Focus!${NC} - print_tasks started "Currently working on: " $MAGENTA + if [ -z "$1" ]; then + echo -e "${BOLD}Focus!${NC}" + print_tasks started "Currently working on: " "$MAGENTA" exit 0 else case "$1" in @@ -276,7 +276,7 @@ if _check_if_task_started; then exit 1 ;; stop) - mv $DATADIR/started/* $DATADIR/today/ + mv "$DATADIR"/started/* "$DATADIR"/today/ echo "Stopped working on your task." exit 0 ;; @@ -289,15 +289,15 @@ if _check_if_task_started; then fi # now for "normal mode" where no task has been started -if [ -z $1 ]; then # if no arguments given, print all tasks today and tomorrow +if [ -z "$1" ]; then # if no arguments given, print all tasks today and tomorrow # use the following syntax: directory name, day in "readable case" and name of color variable - if [[ $CRINGE_MODE != 0 ]] then + if [[ "$CRINGE_MODE" != 0 ]]; then HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} - echo -e ${BOLD}$HEADLINEOUT${NC} + echo -e "${BOLD}$HEADLINEOUT${NC}" fi - print_tasks today Today: $GREEN - print_tasks tomorrow Tomorrow: $BLUE - print_tasks done Done: $YELLOW + print_tasks 'today' 'Today:' "$GREEN" + print_tasks 'tomorrow' 'Tomorrow:' "$BLUE" + print_tasks 'done' 'Done:' "$YELLOW" exit 0 fi @@ -309,7 +309,7 @@ case "$1" in today|tomorrow) # parse day DAY=$2 shift; shift - add_task $DAY "$@" + add_task "$DAY" "$@" exit 0 ;; @@ -350,21 +350,21 @@ case "$1" in show_usage exit 1 fi - shift; TASK="$@" + shift; TASK="$*" # create and start task if it doesn't exist if ! [[ -e $DATADIR/today/"$TASK" ]]; then add_task today "$TASK" fi - mv $DATADIR/today/"$TASK" $DATADIR/started/ + mv "$DATADIR"/today/"$TASK" "$DATADIR"/started/ echo "Started work on task $TASK." ;; prioritize|prio) - shift; TASK="$@" + shift; TASK="$*" prioritize exit 0 ;; procrastinate|proc) - shift; TASK="$@" + shift; TASK="$*" procrastinate exit 0 ;; @@ -381,32 +381,29 @@ case "$1" in exit 0 ;; pull) - cd "$DATADIR" + cd "$DATADIR" || exit 1 echo "Pulling fresh data from $(git remote get-url --push origin)..." git pull exit 0 ;; - vanish|rm) # unfinished - do not use + vanish|rm) if [[ "$2" == "today" || "$2" == "tomorrow" ]]; then DAY="$2" shift; shift - TASK="$@" - cd "$DATADIR"/"$DAY" - rm "$TASK" - if [[ $? -eq 0 ]]; then - echo -e "Task '$TASK' has vanished." - else # debug - echo "rm has returned non-zero" - fi + else + DAY="today" + shift + fi + TASK="$*" + cd "$DATADIR"/"$DAY" || exit 1 + + if rm "$TASK"; then + echo -e "Task '$TASK' has vanished." exit 0 else - echo "nö" + echo "Removing task failed!" exit 1 fi - cd $DATADIR/today/ - rm "$@" - echo "harharhar" - exit 0 ;; --help|-h) show_usage From 183ef037e346548da86fc09f76268be1ce17b772 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 20 Sep 2024 16:27:15 +0200 Subject: [PATCH 18/29] refactoring! use _check_if_task_exists everywhere --- y.sh | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/y.sh b/y.sh index 7c6bb9c..db4775d 100755 --- a/y.sh +++ b/y.sh @@ -76,7 +76,7 @@ add_task() { DAY="$1" shift TASK="$*" - if [[ -e $DATADIR/$DAY/"$TASK" ]]; then # open in editor if task already exists + if _check_if_task_exists "$DAY" "$TASK"; then # open in editor if task already exists if [[ -z $EDITOR ]]; then export EDITOR=vi fi @@ -84,11 +84,11 @@ add_task() { $EDITOR "$DATADIR"/"$DAY"/"$TASK" exit 0 fi - if [[ $DAY == "today" ]] && [[ -e $DATADIR/tomorrow/"$TASK" ]]; then # if tasks exists in tomorrow, move to today + if [[ $DAY == "today" ]] && _check_if_task_exists 'tomorrow' "$TASK"; then # if tasks exists in tomorrow, move to today echo "Task exists tomorrow - moving it to today" mv "$DATADIR"/tomorrow/"$TASK" "$DATADIR"/today/"$TASK" fi - # experimental ghetto input validation + # ghetto input validation if [[ "$TASK" =~ ^\. ]] || [[ "$TASK" =~ [\*\/\;] ]]; then echo "Error: a task name can not start with a . or contain any of the following characters: * / ;. Exiting." exit 1 @@ -108,11 +108,11 @@ _check_if_task_started() { _check_if_task_exists() { # $1 is the day, rest is task name - DAY="$1" + day_to_check="$1" shift - TASK="$*" + task_to_check="$*" - if [[ -e "$DATADIR"/"$DAY"/"$TASK" ]]; then + if [[ -e "$DATADIR"/"$day_to_check"/"$task_to_check" ]]; then return 0 else return 1 @@ -129,18 +129,13 @@ _error_task_doesnt_exist() { } prioritize() { - if ! [[ -e $DATADIR/today/"$TASK" ]]; then - echo "No such task!" - exit 1 + _check_if_task_exists 'today' "$TASK" || _error_task_doesnt_exist "$TASK" + if [[ "$TASK" == "! "* ]]; then + mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/"$(echo "$TASK" | cut -c3-)" + echo "De-prioritized task '$(echo "$TASK" | cut -c3-)'." else - if [[ "$TASK" == "! "* ]]; then - mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/"$(echo "$TASK" | cut -c3-)" - echo "De-prioritized task '$(echo "$TASK" | cut -c3-)'." - else - # TODO can this be nicened up without a shellcheck finding? - mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/!\ "$TASK" - echo "Prioritized task '! $TASK'." - fi + mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/!\ "$TASK" + echo "Prioritized task '! $TASK'." fi } @@ -219,17 +214,13 @@ next_day() { } procrastinate() { - if [[ -e $DATADIR/today/"$TASK" ]]; then - if [[ ! -e $DATADIR/tomorrow/"$TASK" ]]; then - mv "$DATADIR"/today/"$TASK" "$DATADIR"/tomorrow/"$TASK" - echo -e "'$TASK' moved to ${BLUE}tomorrow${NC}." - else - echo "'$TASK' already exists tomorrow!" - fi + _check_if_task_exists 'today' "$TASK" || _error_task_doesnt_exist "$TASK" + if ! _check_if_task_exists 'tomorrow' "$TASK"; then + mv "$DATADIR"/today/"$TASK" "$DATADIR"/tomorrow/"$TASK" + echo -e "'$TASK' moved to ${BLUE}tomorrow${NC}." else - show_usage - exit 1 - fi + echo "'$TASK' already exists tomorrow!" + fi } clean() { @@ -352,9 +343,8 @@ case "$1" in fi shift; TASK="$*" # create and start task if it doesn't exist - if ! [[ -e $DATADIR/today/"$TASK" ]]; then - add_task today "$TASK" - fi + _check_if_task_exists 'today' "$TASK" || add_task 'today' "$TASK" + mv "$DATADIR"/today/"$TASK" "$DATADIR"/started/ echo "Started work on task $TASK." ;; From 33e0b07beb9ab1f0f695b3db574e560fe3499f4f Mon Sep 17 00:00:00 2001 From: colorchestra Date: Wed, 20 Nov 2024 09:46:14 +0100 Subject: [PATCH 19/29] remove printing motivation --- README.md | 10 +++++++--- y.sh | 33 +++------------------------------ 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 2dd7e73..e4eef17 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [x] add "focus mode" to keep track of the task you're currently working on - [x] remove "later" / "backlog" feature that no one used - [x] remove cringey motivation / demotivation / headline -- [ ] maybe: add new motivation? -- [ ] maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism +- [x] maybe: add new motivation? +- [ ] ~~maybe: add time tracking? It's almost for free with the inclusion of the start/stop mechanism~~ - [x] remove instant creation of non-existant tasks with "done" - [x] read EDITOR variable, default to vi - [x] add GuMo syntax to Feierabend @@ -23,8 +23,12 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [ ] add better comments, remove bad comments - [ ] rename y.sh to y - [ ] move things to proper directories (~/.local/bin, ~/.config/something?) -- [ ] fix vanish/rm +- [x] fix vanish/rm - [ ] fix behaviour of deprioritizing (make callable without !) +- [ ] rename branch to main +- [ ] new screenshot +- [ ] fix rm/vanish completion (borken) +- [ ] make installable to any directory, with symlink from ~/.local/bin ## Features + Ask yourself: "y the hell am I doing this?" with every new task diff --git a/y.sh b/y.sh index db4775d..eafc43f 100755 --- a/y.sh +++ b/y.sh @@ -1,19 +1,14 @@ #!/bin/bash # Constants -MOTIVATION=("u should be proud of urself" "u r da man, man" "u da best" "look at u go" "nice work, yay" "u amazinggggggg" "u did good, kid" "this shit is bananas, B-A-N-A-N-A-S!" "the best there ever was" "u the real mvp" "now go treat yoself") -DEMOTIVATION=("u lazy piece of shit" "weeeell done *slow clap*" "son i am disappoint" "lauch" "u suck" "all you had to do was follow the damn train!" "the fuck is wrong with you" "try harder, pal" "congratulations on your spectacular failure" "hope ur proud of urself") -HEADLINE=("Frisch ans Werk, Freund!" "Morgenstund hat Gold im Mund!" "Wer wagt, gewinnt!" "Müßiggang ist aller Laster Anfang!" "Wer wagt, gewinnt!" "Den Tüchtigen gehört die Welt!" "Gib jedem Tag die Chance, der produktivste deines Lebens zu werden!" "Ich arbeite gern für meinen Konzern!" "You gotta do what you gotta do 👍" "Wir haben uns alle lieb im Betrieb!" "Der frühe Vogel fängt den Wurm!" "Die schönste Zeit... ist die Arbeit!" "Frage nicht, was dein Arbeitsplatz für dich tun kann - frage, was du für deinen Arbeitsplatz tun kannst!" "Die schönste Musik? - Der Sound der Fabrik!") - BASEDIR=~/y DEFAULTDATADIR=$BASEDIR/data +CRINGE_MODE=0 if [ -z "$DATADIR" ]; then DATADIR="$DEFAULTDATADIR" fi -# echo "DEBUG: current DATADIR: $DATADIR" - DOLLARNULL=$(echo "$0" | sed 's/.*\///') if [[ ! "$DOLLARNULL" == *nocolor* ]]; then @@ -26,10 +21,6 @@ if [[ ! "$DOLLARNULL" == *nocolor* ]]; then NC='\033[0m' # No Color fi -# Configuration -## turn on cringe mode if you want the cringey motivational thingsies -CRINGE_MODE=0 - print_tasks() { if [[ ! -d "$DATADIR/$1" ]]; then echo "Directory '$1' not found! Exiting." @@ -56,22 +47,6 @@ print_tasks() { done } -print_motivation() { - if [[ $CRINGE_MODE != 0 ]]; then - MOTIVOUT=${MOTIVATION[$(shuf -i 0-$((${#MOTIVATION[@]}-1)) -n 1)]} - printf \\n - echo -e "${YELLOW}""$MOTIVOUT""${NC}" - printf \\n - fi -} - -print_demotivation() { - DEMOTIVOUT=${DEMOTIVATION[$(shuf -i 0-$((${#DEMOTIVATION[@]}-1)) -n 1)]} - printf \\n - echo -e "${RED}""$DEMOTIVOUT""${NC}" - printf \\n -} - add_task() { DAY="$1" shift @@ -88,7 +63,7 @@ add_task() { echo "Task exists tomorrow - moving it to today" mv "$DATADIR"/tomorrow/"$TASK" "$DATADIR"/today/"$TASK" fi - # ghetto input validation + # input validation should be good enough... if [[ "$TASK" =~ ^\. ]] || [[ "$TASK" =~ [\*\/\;] ]]; then echo "Error: a task name can not start with a . or contain any of the following characters: * / ;. Exiting." exit 1 @@ -153,7 +128,6 @@ next_day() { # TODO: find here vs ls above? if [[ ! "$(find . -maxdepth 1 -type f)" ]]; then echo "u did absolutely nothing $1." - print_demotivation else echo -e "${GREEN}here's what u did ${1}${NC}" printf \\n # show all files from 'done' @@ -170,7 +144,7 @@ next_day() { sleep 0.5s fi done - print_motivation + echo -e "${YELLOW}Well done! 😊${NC}" fi find "$DATADIR/tomorrow" -type f ! -name ".*" -exec mv "{}" "$DATADIR/today/" \; 2> /dev/null # move task from tomorrow to today @@ -328,7 +302,6 @@ case "$1" in _check_if_task_exists 'today' "$TASK" || _error_task_doesnt_exist "$TASK" mv "$DATADIR"/today/"$TASK" "$DATADIR"/done/ echo "Done: $TASK." - print_motivation ;; start) From ff676d66105a276a63e7fc4ad2a11530a94f4977 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Wed, 20 Nov 2024 11:36:02 +0100 Subject: [PATCH 20/29] dynamically find datadir; remove cringe mode --- y.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/y.sh b/y.sh index eafc43f..083344b 100755 --- a/y.sh +++ b/y.sh @@ -2,12 +2,19 @@ # Constants BASEDIR=~/y -DEFAULTDATADIR=$BASEDIR/data -CRINGE_MODE=0 +# find the data directory +for dir in "$HOME/.local/share/y" "$HOME/y/data"; do + if [ -d "$dir" ]; then + DATADIR="$dir" + echo "Found datadir: $dir" + break + fi +done if [ -z "$DATADIR" ]; then - DATADIR="$DEFAULTDATADIR" -fi + echo "No data directory could be found! Aborting." + exit 1 +fi DOLLARNULL=$(echo "$0" | sed 's/.*\///') if [[ ! "$DOLLARNULL" == *nocolor* ]]; then @@ -256,10 +263,6 @@ fi # now for "normal mode" where no task has been started if [ -z "$1" ]; then # if no arguments given, print all tasks today and tomorrow # use the following syntax: directory name, day in "readable case" and name of color variable - if [[ "$CRINGE_MODE" != 0 ]]; then - HEADLINEOUT=${HEADLINE[$(shuf -i 0-$((${#HEADLINE[@]}-1)) -n 1)]} - echo -e "${BOLD}$HEADLINEOUT${NC}" - fi print_tasks 'today' 'Today:' "$GREEN" print_tasks 'tomorrow' 'Tomorrow:' "$BLUE" print_tasks 'done' 'Done:' "$YELLOW" From 7c998c687caff3325fda07c16029aecdf00ae0ad Mon Sep 17 00:00:00 2001 From: colorchestra Date: Wed, 20 Nov 2024 11:40:26 +0100 Subject: [PATCH 21/29] write git.log to datadir --- y.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/y.sh b/y.sh index 083344b..f054700 100755 --- a/y.sh +++ b/y.sh @@ -157,34 +157,34 @@ next_day() { cd "$DATADIR" || exit 1 COMMITMESSAGE="End of day $(date '+%F %T')" - echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log - git add --all >> $BASEDIR/git.log + echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> $DATADIR/git.log + git add --all >> $DATADIR/git.log printf "+ git commit... " COMMITOUTPUT=$(git commit -m "$COMMITMESSAGE") # TODO # shellcheck disable=SC2181 if [[ $? -eq 0 ]]; then printf "${GREEN}%12s${NC}\n" "Successful" - echo "$COMMITOUTPUT" >> $BASEDIR/git.log + echo "$COMMITOUTPUT" >> $DATADIR/git.log if [[ $(git remote show) ]] ; then printf "+ git push... " PUSHOUTPUT=$(git push -u origin master 2>&1) if [[ $? -eq 0 ]]; then printf "${GREEN}%14s${NC}\n" "Successful" - echo "$COMMITOUTPUT" >> $BASEDIR/git.log + echo "$COMMITOUTPUT" >> $DATADIR/git.log else printf "${RED}%10s${NC}\n" "Failed" - echo "$PUSHOUTPUT" >> $BASEDIR/git.log + echo "$PUSHOUTPUT" >> $DATADIR/git.log echo "$PUSHOUTPUT" fi fi else printf "${RED}%8s${NC}\n" "Failed" - echo "$COMMITOUTPUT" >> $BASEDIR/git.log + echo "$COMMITOUTPUT" >> $DATADIR/git.log echo "$COMMITOUTPUT" fi - echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> $BASEDIR/git.log + echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> $DATADIR/git.log printf \\n if [[ "$1" == "yesterday" ]]; then echo "Have a great day! 🌞" @@ -208,7 +208,7 @@ clean() { read -rp "Are you SURE you want to irrecoverably delete ALL of your entries? (yes/no) " cleanyn case $cleanyn in [Yy]*) for i in 'today' 'tomorrow' 'done' 'archive' 'started'; do rm -rf "${DATADIR:?}"/"${i}"/*; done - rm $BASEDIR/git.log + rm $DATADIR/git.log echo "All entries deleted." ;; *) echo "Aborting." From 013ec1ab6a9ce73d320d6768c76f5e5917b8f2e0 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 22 Nov 2024 17:59:32 +0100 Subject: [PATCH 22/29] start reworking setup.sh and installation paths --- README.md | 1 + completion.sh | 12 ++++++++- nul | 1 - setup-legacy.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 24 ++++++------------ y.sh | 8 +++++- 6 files changed, 94 insertions(+), 19 deletions(-) delete mode 100644 nul create mode 100755 setup-legacy.sh diff --git a/README.md b/README.md index e4eef17..8c15685 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [ ] new screenshot - [ ] fix rm/vanish completion (borken) - [ ] make installable to any directory, with symlink from ~/.local/bin +- [ ] eliminate the need for BASEDIR ## Features + Ask yourself: "y the hell am I doing this?" with every new task diff --git a/completion.sh b/completion.sh index 63ab9cd..5987d50 100644 --- a/completion.sh +++ b/completion.sh @@ -18,7 +18,17 @@ _y() { COMPREPLY=( "${tmp[@]// /\ }" ) return 0 ;; - vanish) # extremely ghetto +# TODO - check for files prefixed with '! ' +# prio|prioritize) +# #if [[ "$cur" == "! *"]]; then +# # cur="$(echo $cur | cut -c 3-)" +# #fi +# IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) +# COMPREPLY=( "${tmp[@]// /\ }" ) +# return 0 +# ;; + + vanish|rm) # extremely ghetto opts="today tomorrow" case "${prev}" in today) diff --git a/nul b/nul deleted file mode 100644 index f46afa3..0000000 --- a/nul +++ /dev/null @@ -1 +0,0 @@ -/mnt/c/Program Files/Git/cmd/start-ssh-agent.cmd: line 4: @VERIFY: command not found diff --git a/setup-legacy.sh b/setup-legacy.sh new file mode 100755 index 0000000..548abf7 --- /dev/null +++ b/setup-legacy.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +BASEDIR=~/y +DATADIR=$BASEDIR/data/ + +printf "Creating nocolor symlink... " +if [ ! -h "$BASEDIR/y-nocolor.sh" ]; then + ln -s y.sh y-nocolor.sh + printf "Successful.\n" +else + printf "Symlink already exists!\n" +fi + +echo "Removing old stuff from .bashrc... " +sed -i '/alias y=/d' ~/.bashrc +sed -i '/y\/completion.sh/d' ~/.bashrc +# todo: feedback + +printf "Writing new aliases to .bashrc... " +if echo "alias y='$BASEDIR/y.sh'" >> ~/.bashrc; then + printf "Successful.\n" +else + printf "Error!\n" +fi + +printf "Writing completion stuff to .bashrc... " +if echo "source $BASEDIR/completion.sh" >> ~/.bashrc; then + printf "Successful.\n" +else + printf "Error!\n" +fi + +read -rp "Do you have an existing y data directory, e.g. in a Git repo? (yes/no) " yn +case $yn in + [Yy]* ) echo "Please manually copy/clone your data directory now." # to do: automatically clone if repo link is inserted + ;; + + * ) echo "A local Git repository will be initialized. If you want, set a remote." + + printf "Creating data directory... " + if [ ! -d "$DATADIR" ]; then + mkdir "$DATADIR" + printf "Successful.\n" # naja... + else + printf "Directory already exists!\n" + fi + + cd "$DATADIR" || exit 1 + + printf "Creating daily directories...\n" + for d in 'today' 'tomorrow' 'done' 'archive' 'started'; do + if ! [[ -d "$d" ]]; then + mkdir "$d" + printf " Directory '$d' created.\n" + else + printf " Directory '$d' already exists!\n" + + fi + done + git init + cd "$BASEDIR" || exit 1 + ;; +esac + +echo "Please run 'source ~/.bashrc' to enable bash completion (or start a new shell, or log out and back in)" +echo "Done." +exit diff --git a/setup.sh b/setup.sh index 548abf7..0384389 100755 --- a/setup.sh +++ b/setup.sh @@ -1,28 +1,20 @@ #!/bin/bash -BASEDIR=~/y -DATADIR=$BASEDIR/data/ +DATADIR="$HOME/.local/share/y" + +printf "Copying binary to ~/.local/bin..." +# TODO check if already present etc +cp ./y "$HOME/.local/bin/y" printf "Creating nocolor symlink... " -if [ ! -h "$BASEDIR/y-nocolor.sh" ]; then - ln -s y.sh y-nocolor.sh +if [ ! -h "$HOME/.local/bin/y-nocolor" ]; then + ln -s "$HOME/.local/bin/y" "$HOME/.local/bin/y-nocolor" printf "Successful.\n" else printf "Symlink already exists!\n" fi -echo "Removing old stuff from .bashrc... " -sed -i '/alias y=/d' ~/.bashrc -sed -i '/y\/completion.sh/d' ~/.bashrc -# todo: feedback - -printf "Writing new aliases to .bashrc... " -if echo "alias y='$BASEDIR/y.sh'" >> ~/.bashrc; then - printf "Successful.\n" -else - printf "Error!\n" -fi - +# TODO: can this go somewhere else? printf "Writing completion stuff to .bashrc... " if echo "source $BASEDIR/completion.sh" >> ~/.bashrc; then printf "Successful.\n" diff --git a/y.sh b/y.sh index f054700..774d78e 100755 --- a/y.sh +++ b/y.sh @@ -7,7 +7,8 @@ BASEDIR=~/y for dir in "$HOME/.local/share/y" "$HOME/y/data"; do if [ -d "$dir" ]; then DATADIR="$dir" - echo "Found datadir: $dir" + # TODO log as debug + #echo "Found datadir: $dir" break fi done @@ -28,6 +29,11 @@ if [[ ! "$DOLLARNULL" == *nocolor* ]]; then NC='\033[0m' # No Color fi +# TODO logging +#log() { +# echo " +#} + print_tasks() { if [[ ! -d "$DATADIR/$1" ]]; then echo "Directory '$1' not found! Exiting." From 20a764a903f7040eb6c72236cf42ebc1684bb185 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Tue, 10 Jun 2025 11:08:19 +0200 Subject: [PATCH 23/29] rename y.sh to y --- y.sh => y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename y.sh => y (99%) diff --git a/y.sh b/y similarity index 99% rename from y.sh rename to y index 774d78e..21a1364 100755 --- a/y.sh +++ b/y @@ -174,7 +174,7 @@ next_day() { echo "$COMMITOUTPUT" >> $DATADIR/git.log if [[ $(git remote show) ]] ; then printf "+ git push... " - PUSHOUTPUT=$(git push -u origin master 2>&1) + PUSHOUTPUT=$(git push -u origin 2>&1) if [[ $? -eq 0 ]]; then printf "${GREEN}%14s${NC}\n" "Successful" echo "$COMMITOUTPUT" >> $DATADIR/git.log From e7f5ae671ec10de06fc2598f9d68c1a0186f68ac Mon Sep 17 00:00:00 2001 From: colorchestra Date: Tue, 10 Jun 2025 14:25:45 +0200 Subject: [PATCH 24/29] plonk --- README.md | 9 ++++++++- setup.sh | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c15685..a7e0cdf 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [ ] fix remaining shellcheck todos - [ ] clean up other youth sins - [ ] add better comments, remove bad comments -- [ ] rename y.sh to y +- [x] rename y.sh to y - [ ] move things to proper directories (~/.local/bin, ~/.config/something?) - [x] fix vanish/rm - [ ] fix behaviour of deprioritizing (make callable without !) @@ -30,6 +30,13 @@ Notice: this branch is unstable and likely to change. Here's the v2 roadmap: - [ ] fix rm/vanish completion (borken) - [ ] make installable to any directory, with symlink from ~/.local/bin - [ ] eliminate the need for BASEDIR +### setup.sh +- [ ] check if .local/bin exists on the path find a way to install if it doesn't (either create and add to PATH, or add ~/y to path) +- [ ] fail if things go wrong, don't write completion.sh to bashrc several times or without BASEDIR +- [ ] prompt for existing data repo, clone it automatically +- [ ] add color +- [ ] auto-create 'tomorrow' after cloning data repo because it's never committed + ## Features + Ask yourself: "y the hell am I doing this?" with every new task diff --git a/setup.sh b/setup.sh index 0384389..acec86e 100755 --- a/setup.sh +++ b/setup.sh @@ -2,9 +2,10 @@ DATADIR="$HOME/.local/share/y" -printf "Copying binary to ~/.local/bin..." +printf "Copying binary to ~/.local/bin... " # TODO check if already present etc cp ./y "$HOME/.local/bin/y" +printf "Successful.\n" printf "Creating nocolor symlink... " if [ ! -h "$HOME/.local/bin/y-nocolor" ]; then From af9bf4b7643491ed2dac928e4e839b130ac57358 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 27 Nov 2025 00:44:53 +0100 Subject: [PATCH 25/29] remove BASEDIR, fix some shellchecks, replace ls with find --- y | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/y b/y index 21a1364..f3847e1 100755 --- a/y +++ b/y @@ -1,9 +1,6 @@ #!/bin/bash -# Constants -BASEDIR=~/y - -# find the data directory +# find the data directory: new and legacy for dir in "$HOME/.local/share/y" "$HOME/y/data"; do if [ -d "$dir" ]; then DATADIR="$dir" @@ -87,7 +84,7 @@ add_task() { # helper functions, wow! _check_if_task_started() { - if [ -z "$(ls -A "$DATADIR"/started)" ]; then + if [[ ! "$(find "$DATADIR/started" -maxdepth 1 -type f)" ]]; then return 1 else return 0 @@ -138,7 +135,6 @@ next_day() { if [[ ! -d "$DATADIR"/archive/"$DATE_OF_WORKDAY" ]]; then mkdir "$DATADIR"/archive/"$DATE_OF_WORKDAY" fi - # TODO: find here vs ls above? if [[ ! "$(find . -maxdepth 1 -type f)" ]]; then echo "u did absolutely nothing $1." else @@ -163,34 +159,34 @@ next_day() { cd "$DATADIR" || exit 1 COMMITMESSAGE="End of day $(date '+%F %T')" - echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> $DATADIR/git.log - git add --all >> $DATADIR/git.log + echo "======== Begin Git log for commit '$COMMITMESSAGE' ========" >> "${DATADIR}/git.log" + git add --all >> "${DATADIR}/git.log" printf "+ git commit... " COMMITOUTPUT=$(git commit -m "$COMMITMESSAGE") # TODO # shellcheck disable=SC2181 if [[ $? -eq 0 ]]; then printf "${GREEN}%12s${NC}\n" "Successful" - echo "$COMMITOUTPUT" >> $DATADIR/git.log + echo "$COMMITOUTPUT" >> "${DATADIR}/git.log" if [[ $(git remote show) ]] ; then printf "+ git push... " PUSHOUTPUT=$(git push -u origin 2>&1) if [[ $? -eq 0 ]]; then printf "${GREEN}%14s${NC}\n" "Successful" - echo "$COMMITOUTPUT" >> $DATADIR/git.log + echo "$COMMITOUTPUT" >> "${DATADIR}/git.log" else printf "${RED}%10s${NC}\n" "Failed" - echo "$PUSHOUTPUT" >> $DATADIR/git.log + echo "$PUSHOUTPUT" >> "${DATADIR}/git.log" echo "$PUSHOUTPUT" fi fi else printf "${RED}%8s${NC}\n" "Failed" - echo "$COMMITOUTPUT" >> $DATADIR/git.log + echo "$COMMITOUTPUT" >> "${DATADIR}/git.log" echo "$COMMITOUTPUT" fi - echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> $DATADIR/git.log + echo "========== End Git log for commit '$COMMITMESSAGE' ========" >> "${DATADIR}/git.log" printf \\n if [[ "$1" == "yesterday" ]]; then echo "Have a great day! 🌞" @@ -214,7 +210,7 @@ clean() { read -rp "Are you SURE you want to irrecoverably delete ALL of your entries? (yes/no) " cleanyn case $cleanyn in [Yy]*) for i in 'today' 'tomorrow' 'done' 'archive' 'started'; do rm -rf "${DATADIR:?}"/"${i}"/*; done - rm $DATADIR/git.log + rm "${DATADIR}/git.log" echo "All entries deleted." ;; *) echo "Aborting." From 066d02ba751bae80f289dcaf95c7b99ef5c7cffe Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 27 Nov 2025 01:19:38 +0100 Subject: [PATCH 26/29] deprioritize tasks without ! --- y | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/y b/y index f3847e1..61a1121 100755 --- a/y +++ b/y @@ -26,11 +26,6 @@ if [[ ! "$DOLLARNULL" == *nocolor* ]]; then NC='\033[0m' # No Color fi -# TODO logging -#log() { -# echo " -#} - print_tasks() { if [[ ! -d "$DATADIR/$1" ]]; then echo "Directory '$1' not found! Exiting." @@ -114,10 +109,19 @@ _error_task_doesnt_exist() { } prioritize() { - _check_if_task_exists 'today' "$TASK" || _error_task_doesnt_exist "$TASK" - if [[ "$TASK" == "! "* ]]; then - mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/"$(echo "$TASK" | cut -c3-)" - echo "De-prioritized task '$(echo "$TASK" | cut -c3-)'." + # we're given a task starting with '! ', assuming we want to deprioritize + if [[ "$TASK" == "! "* ]] ; then + if [[ -e "$DATADIR/today/$TASK" ]]; then + mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/"$(echo "$TASK" | cut -c3-)" + echo "De-prioritized task '$(echo "$TASK" | cut -c3-)'." + else + echo -e "${RED}Error${NC}: task '$*' doesn't exist!" + fi + # if no !, check if we have a matching prioritized task to deprioritize + elif [[ -e "$DATADIR/today/! ${TASK}" ]] ; then + mv "${DATADIR}/today/! ${TASK}" "${DATADIR}/today/${TASK}" + echo "De-prioritized task ${TASK}" + # if not, prioritize else mv "$DATADIR"/today/"$TASK" "$DATADIR"/today/!\ "$TASK" echo "Prioritized task '! $TASK'." From e8b93d8b21f37a5bf9ca849b328223d54ce1f394 Mon Sep 17 00:00:00 2001 From: colorchestra Date: Thu, 27 Nov 2025 01:44:07 +0100 Subject: [PATCH 27/29] sorta fix prio completion thing --- completion.sh | 56 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/completion.sh b/completion.sh index 5987d50..6bdf98a 100644 --- a/completion.sh +++ b/completion.sh @@ -1,6 +1,3 @@ -#!/bin/bash -# i have no idea what i'm doing - _y() { local cur prev opts COMREPLY=() @@ -8,7 +5,7 @@ _y() { prev="${COMP_WORDS[COMP_CWORD-1]}" opts="do done procrastinate proc prio prioritize vanish rm feierabend start stop" case "${prev}" in - done|procrastinate|proc|prio|prioritize|start) + done|procrastinate|proc|start) IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) COMPREPLY=( "${tmp[@]// /\ }" ) return 0 @@ -18,15 +15,48 @@ _y() { COMPREPLY=( "${tmp[@]// /\ }" ) return 0 ;; -# TODO - check for files prefixed with '! ' -# prio|prioritize) -# #if [[ "$cur" == "! *"]]; then -# # cur="$(echo $cur | cut -c 3-)" -# #fi -# IFS=$'\n' tmp=( $(compgen -W "$(ls ~/y/data/today)" -- "${COMP_WORDS[$COMP_CWORD]}" )) -# COMPREPLY=( "${tmp[@]// /\ }" ) -# return 0 -# ;; + + prio|prioritize) + # simplified: iterate filenames, strip leading "! " into 's', match prefix, and push appropriate completion + local match_cur="$cur" + local mode=0 # 0=return original, 1=return with leading "! ", 2=return stripped only (prev == '!') + if [[ "${COMP_WORDS[COMP_CWORD-1]}" == '!' ]]; then + mode=2 + match_cur="$cur" + elif [[ "$cur" == '!'* ]]; then + # user typed bang in same word: remove leading '!' and optional space + mode=1 + match_cur="${cur#\!}" + match_cur="${match_cur# }" + else + mode=0 + match_cur="$cur" + fi + + # iterate files and match stripped names by prefix + local f s out + while IFS= read -r f; do + [[ -z "$f" ]] && continue + if [[ "$f" == '! '* ]]; then + s="${f#\! }" + else + s="$f" + fi + # prefix match + if [[ "$s" == "$match_cur"* ]]; then + if [[ $mode -eq 1 ]]; then + out="! ${s}" + elif [[ $mode -eq 2 ]]; then + out="${s}" + else + out="${f}" + fi + COMPREPLY+=( "$out" ) + fi + done < <(ls -1 ~/y/data/today 2>/dev/null) + + return 0 + ;; vanish|rm) # extremely ghetto opts="today tomorrow" From f68f8746e0cdfa0f3ec06a126b1879a2cb7f799f Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 28 Nov 2025 16:05:12 +0100 Subject: [PATCH 28/29] add 'done' feature for focus mode --- y | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/y b/y index 61a1121..dc95afb 100755 --- a/y +++ b/y @@ -250,8 +250,10 @@ if _check_if_task_started; then exit 1 ;; done) - echo "tbd: mark task as done and stop focus mode" - exit 1 + TASK=$(basename "$(find data/started/ -type f)") + mv "${DATADIR}/started/${TASK}" "${DATADIR}/done/" + echo "Done: $TASK". + exit 0 ;; stop) mv "$DATADIR"/started/* "$DATADIR"/today/ From e8e0f0b2e7edc851629326a34824d2352b7f866b Mon Sep 17 00:00:00 2001 From: colorchestra Date: Fri, 28 Nov 2025 16:22:20 +0100 Subject: [PATCH 29/29] move day parsing to function; add 'do' feature to focus mode --- y | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/y b/y index dc95afb..e1e39d9 100755 --- a/y +++ b/y @@ -108,6 +108,30 @@ _error_task_doesnt_exist() { exit 1 } +_parse_day_and_add_task() { + case "$2" in + today|tomorrow) + DAY=$2 + shift; shift + add_task "$DAY" "$@" + exit 0 + ;; + + "") + echo "Error: no task name given" + show_usage + exit 1 + ;; + *) + DAY=today + shift + add_task $DAY "$@" + exit 0 + ;; + esac + +} + prioritize() { # we're given a task starting with '! ', assuming we want to deprioritize if [[ "$TASK" == "! "* ]] ; then @@ -245,9 +269,8 @@ if _check_if_task_started; then exit 0 else case "$1" in - do|edit) - echo "tbd: edit tasks or add new ones while in focus mode" - exit 1 + do) + _parse_day_and_add_task $* ;; done) TASK=$(basename "$(find data/started/ -type f)") @@ -280,29 +303,9 @@ fi ### "normal" mode without any started tasks case "$1" in do) - - case "$2" in - today|tomorrow) # parse day - DAY=$2 - shift; shift - add_task "$DAY" "$@" - exit 0 - ;; - - "") - echo "Error: no task name given" - show_usage - exit 1 - ;; - *) - DAY=today - shift - add_task $DAY "$@" - ;; - esac + _parse_day_and_add_task $* ;; - done) if [ -z "$2" ]; then echo "Error: no task name given"