代码拉取完成,页面将自动刷新
同步操作将从 _KK/useful-scripts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/bin/bash
# @Function
# Open file in file explorer.
#
# @Usage
# $ ./xpf [file [file ...] ]
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/shell.md#-xpl-and-xpf
# @author Jerry Lee (oldratlee at gmail dot com)
PROG=`basename $0`
usage() {
[ -n "$1" -a "$1" != 0 ] && local out=/dev/stderr || local out=/dev/stdout
[ $# -gt 1 ] && { echo "$2"; echo; } > $out
cat <<EOF
Usage: ${PROG} [OPTION] [FILE]...
Open file in file explorer.
Example: ${PROG} file.txt
Options:
-s, --selected select the file or dir
-h, --help display this help and exit
EOF
exit $1
}
# if program name is xpf, set option selected!
[ "xpf" == "${PROG}" ] && selected=true
################################################################################
# parse options
################################################################################
declare -a args=()
while [ $# -gt 0 ]; do
case "$1" in
-s|--selected)
selected=true
shift
;;
-h|--help)
usage
;;
--)
shift
args=("${args[@]}" "$@")
break
;;
-*)
usage 2 "${PROG}: unrecognized option '$1'"
;;
*)
args=("${args[@]}" "$1")
shift
;;
esac
done
################################################################################
# biz options
################################################################################
# open one file
openOneFile() {
local file="$1"
case "$(uname)" in
Darwin*)
[ -f "${file}" ] && selected=true
open ${selected:+-R} "$file"
;;
CYGWIN*)
[ -f "${file}" ] && selected=true
explorer ${selected:+/select,} "$(cygpath -w "${file}")"
;;
*)
if [ -d "${file}" ] ; then
nautilus "$(dirname "${file}")"
else
if [ -z "${selected}" ] ; then
nautilus "$(dirname "${file}")"
else
nautilus "${file}"
fi
fi
;;
esac
}
[ "${#args[@]}" == 0 ] && files=( . ) || files=( "${args[@]}" )
for file in "${files[@]}" ; do
[ ! -e "$file" ] && { echo "$file not exsited!"; continue; }
openOneFile "$file"
echo "$file opened${selected:+ with selection}!"
done
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。