# shellcheck shell=dash

# More opt: in bash and zsh, just using string substituion
___x_cmd_path_rm_(){
    ___x_cmd_path_obj_rm_ "$PATH" "$1"
}

___x_cmd_path_rm(){
    local x_=""
    ___x_cmd_path_rm_ "$@" || return $?
    PATH="$x_"
}

___x_cmd_path_rm_by_prefix___(){
    local prefix="${1:?Provide a directory}"
    if [ -z "$PATH" ] ; then
        _1=":"
        return
    fi
    _1=":$PATH:"
    local p="${_1#*:"$prefix"*:}"
    while [ "$_1" != "$p" ]; do
        _1="${_1%%:"$prefix"*:*}:$p"
        p="${_1#*:"$prefix"*:}"
    done
}

___x_cmd_path_rm_by_prefix(){
    local _1
    ___x_cmd_path_rm_by_prefix___ "$@"
    PATH="${_1#:}"
    PATH="${PATH%:}"
}

___x_cmd_path_rm_by_suffix___(){
    local suffix="${1:?Provide a directory}"
    if [ -z "$PATH" ] ; then
        _1=":"
        return
    fi
    _1=":$PATH:"
    local p="${_1#*:*"$suffix":}"
    while [ "$_1" != "$p" ]; do
        _1="${_1%%:*"$suffix":*}:$p"
        p="${_1#*:*"$suffix":}"
    done
}

___x_cmd_path_rm_by_suffix(){
    local _1
    ___x_cmd_path_rm_by_suffix___ "$@"
    PATH="${_1#:}"
    PATH="${PATH%:}"
}
