-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
cp-svn-url
executable file
路83 lines (69 loc) 路 1.84 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
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
#!/usr/bin/env bash
# @Function
# copy the svn remote url of current svn directory.
#
# @Usage
# $ ./cp-svn-url
# $ ./cp-svn-url /path/to/svn/work/dir
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-3.x/docs/vcs.md#-cp-svn-url
# @author ivanzhangwb (ivanzhangwb at gmail dot com)
readonly PROG=${0##*/}
readonly PROG_VERSION='3.x-dev'
################################################################################
# parse options
################################################################################
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
-V, --version display version information and exit
EOF
exit "$1"
}
progVersion() {
echo "$PROG $PROG_VERSION"
exit
}
args=("$@")
# check arguments in reverse, so last option wins.
for ((idx = $# - 1; idx >= 0; --idx)); do
[[ "${args[idx]}" = -h || "${args[idx]}" = --help ]] && usage
[[ "${args[idx]}" = -V || "${args[idx]}" = --version ]] && progVersion
done
unset args idx
################################################################################
# biz logic
################################################################################
(($# > 1)) && {
echo At most 1 local directory is need!
usage 1
}
readonly dir="${1:-.}"
# DO NOT declare and assign var url(as readonly) in ONE line!
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
url="$(svn info "$dir" | awk '/^URL: /{print $2}')"
if [ -z "$url" ]; then
echo "Fail to get svn url!" >&2
exit 1
fi
copy() {
case "$(uname)" in
Darwin*)
pbcopy
;;
CYGWIN* | MINGW*)
clip
;;
*)
xsel -b
;;
esac
}
echo -n "$url" | copy && echo "$url copied!"