forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpf
executable file
·38 lines (35 loc) · 969 Bytes
/
xpf
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
#!/bin/bash
# @Function
# Open file in file explorer, file is selected.
# same as xpl --selected [file [file ...] ]
#
# @Usage
# $ ./xpf file
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-xpl-and-xpf
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail
# How can I get the behavior of GNU's readlink -f on a Mac?
# https://stackoverflow.com/questions/1055671
portableReadLink() {
local file="$1" uname
uname="$(uname)"
case "$uname" in
Linux* | CYGWIN* | MINGW*)
readlink -f "$file"
;;
Darwin*)
if command -v greadlink >/dev/null; then
greadlink -f "$file"
else
python -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$file"
fi
;;
*)
echo "not support uname($uname)!" >&2
exit 1
;;
esac
}
BASE="$(dirname "$(portableReadLink "${BASH_SOURCE[0]}")")"
source "$BASE/xpl" "$@"