diff --git a/functions/_enhancd_source_history.fish b/functions/_enhancd_source_history.fish index 2f503ac..4fd31ae 100644 --- a/functions/_enhancd_source_history.fish +++ b/functions/_enhancd_source_history.fish @@ -6,5 +6,12 @@ function _enhancd_source_history return 0 end + if test -n "$CDPATH" + _enhancd_command_awk \ + -f "$ENHANCD_ROOT/lib/cdpath.awk" \ + -v cdpath="$CDPATH" \ + -v dir="$dir" && return 0 + end + _enhancd_history_list "$dir" end diff --git a/functions/enhancd/lib/cdpath.awk b/functions/enhancd/lib/cdpath.awk new file mode 100644 index 0000000..ece24fe --- /dev/null +++ b/functions/enhancd/lib/cdpath.awk @@ -0,0 +1,11 @@ +BEGIN { + n = split(cdpath, array, ":") + for (i = 1; i <= n; i++) { + path = array[i] "/" dir + if (! system("test -d " path )) { + print path + exit 0 + } + } + exit 1 +} diff --git a/src/sources.sh b/src/sources.sh index c7bc96e..b05e33f 100644 --- a/src/sources.sh +++ b/src/sources.sh @@ -51,5 +51,9 @@ __enhancd::sources::history() return 0 fi + if [[ -n $CDPATH ]]; then + __enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/cdpath.awk" -v cdpath="${CDPATH}" -v dir="${dir}" && return 0 + fi + __enhancd::history::list "${dir}" }