#!/bin/bash _mtracker() { local cur prev commands COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" commands="list ls add a remove rm rate r unrate u edit help" if [[ $COMP_CWORD -eq 1 ]]; then COMPREPLY=( $(compgen -W "$commands" -- "$cur") ) return 0 fi case "${COMP_WORDS[1]}" in add|a) if [[ $COMP_CWORD -eq 2 ]]; then local unrated_movies IFS=$'\n' movies=$(mtracker ls | sed -E "s/^\S+\s(WL:\s)?//") COMPREPLY=( $(compgen -W "$movies" -- "$cur") ) elif [[ $COMP_CWORD -eq 3 ]]; then COMPREPLY=( $(compgen -W "--tag" -- "$cur") ) fi ;; remove|rm) local movies IFS=$'\n' movies=$(mtracker ls | sed -E "s/^\S+\s(WL:\s)?//") COMPREPLY=( $(compgen -W "$movies" -- "$cur") ) ;; rate|r) if [[ $COMP_CWORD -eq 2 ]]; then local movies IFS=$'\n' movies=$(mtracker ls | sed -E "s/^\S+\s(WL:\s)?//") COMPREPLY=( $(compgen -W "$movies" -- "$cur") ) elif [[ $COMP_CWORD -eq 3 ]]; then COMPREPLY=( $(compgen -W "0 1 2 3 4 5 6 7 8 9" -- "$cur") ) fi ;; unrate|u) local rated_movies IFS=$'\n' rated_movies=$(mtracker ls rated | sed -E "s/^\S+\s(WL:\s)?//") COMPREPLY=( $(compgen -W "$rated_movies" -- "$cur") ) ;; list|ls) local tags IFS=$'\n' tags=$(mtracker tags) COMPREPLY=( $(compgen -W "$tags" -- "$cur") ) ;; esac return 0 } complete -F _mtracker mtracker