Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. function _task_list() {
  4. local CMD=$1
  5. local TERM=$2
  6. local WORD=${COMP_WORDS[${COMP_CWORD}]}
  7. local PREV=$3
  8. local PREFIX=""
  9.  
  10. # If the current or previous word is a colon, we're halfway through
  11. # a colon delimited task path so prepend the first part
  12. if [[ $WORD == ":" ]]
  13. then
  14. PREFIX="$PREV:"
  15. elif [[ $PREV == ":" ]]
  16. then
  17. PREFIX="${COMP_WORDS[$((COMP_CWORD-2))]}:"
  18. fi
  19.  
  20. # Generate the task list by parsing out the task names, filtering them
  21. # for any prefix, then stripping the prefix
  22. TASK_LIST=$(
  23. task --list 2>/dev/null \
  24. | sed -n -e '/^\*\s/ s/^\*\s\(\S*\):\s.*/\1/p' \
  25. | sed -n -e '/^'${PREFIX//\//\\/}'/ s/^'${PREFIX//\//\\/}'//p' \
  26. | xargs
  27. )
  28.  
  29. COMPREPLY=( $(compgen -W "$TASK_LIST" "${TERM}") )
  30. }
  31.  
  32. complete -F _task_list task
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement