[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,13 +8,17 @@ 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}" {
if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" && "$chosen_dir" != "$PWD" ]]; then ranger --no-such-opt --choosedir="$temp_file" -- "${@:-$PWD}"
cd -- "$chosen_dir" if chosen_dir="$(<"$temp_file")" && [[ -n "$chosen_dir" && "$chosen_dir" != "$PWD" ]]; then
fi cd -- "$chosen_dir"
rm -f -- "$temp_file" fi
} always {
rm -f -- "$temp_file"
}
} }
command_exists() { command -v "$1" &>/dev/null; } command_exists() { command -v "$1" &>/dev/null; }
@ -56,7 +60,7 @@ else
paste_cmd='print >&2 "clippaste: '"$error_msg"'"; return 1' paste_cmd='print >&2 "clippaste: '"$error_msg"'"; return 1'
unset error_msg unset error_msg
fi fi
eval "clipcopy(){ $copy_cmd; }; clippaste(){ $paste_cmd; }" eval "clipcopy() { $copy_cmd; }; clippaste() { $paste_cmd; }"
unset copy_cmd paste_cmd unset copy_cmd paste_cmd
# for compatibility with Oh My Zsh plugins # for compatibility with Oh My Zsh plugins