-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrls
executable file
·91 lines (70 loc) · 1.35 KB
/
rls
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# Time-stamp: <2017-09-13 10:59:33 Wednesday by ahei>
# @file ls.sh
# @version 1.0
# @author ahei
readonly PROGRAM_NAME="rls"
readonly PROGRAM_VERSION="1.0.0"
home=`cd $(dirname "$0") && pwd`
version()
{
echo "${PROGRAM_NAME} ${PROGRAM_VERSION}"
exit 1
}
# echo to stderr
echoe()
{
printf "$*\n" 1>&2
}
usage()
{
local code=1
local redirect
if [ $# -gt 0 ]; then
code="$1"
fi
if [ "$code" != 0 ]; then
redirect="1>&2"
fi
eval cat "$redirect" << EOF
usage: ${PROGRAM_NAME} [OPTIONS] CLUSTER FILES [LS_OPTIONS]
Options:
-o REMOTE_OPTIONS
Set remote's options.
-v Output version info.
-h Output this help.
EOF
exit "$code"
}
while getopts ":hvo:" OPT; do
case "$OPT" in
o)
remoteOptions="$OPTARG"
;;
v)
version
;;
h)
usage 0
;;
:)
case "${OPTARG}" in
?)
echoe "Option \`-${OPTARG}' need argument.\n"
usage
esac
;;
?)
echoe "Invalid option \`-${OPTARG}'.\n"
usage
;;
esac
done
shift $((OPTIND - 1))
if [ $# -lt 2 ]; then
usage
fi
cluster=$1
file=$2
shift 2
remote -q $remoteOptions "$cluster" "ls -l $file $@"