Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
140 changes: 140 additions & 0 deletions misc/_bartib
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#compdef bartib

_bartib_tasks() {
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 "TASK" ${_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 "${@}"
Loading