forked from superhj1987/awesome-scripts
-
Notifications
You must be signed in to change notification settings - Fork 25
/
cp-svn-url
executable file
·57 lines (47 loc) · 1.01 KB
/
cp-svn-url
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
#!/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
#
# @author ivanzhangwb
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 in "$@"; 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() {
local name=$(uname | tr A-Z a-z)
case "${name}" in
darwin*)
pbcopy ;;
cygwin*)
clip ;;
mingw*)
clip ;;
*)
xsel -b ;;
esac
}
echo -n "${url}" | copy && echo "${url} copied!"