Skip to content
Open
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
61 changes: 51 additions & 10 deletions misc/bartibCompletion.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
#!/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 sanity change"
COMPREPLY=($(compgen -W "$words" -- "$word"))
;;
-p|--project)
# 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)
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"))

if [ ${#candidate_tasks[*]} -eq 0 ]; then
COMPREPLY=()
else
COMPREPLY=($(printf "\"%s\"\n" "${candidate_tasks[@]}"))
fi
fi
;;
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"))
;;
*)
;;
esac
}

complete -F _bartib_completions bartib