forked from babarot/enhancd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilepath.sh
64 lines (53 loc) · 1.52 KB
/
filepath.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Currently this is not used
__enhancd::filepath::split()
{
__enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/split.awk" -v arg="${1:-$PWD}"
}
__enhancd::filepath::get_parent_dirs()
{
__enhancd::command::awk -f "${ENHANCD_ROOT}/functions/enhancd/lib/step_by_step.awk" -v dir="${1:-$PWD}"
}
__enhancd::filepath::walk()
{
local -a dirs
# __enhancd::filepath::get_parent_dirs does not return $PWD itself
# so add it to array expressly
dirs=( "${PWD}" $(__enhancd::filepath::get_parent_dirs "${1:-${PWD}}") )
for dir in "${dirs[@]}"
do
command find "${dir}" -maxdepth 1 -type d -name '\.*' -prune -o -type d -print
done
}
__enhancd::filepath::current_dir()
{
echo "${PWD:-$(command pwd)}"
}
# Currently this is not used
__enhancd::filepath::abs()
{
local cwd dir
cwd="${PWD%/*}"
dir="${1}"
if [[ -p /dev/stdin ]]; then
dir="$(command cat <&0)"
fi
if [[ -z ${dir} ]]; then
return 1
fi
__enhancd::command::awk \
-f "${ENHANCD_ROOT}/functions/enhancd/lib/to_abspath.awk" \
-v cwd="${cwd}" \
-v dir="${dir}"
}
__enhancd::filepath::get_dirs_in_cwd()
{
# https://github.com/sharkdp/fd
if type fd &>/dev/null; then
# using fd command gives better results than find command
command fd --type d --hidden -E .git
return ${?}
fi
# https://unix.stackexchange.com/questions/611685/finding-all-directories-except-hidden-ones
# cut is needed fot triming "./" from the output
LC_ALL=C command find . ! -name . \( -name '.*' -prune -o -type d -print \) | cut -c3-
}