Skip to content

Commit 576c0e5

Browse files
authored
Use CDPATH if set (#219)
* Respect CDPATH when set * Fish version
1 parent d6e3ce4 commit 576c0e5

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

functions/_enhancd_source_history.fish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ function _enhancd_source_history
66
return 0
77
end
88

9+
if test -n "$CDPATH"
10+
_enhancd_command_awk \
11+
-f "$ENHANCD_ROOT/lib/cdpath.awk" \
12+
-v cdpath="$CDPATH" \
13+
-v dir="$dir" && return 0
14+
end
15+
916
_enhancd_history_list "$dir"
1017
end

functions/enhancd/lib/cdpath.awk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BEGIN {
2+
n = split(cdpath, array, ":")
3+
for (i = 1; i <= n; i++) {
4+
path = array[i] "/" dir
5+
if (! system("test -d " path )) {
6+
print path
7+
exit 0
8+
}
9+
}
10+
exit 1
11+
}

src/sources.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@ __enhancd::sources::history()
5151
return 0
5252
fi
5353

54+
if [[ -n $CDPATH ]]; then
55+
__enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/cdpath.awk" -v cdpath="${CDPATH}" -v dir="${dir}" && return 0
56+
fi
57+
5458
__enhancd::history::list "${dir}"
5559
}

0 commit comments

Comments
 (0)