[zsh] better error handling for viscd

This commit is contained in:
Dmytro Meleshko 2020-09-05 18:09:29 +03:00
parent ffb177044a
commit b2410007a8

View file

@ -8,14 +8,18 @@ bytecount() { wc -c "$@" | numfmt --to=iec-i; }
mkcd() { mkdir -p "$@" && cd "${@[-1]}"; } mkcd() { mkdir -p "$@" && cd "${@[-1]}"; }
viscd() { viscd() {
setopt local_options err_return
local temp_file chosen_dir local temp_file chosen_dir
temp_file="$(mktemp -t ranger_cd.XXXXXXXXXX)" temp_file="$(mktemp -t ranger_cd.XXXXXXXXXX)"
ranger --choosedir="$temp_file" -- "${@:-$PWD}" {
ranger --no-such-opt --choosedir="$temp_file" -- "${@:-$PWD}"
if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" && "$chosen_dir" != "$PWD" ]]; then if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" && "$chosen_dir" != "$PWD" ]]; then
cd -- "$chosen_dir" cd -- "$chosen_dir"
fi fi
} always {
rm -f -- "$temp_file" rm -f -- "$temp_file"
} }
}
command_exists() { command -v "$1" &>/dev/null; } command_exists() { command -v "$1" &>/dev/null; }