Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- function _task_list() {
- local CMD=$1
- local TERM=$2
- local WORD=${COMP_WORDS[${COMP_CWORD}]}
- local PREV=$3
- local PREFIX=""
- # If the current or previous word is a colon, we're halfway through
- # a colon delimited task path so prepend the first part
- if [[ $WORD == ":" ]]
- then
- PREFIX="$PREV:"
- elif [[ $PREV == ":" ]]
- then
- PREFIX="${COMP_WORDS[$((COMP_CWORD-2))]}:"
- fi
- # Generate the task list by parsing out the task names, filtering them
- # for any prefix, then stripping the prefix
- TASK_LIST=$(
- task --list 2>/dev/null \
- | sed -n -e '/^\*\s/ s/^\*\s\(\S*\):\s.*/\1/p' \
- | sed -n -e '/^'${PREFIX//\//\\/}'/ s/^'${PREFIX//\//\\/}'//p' \
- | xargs
- )
- COMPREPLY=( $(compgen -W "$TASK_LIST" "${TERM}") )
- }
- complete -F _task_list task
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement