From 296863c038fd15382d6eb08118e2b8bc43fc7002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Gagn=C3=A9?= Date: Sat, 3 May 2025 14:43:04 -0400 Subject: [PATCH 1/2] Add zsh completions --- README.md | 2 + misc/_bartib | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 misc/_bartib diff --git a/README.md b/README.md index 04bc4ae..73d3528 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,8 @@ Bartib offers a simple auto completion for project names. This saves you from ty For fish users, add the [misc/bartib.fish](misc/bartib.fish) to either the `~/.config/fish/completions/` or `~/.local/share/fish/vendor_completions.d/` directory. Currently, you must set the `BARTIB_FILE` in your fish shell for the project and description names completions. +For zsh users, the `misc/_bartib` file can be used for completions. + ## Command overview All these commands require that you have set the `BARTIB_FILE` environment variable to the file path of your activity log. Otherwise they require an additional `-f/--file` parameter between `bartib` and the subcommand (see above: [How to define in which file to save the log of your activities](#how-to-define-in-which-file-to-save-the-log-of-your-activities)). diff --git a/misc/_bartib b/misc/_bartib new file mode 100644 index 0000000..f7b5fca --- /dev/null +++ b/misc/_bartib @@ -0,0 +1,140 @@ +#compdef bartib + +_bartib_tasks() { + local -a _tasks=($(bartib last | awk 'NR > 2 {print $1}' | tr -d '[]' | sort | tr '\n' ' ')) + + _values "NUMBER" ${_tasks[@]} +} + +_bartib_projects() { + local -a _projects=($(bartib projects --no-quotes | sort | tr '\n' ' ')) + + _values "PROJECTS" ${_projects[@]} +} + +_bartib() { + typeset -A opt_args + local context state line + local current_context="${curcontext}" + + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(-v --version)'{-v,--version}'[Prints version information]' \ + '-f[the file in which bartib tracks all the activities]:FILE:_files' \ + '1:bartib commands:->commands' \ + '*:: :->command_arguments' + + case $state in + commands) + local commands + commands=( + 'cancel:cancels all currently running activities', + 'change:changes the current activity', + 'check:checks file and reports parsing errors', + 'continue:continues a previous activity', + 'current:lists all currently running activities', + 'edit:opens the activity log in an editor', + 'help:Prints this message or the help of the given subcommand(s)', + 'last:displays the descriptions and projects of recent activities', + 'list:list recent activities', + 'projects:list all projects', + 'report:reports duration of tracked activities', + 'sanity:checks sanity of bartib log', + 'search:search for existing descriptions and projects', + 'start:starts a new activity', + 'status:shows current status and time reports for today, current week, and current month', + 'stop:stops all currently running activities' + ) + _describe -t commands 'bartib command' commands + ;; + + command_arguments) + case $words[1] in + cancel) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' + ;; + change) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(-d --description)'{-d,--description}'[the description of the new activity]:DESCRIPTION:()' \ + '(-p,--project)'{-p,--project}'[the project to which the new activity belongs]:PROJECT:_bartib_projects' \ + '(-t,--time)'{-t,--time}'[the time for changing the activity status (HH:MM)]:TIME:()' + ;; + check) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' + ;; + continue) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(-d --description)'{-d,--description}'[the description of the new activity]:DESCRIPTION:()' \ + '(-p --project)'{-p,--project}'[the project to which the new activity belongs]:PROJECT:_bartib_projects' \ + '(-t --time)'{-t,--time}'[the time for changing the activity status (HH:MM)]:TIME:()' \ + '*::NUMBER:_bartib_tasks' + ;; + help) + _arguments \ + '*::SUBCOMMAND:(cancel change check continue current edit help last list projects report sanity search start status stop)' + ;; + list) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(--current-week)'--current-week'[show activities of the current week]' \ + '(--last-week)'--last-week'[show activities of the last week]' \ + '(--no_grouping)'--no_grouping'[do not group activities by date in list]' \ + '(--today)'--today'[show activities of the current day]' \ + '(--yesterday)'--yesterday"[show yesterdays' activities]" \ + '(-d --date)'{-d,--date}'[show activities of a certain date only]:DATE:' \ + '(--from)'--from'[begin of date range (inclusive)]:DATE:' \ + '(--n --number)'{-n,--number}'[maximum number of activities to display]:NUMBER:' \ + '(--p --project)'{-p,--project}'[do list activities for this project only]:PROJECT:_bartib_projects' \ + '(--round)'--round'[rounds the start and end time to the nearest duration. Durations can be in minutes or hours. E.g. 15m or 4h]:ROUND:' \ + '(--to)'--to'[end of date range (inclusive)]:TO_DATE:' + ;; + projects) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(-c --current)'{-c,--current}'[prints currently running projects only]' \ + '(-n --no-quotes)'{-n,--no-quotes}'[prints projects without quotes]' + ;; + report) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(--current_week)'--current_week'[show activities of the current week]' \ + '(--last_week)'--last_week'[show activities of the last week]' \ + '(--today)'--today'[show activities of the current day]' \ + '(--yesterday)'--yesterday"[show yesterdays' activities]" \ + '(-d --date)'{-d,--date}'[show activities of a certain date only]:DATE:' \ + '(--from)'--from'[begin of date range (inclusive)]:DATE:' \ + '(-p --project)'{-p,--project}'[do report activities for this project only]:PROJECT:_bartib_projects' \ + '(--round)'--round'[rounds the start and end time to the nearest duration. Durations can be in minutes or hours. E.g. 15m or 4h]:ROUND:' \ + '(--to)'--to'[end of date range (inclusive)]:DATE:' + ;; + sanity) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' + ;; + search) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '*::SEARCH_TERM:' + ;; + start) + _arguments -C \ + '(-h --help)'{-h,--help}'[Prints help information]' \ + '(-d --description)'{-d,--description}'[the description of the new activity]:DESCRIPTION:()' \ + '(-p,--project)'{-p,--project}'[the project to which the new activity belongs]:PROJECT:_bartib_projects' \ + '(-t,--time)'{-t,--time}'[the time for changing the activity status (HH:MM)]:TIME:()' + ;; + stop) + _arguments -C \ + '(-h --help)'{-h,--help}'[show command line help]' \ + '(-t,--time)'{-t,--time}'[the time for changing the activity status (HH:MM)]:TIME:()' + ;; + esac + ;; + esac +} + +_bartib "${@}" From a766d47390fc9cd25ce2d0ce10ef1c9eee3e677b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Gagn=C3=A9?= Date: Tue, 6 May 2025 13:16:56 -0400 Subject: [PATCH 2/2] Improve task completion --- misc/_bartib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/_bartib b/misc/_bartib index f7b5fca..1e9eadd 100644 --- a/misc/_bartib +++ b/misc/_bartib @@ -1,9 +1,9 @@ #compdef bartib _bartib_tasks() { - local -a _tasks=($(bartib last | awk 'NR > 2 {print $1}' | tr -d '[]' | sort | tr '\n' ' ')) + local -a _tasks=($(bartib last | head -n -1 | awk 'BEGIN { a="" } NR > 2 {for (i=2; i <= NF - 1; i++) { if (i != 2) { a=a" "$i; } else { a=$i } } gsub("[\[\]]", "", $1); printf("%s[%s]\n", $1, a)}' | tr '\n' ' ')) - _values "NUMBER" ${_tasks[@]} + _values "TASK" ${_tasks[@]} } _bartib_projects() {