From ce019c36d0247e2a375a4a039169660d6a558596 Mon Sep 17 00:00:00 2001 From: P-15 Date: Thu, 26 Jun 2025 13:50:41 +0200 Subject: [PATCH 1/3] Improve bash autocompletion script --- misc/bartibCompletion.sh | 54 ++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/misc/bartibCompletion.sh b/misc/bartibCompletion.sh index ed3f2f8..f93f1c3 100644 --- a/misc/bartibCompletion.sh +++ b/misc/bartibCompletion.sh @@ -1,18 +1,52 @@ #!/bin/bash -_bartib_completions() +function _bartib_completions() { - local CWORD=${COMP_WORDS[COMP_CWORD]} - ALL_PROJECTS=`bartib projects` + word="${COMP_WORDS[$COMP_CWORD]}" + prev="${COMP_WORDS[$COMP_CWORD - 1]}" - local IFS=$'\n' - CANDIATE_PROJECTS=($(compgen -W "${ALL_PROJECTS[*]}" -- "$CWORD")) + case "${prev}" in + bartib) + # COMPLETE COMMAND + words="start stop current continue edit report list help cancel check last projects" + COMPREPLY=($(compgen -W "$words" -- "$word")) + ;; + -p) + # COMPLETE PROJECT NAME + local IFS=$'\n' + ALL_PROJECTS=$(bartib projects) + CANDIATE_PROJECTS=($(compgen -W "${ALL_PROJECTS[*]}" -- "$word")) - if [ ${#CANDIATE_PROJECTS[*]} -eq 0 ]; then - COMPREPLY=() - else - COMPREPLY=($(printf "\"%s\"\n" "${CANDIATE_PROJECTS[@]}")) - fi + if [ ${#CANDIATE_PROJECTS[*]} -eq 0 ]; then + COMPREPLY=() + else + COMPREPLY=($(printf "\"%s\"\n" "${CANDIATE_PROJECTS[@]}")) + fi + ;; + -d) + # COMPLETE TASK + local IFS=$'\n' + # Get selected project and remove surrounding quotes + local project="${COMP_WORDS[$COMP_CWORD - 2]}" + project=$(echo "$project" | tr -d '"') + # Get tasks for that project + tasks=$(grep "| $project |" /opt/shared/bartib-hist | cut -d'|' -f 3 | sort | uniq | sed 's/ //' | sed -e 's/\(.*\)/"\1"/') + + candidate_tasks=($(compgen -W "${tasks[*]}" -- "$word")) + + if [ ${#candidate_tasks[*]} -eq 0 ]; then + COMPREPLY=() + else + COMPREPLY=($(printf "\"%s\"\n" "${candidate_tasks[@]}")) + fi + ;; + list|report) + words="--today --help --last_week --current_week --yesterday --project" + COMPREPLY=($(compgen -W "$words" -- "$word")) + ;; + *) + ;; + esac } complete -F _bartib_completions bartib From e16876f230628bb2013d526d5057b93decdafd92 Mon Sep 17 00:00:00 2001 From: P-15 Date: Sat, 24 Jan 2026 18:20:15 +0100 Subject: [PATCH 2/3] Complete description only if BARTIB_FILE is set --- misc/bartibCompletion.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) mode change 100644 => 100755 misc/bartibCompletion.sh diff --git a/misc/bartibCompletion.sh b/misc/bartibCompletion.sh old mode 100644 new mode 100755 index f93f1c3..21dd17e --- a/misc/bartibCompletion.sh +++ b/misc/bartibCompletion.sh @@ -24,20 +24,23 @@ function _bartib_completions() fi ;; -d) - # COMPLETE TASK - local IFS=$'\n' - # Get selected project and remove surrounding quotes - local project="${COMP_WORDS[$COMP_CWORD - 2]}" - project=$(echo "$project" | tr -d '"') - # Get tasks for that project - tasks=$(grep "| $project |" /opt/shared/bartib-hist | cut -d'|' -f 3 | sort | uniq | sed 's/ //' | sed -e 's/\(.*\)/"\1"/') + if [ -n "$BARTIB_FILE" ] + then + # COMPLETE TASK + local IFS=$'\n' + # Get selected project and remove surrounding quotes + local project="${COMP_WORDS[$COMP_CWORD - 2]}" + project=$(echo "$project" | tr -d '"') + # Get tasks for that project + tasks=$(grep "| $project |" /opt/shared/bartib-hist | cut -d'|' -f 3 | sort | uniq | sed 's/ //' | sed -e 's/\(.*\)/"\1"/') - candidate_tasks=($(compgen -W "${tasks[*]}" -- "$word")) + candidate_tasks=($(compgen -W "${tasks[*]}" -- "$word")) - if [ ${#candidate_tasks[*]} -eq 0 ]; then - COMPREPLY=() - else - COMPREPLY=($(printf "\"%s\"\n" "${candidate_tasks[@]}")) + if [ ${#candidate_tasks[*]} -eq 0 ]; then + COMPREPLY=() + else + COMPREPLY=($(printf "\"%s\"\n" "${candidate_tasks[@]}")) + fi fi ;; list|report) From 9f2f1b5131495ba2e075bda3d310838964805b2b Mon Sep 17 00:00:00 2001 From: P-15 Date: Sat, 24 Jan 2026 18:39:49 +0100 Subject: [PATCH 3/3] Add missing options for bash autocompletion --- misc/bartibCompletion.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/misc/bartibCompletion.sh b/misc/bartibCompletion.sh index 21dd17e..472751e 100755 --- a/misc/bartibCompletion.sh +++ b/misc/bartibCompletion.sh @@ -8,10 +8,10 @@ function _bartib_completions() case "${prev}" in bartib) # COMPLETE COMMAND - words="start stop current continue edit report list help cancel check last projects" + words="start stop current continue edit report list help cancel check last projects sanity change" COMPREPLY=($(compgen -W "$words" -- "$word")) ;; - -p) + -p|--project) # COMPLETE PROJECT NAME local IFS=$'\n' ALL_PROJECTS=$(bartib projects) @@ -43,8 +43,12 @@ function _bartib_completions() fi fi ;; - list|report) - words="--today --help --last_week --current_week --yesterday --project" + list) + words="--today --help --last_week --current_week --yesterday --project --no_grouping --date --from --number --round --to" + COMPREPLY=($(compgen -W "$words" -- "$word")) + ;; + report) + words="--today --help --last_week --current_week --yesterday --project --date --from --round --to" COMPREPLY=($(compgen -W "$words" -- "$word")) ;; *)