-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathxpf
executable file
·36 lines (31 loc) · 1.27 KB
/
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
#!/usr/bin/env bash
# @Function
# Open file in file explorer, file is selected.
# same as xpl --selected [file]...
#
# @Usage
# $ ./xpf file
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-3.x/docs/shell.md#-xpl-and-xpf
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail
################################################################################
# util functions
################################################################################
# `realpath` command exists on Linux and macOS, return resolved physical path
# - realpath command on macOS do NOT support option `-e`;
# combined `[ -e $file ]` to check file existence first.
# - How can I get the behavior of GNU's readlink -f on a Mac?
# https://stackoverflow.com/questions/1055671
realpath() {
[ -e "$1" ] && command realpath -- "$1"
}
################################################################################
# biz logic
################################################################################
# DO NOT inline THIS_SCRIPT into BASE_DIR, because sub-shell:
# BASE_DIR=$(dirname -- "$(realpath "${BASH_SOURCE[0]}")")
THIS_SCRIPT=$(realpath "${BASH_SOURCE[0]}")
BASE_DIR=$(dirname -- "$THIS_SCRIPT")
# shellcheck disable=SC1091
source "$BASE_DIR/xpl" "$@"