#!/bin/bash

_manage_completion() {
    local cur prev commands
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    # Define available commands
    commands="help new edit iedit"

    case "$prev" in
        edit|iedit)
            # Provide completion for existing song names (directories in content/)
            COMPREPLY=( $(compgen -W "$(ls -1 content/ 2>/dev/null)" -- "$cur") )
            return 0
            ;;
        new)
            # No completion for "new" since it's a new name
            return 0
            ;;
    esac

    # Default command completion
    if [[ $COMP_CWORD -eq 1 ]]; then
        COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
    fi
}

# Register the completion function for 'manage'
complete -F _manage_completion manage
complete -F _manage_completion ./manage

