# shellcheck shell=dash

___x_cmd_tmux_pm(){
    [ $# -gt 0 ]    ||      set -- --help

    local op="$1";          shift

    case "$op" in
        use|unuse|rm|clone|ls)      "___x_cmd_tmux_pm_$op" "$@" ;;
        -h|--help)                  ___x_cmd help -m tmux pm "$@"; return 0 ;;
        *)                          N=tmux M="Unknown subcmd -> $op" log:ret:64 ;;
    esac
}

# source-file <plugin>
# It is just a shell

___x_cmd_tmux_pm_ls(){
    :
    # x filelist ls "source-file $___X_CMD_TMUX_PM_WHICHDIR_"
    # line="${line#source-file }"
    # line="${line%%/*}"
}

___x_cmd_tmux_pm_whichdir_(){
    local name="$1"
    case "$name" in
        @*/*)                   ;;
        tmux-plugins/*)         ;;
        git@*/*)                ;;
        https://*)              ;;
        */*)                    ;;  # Using git
        *)                      ;;
    esac
}

___x_cmd_tmux_pm_src(){
    ___x_cmd tmux source-file "${1:?Provide folder}/"*.tmux
}

___x_cmd_tmux_pm_try(){
    local i; for i in "$@"; do
        ___x_cmd_tmux_pm_whichdir_ "$@" || return
        ___x_cmd_tmux_pm_src "$___X_CMD_TMUX_PM_WHICHDIR_"
    done
}

# tmux start up should be fast enough.
___x_cmd_tmux_pm_use(){
    local i; for i in "$@"; do
        ___x_cmd_tmux_pm_whichdir_ "$@" || return
        ___x_cmd_tmux_pm_src "$___X_CMD_TMUX_PM_WHICHDIR_"
        # should be a tmux config file
        # x filelist add "source-file $___X_CMD_TMUX_PM_WHICHDIR_"
    done
}

# file list
# x filelist rm ''
# x filelist add ''
___x_cmd_tmux_pm_unuse(){
    local i
    for i in "$@"; do
        ___x_cmd_tmux_pm_whichdir_ "$@" || return
        # should be a tmux config file
        # x filelist add "source-file $___X_CMD_TMUX_PM_WHICHDIR_"
    done
}

___x_cmd_tmux_pm_rm(){
    local i
    for i in "$@"; do
        ___x_cmd_tmux_pm_whichdir_ "$@" || return
        # should be a tmux config file
        # x filelist add "source-file $___X_CMD_TMUX_PM_WHICHDIR_"
    done
}
