Skip to content

Commit 756457c

Browse files
committed
improve cp-svn-url.sh, remove option parse of getopt
1 parent f8f521c commit 756457c

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

cp-svn-url.sh

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# copy the svn remote url of current svn directory.
44
#
55
# @Usage
6-
# $ ./svn-url.sh
6+
# $ ./cp-svn-url.sh
7+
# $ ./cp-svn-url.sh /path/to/svn/work/dir
78
#
89
# @author ivanzhangwb
9-
10-
PROG=`basename $0`
10+
readonly PROG=`basename $0`
1111

1212
usage() {
1313
cat <<EOF
@@ -25,42 +25,33 @@ EOF
2525
exit $1
2626
}
2727

28-
ARGS=`getopt -a -o h -l help -- "$@"`
29-
[ $? -ne 0 ] && usage 1
30-
eval set -- "${ARGS}"
31-
32-
while true; do
33-
case "$1" in
34-
-h|--help)
35-
usage
36-
;;
37-
--)
38-
shift
39-
break
40-
;;
41-
esac
28+
for a in "$@"; do
29+
[ -h = "$a" -o --help = "$1" ] && usage
4230
done
4331

4432
[ $# -gt 1 ] && { echo At most 1 local directory is need! ; usage 1; }
4533

46-
dir="${1}"
47-
dir=${dir:-.}
34+
readonly dir="${1:-.}"
4835

49-
url=$(svn info "${dir}" | awk '/^URL: /{print $2}')
36+
readonly url=$(svn info "${dir}" | awk '/^URL: /{print $2}')
5037
if [ -z "${url}" ]; then
5138
echo "Fail to get svn url!" 1>&2
5239
exit 1
5340
fi
5441

55-
name=$(uname | tr A-Z a-z)
56-
57-
case "${name}" in
58-
darwin*)
59-
echo -n "${url}" | pbcopy ;;
60-
cygwin*)
61-
echo -n "${url}" | clip ;;
62-
*)
63-
echo -n "${url}" | xsel -b ;;
64-
esac
42+
copy() {
43+
local name=$(uname | tr A-Z a-z)
44+
45+
case "${name}" in
46+
darwin*)
47+
pbcopy ;;
48+
cygwin*)
49+
clip ;;
50+
mingw*)
51+
clip ;;
52+
*)
53+
xsel -b ;;
54+
esac
55+
}
6556

66-
[ $? == 0 ] && echo "${url} copied!" || exit 2
57+
echo -n "${url}" | copy && echo "${url} copied!"

0 commit comments

Comments
 (0)