-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathls-path
executable file
·54 lines (49 loc) · 1.22 KB
/
ls-path
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
#!/bin/bash
# or
#!/bin/ksh
# or
#!/bin/zsh
##
## List specified files and all parent directories
## Copyright (c) 2013 SATOH Fumiyasu @ OSS Technology Corp., Japan
##
## License: GNU General Public License version 3
##
set -u
typeset -a opts
while [[ $# -gt 0 ]]; do
[[ -n "${1##-*}" ]] && break
opts=(${opts[@]+"${opts[@]}"} "$1")
shift
done
for fname in "$@"; do
if [[ -n "${fname##/*}" ]]; then
## Convert a relative path to an absolute path
fname="${cwd=`pwd`}/$fname"
## "/path/to/." -> "/path/to/./"
fname="${fname/%\/.//./}"
## "/path/./to/./dir" -> "/path/to/dir"
fname="${fname//\/.\///}"
## "/path/to/.." -> "/path/to/../"
fname="${fname/%\/..//../}"
while :; do
## "/path/to/../dir" -> "/path/to"
fname_left="${fname%%/../*}"
[[ "$fname_left" = "$fname" ]] && break
## "/path/to/../dir" -> "dir"
fname_right="${fname#*/../}"
## -> "/path/dir"
fname="${fname_left%/*}/$fname_right"
done
fi
## "/path/to/dir/" -> "/path/to/dir"
fname="${fname%/}"
while :; do
echo "${fname:-/}"
fname_tmp="${fname%/*}"
[[ "$fname_tmp" = "$fname" ]] && break
fname="$fname_tmp"
done
done \
|sort -u \
|xargs ls -d ${opts[@]+"${opts[@]}"} --