forked from hongweiyi/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cp-svn-url.sh
executable file
·66 lines (54 loc) · 1.08 KB
/
cp-svn-url.sh
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
#!/bin/bash
# @Function
# copy the svn remote url of current svn directory.
#
# @Usage
# $ ./svn-url.sh
#
# @author ivanzhangwb
PROG=`basename $0`
usage() {
cat <<EOF
Usage: ${PROG} [DIR]
Copy the svn remote url of local svn directory
DIR is local svn directory, default is current directory.
Example:
${PROG}
${PROG} /path/to/svn/work/dir
Options:
-h, --help display this help and exit
EOF
exit $1
}
ARGS=`getopt -a -o h -l help -- "$@"`
[ $? -ne 0 ] && usage 1
eval set -- "${ARGS}"
while true; do
case "$1" in
-h|--help)
usage
;;
--)
shift
break
;;
esac
done
[ $# -gt 1 ] && { echo At most 1 local directory is need! ; usage 1; }
dir="${1}"
dir=${dir:-.}
url=$(svn info "${dir}" | awk '/^URL: /{print $2}')
if [ -z "${url}" ]; then
echo "Fail to get svn url!" 1>&2
exit 1
fi
name=$(uname | tr A-Z a-z)
case "${name}" in
darwin*)
echo -n "${url}" | pbcopy ;;
cygwin*)
echo -n "${url}" | clip ;;
*)
echo -n "${url}" | xsel -b ;;
esac
[ $? == 0 ] && echo "${url} copied!" || exit 2