Parcourir la Source

~/.bin/rt: Support multiple commands, shortcuts and some uglyness.

Mhh, I'm not quite sure whether this is the *wrong way*. Possibly it
should actually be more like defining what the shortcuts are and not
guessing them.
Lucas Stadler 14 ans auparavant
Parent
commit
ca6ce37a6f
1 fichiers modifiés avec 46 ajouts et 12 suppressions
  1. 46 12
      .bin/rt

+ 46 - 12
.bin/rt

@ -1,25 +1,59 @@
1 1
#!/bin/bash
2 2
3
rt_REPO="$1"
4
5
if [ $# == 0 ]; then
6
	echo "Usage: $0 <repo-url>"
7
	echo -e " clones repository at <repo-url>"
3
if [ $# -lt 1 ]; then
4
	echo "Usage: $0 <cmd> <repo> [<args>]"
5
	echo "  executes <cmd> for <repo> (passing <args> through)"
8 6
	exit 1
9 7
fi
10 8
11
prog_from_url() {
12
	if [ `echo $1 | grep -E "(git|hub|repo.or.cz)"` ]; then
9
rt_CMDS="clone\nlog\ndiff\nmerge"
10
rt_CMD="$1"
11
12
if [ "$rt_REPO" == "" ]; then
13
	rt_REPO="."
14
fi
15
16
# sort of shortcuts for commands (beginnings)
17
cmd=`echo -e $rt_CMDS | grep -E "^$1"`
18
if [ "$?" == "0" ]; then
19
	rt_CMD=$cmd
20
fi
21
22
prog_from_any() {
23
	if [ -d "$1/.git" ]; then
24
		rt_PROG="git"
25
	elif [ -d "$1/.hg" ]; then
26
		rt_PROG="hg"
27
	elif [ `echo $1 | grep -E "(git|hub|repo.or.cz)"` ]; then
13 28
		rt_PROG="git"
14 29
	elif [ `echo $1 | grep -E "(hg|bitbucket)"` ]; then
15 30
		rt_PROG="hg"
16 31
	else
17
		echo "Error: Unknown repo at $1"
18
		exit 1
32
		rt_PROG=""
19 33
	fi
20 34
}
21 35
22
prog_from_url $rt_REPO
23
rt_CMD="clone"
36
rt_clone() {
37
	$rt_PROG $rt_CMD $rt_REPO $@
38
}
39
40
rt_any() {
41
	cd $rt_REPO
42
	$rt_PROG $rt_CMD $@
43
	cd - &> /dev/null
44
}
45
46
if [ "$rt_CMD" == "clone" ]; then
47
	rt_REPO="$2"
48
	rt_FUN="rt_clone"
49
	shift 2
50
else
51
	shift 1
52
	rt_FUN="rt_any"
53
fi
54
55
# get the repo type
56
prog_from_any $rt_REPO
24 57
25
$rt_PROG $rt_CMD $rt_REPO
58
# have fun!
59
$rt_FUN $@