
# default: i
# wo je ich ego watashi ya ana gu zhen laozi ala

xrc shortcut
___x_cmd_icmd_alias(){
    [ $# -gt 0 ]    ||      set -- status
    local op="$1"; shift
    case "$op" in
        enable)     ___x_cmd_icmd_alias_enable     "$@" ;;
        disable)    ___x_cmd_icmd_alias_disable   "$@" ;;
        status)     ___x_cmd_icmd_alias_status    "$@" ;;
        -h|--help)  ___x_cmd help -m icmd alias "$@" ;;
        *)          ___x_cmd help -m icmd alias >&2; return 64 ;;
    esac
}

___x_cmd_icmd_alias_enable(){
    local word="$1"

    [ -n "$word" ] || {
        icmd:info "Using 'i' as the default alias"
        word=i
    }

    shortcut:get:data:init
    ___x_cmd shortcut get --format simple --by category icmd | while shortcut:get:parse:data; do
        if [ "$curword" = "$word" ];then
            [ "$curstatus" != enable ] || {
                icmd:info "Alias '$word' has already been enabled"
                return 0
            }
        else
            ___X_CMD_SHORTCUT_NOAUTO_COMPILE_ALL=1 ___x_cmd shortcut rename "$curword" "$word" || return $?
        fi
    done

    ___x_cmd shortcut enable --platform all --by category icmd \
        --set --status enable --platform all --x-cmd icmd --category icmd --advise "x-advise://icmd/advise.jso" "$word" || return $?
    icmd:info "Alias enabled successfully"
    icmd:info "To apply the configuration, please reopen a new shell environment"
}

___x_cmd_icmd_alias_disable(){
    shortcut:get:data:init
    ___x_cmd shortcut get --format simple --by category icmd | while shortcut:get:parse:data; do
        if [ "$curstatus" = disable ];then
            icmd:info "Alias has already been disabled"
            return 0
        fi
    done

    ___x_cmd shortcut disable --platform all --by category icmd \
        --set --status disable --platform all --x-cmd icmd --category icmd --advise "x-advise://icmd/advise.jso" i || return $?
    icmd:info "Alias disabled successfully"
    icmd:info "To apply the configuration, please reopen a new shell environment"
}

___x_cmd_icmd_alias_status(){
    ___x_cmd shortcut get --by category icmd || {
        printf "status: disable\n"
    }
}
