From 85ec5c4fcfb0d95798656ea1b810cb0a2d8d1a47 Mon Sep 17 00:00:00 2001 From: Andy Weidenbaum Date: Thu, 10 Dec 2015 21:12:29 -0800 Subject: [PATCH] fix fdr function for relative and non-existent paths --- Examples.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Examples.md b/Examples.md index 54c1add..ee885c4 100644 --- a/Examples.md +++ b/Examples.md @@ -67,16 +67,15 @@ fda() { fdr() { local declare dirs=() get_parent_dirs() { - dirs+=("$1") - if [[ ${1} == '/' ]]; then - for _dir in ${dirs[@]}; do - echo $_dir - done + if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi + if [[ "${1}" == '/' ]]; then + for _dir in "${dirs[@]}"; do echo $_dir; done else - get_parent_dirs $(dirname $1) + get_parent_dirs $(dirname "$1") fi } - DIR=$(get_parent_dirs ${1:-$(pwd)} | fzf-tmux --tac) && cd "$DIR" + local DIR=$(get_parent_dirs $(realpath "${1:-$(pwd)}") | fzf-tmux --tac) + cd "$DIR" } ```