forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcp-svn-url.sh
executable file
·55 lines (45 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
#!/bin/bash
# @Function
# copy the svn remote url of current svn directory.
#
# @Usage
# $ ./cp-svn-url.sh
# $ ./cp-svn-url.sh /path/to/svn/work/dir
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/vcs.md#beer-cp-svn-urlsh
# @author ivanzhangwb (ivanzhangwb at gmail dot com)
readonly 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
}
for a; do
[ -h = "$a" -o --help = "$1" ] && usage
done
[ $# -gt 1 ] && { echo At most 1 local directory is need! ; usage 1; }
readonly dir="${1:-.}"
readonly url="$(svn info "${dir}" | awk '/^URL: /{print $2}')"
if [ -z "${url}" ]; then
echo "Fail to get svn url!" 1>&2
exit 1
fi
copy() {
case "`uname`" in
Darwin*)
pbcopy ;;
CYGWIN*|MINGW*)
clip ;;
*)
xsel -b ;;
esac
}
echo -n "${url}" | copy && echo "${url} copied!"