Skip to content

Commit

Permalink
Use CDPATH if set (#219)
Browse files Browse the repository at this point in the history
* Respect CDPATH when set

* Fish version
  • Loading branch information
jbro authored Jan 1, 2025
1 parent d6e3ce4 commit 576c0e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions functions/_enhancd_source_history.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions functions/enhancd/lib/cdpath.awk
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions src/sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

0 comments on commit 576c0e5

Please sign in to comment.