# shellcheck shell=dash
# u for move up, d for move down, w for command which
# File Explorer at the right side. Show the binary list in the folder
___x_cmd_path_lsapp_print(){
    ___x_cmd_path_ls_native | ___x_cmd_cmds_cat -n
}

___x_cmd_path_lsapp(){
    local ___X_CMD_TUI_NAVI_CUR_FILE=
    local ___X_CMD_TUI_NAVI_FINAL_COMMAND=
    local ___X_CMD_TUI_APP_IS_SMALL_SCREEN=

    local ___X_CMD_LS_APP_BASEDATA=
    ___X_CMD_LS_APP_BASEDATA="$( ___x_cmd_path_lsapp___data )" || return $?
    [ -n "$___X_CMD_LS_APP_BASEDATA" ] || N=path M="PATH variable is empty" log:ret:64

    xrc:mod:lib ls  app/lsapp
    local x_=; ___x_cmd storerat_ ___x_cmd_ls_app_ "$@"     || return $?
    [ -n "$x_" ] || return
    eval "$x_"

    case "$___X_CMD_TUI_NAVI_FINAL_COMMAND" in
        q)  ;;      # Just quit
        d)  ;;      # remove
        r)  ;;      # rename
        *)
            if [ ! -t 1 ]; then
                printf "%s\n" "$___X_CMD_TUI_NAVI_CUR_FILE"
            else
                ___x_cmd_path_lsapp_handle "$___X_CMD_TUI_NAVI_CUR_FILE"
            fi
            ;;
    esac
}

___x_cmd_path_lsapp___data(){
    local d=; local x_=
    ___x_cmd_path_ls_native | while read -r d; do
        ___x_cmd str trim_ "$(___x_cmd_cmds_ls "$d" | ___x_cmd_cmds wc -l)"
        printf "%-6s${___X_CMD_UNSEENCHAR_001}%s\n" "$x_" "$d"
    done  2>/dev/null
}

___x_cmd_path_lsapp_handle(){
    local fp="$1"
    local id=
    ___x_cmd ui select id "Action for [dir=$fp]"    \
        "echo directory path"                       \
        "Remove directory from PATH"                \
        "cd to the directory"                       \
        "open directory using Explorer"             \
        "EXIT" || return $?

    case "$id" in
        1)      printf "%s\n" "$fp"     ;;
        2)      ___x_cmd path rm "$fp"  ;;
        3)      ___x_cmd cd "$fp"       ;;
        4)      ___x_cmd open "$fp"     ;;
        *)      return 1 ;;
    esac
}
