Skip to content

Commit 38c7b03

Browse files
committed
add alias to git-feature
1 parent 80a7928 commit 38c7b03

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

bin/git-feature

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
#!/usr/bin/env bash
22

3+
branch_prefix=feature
4+
declare -a argv
5+
while test $# != 0
6+
do
7+
case $1 in
8+
-a|--alias )
9+
if [[ -n $2 ]]
10+
then
11+
shift # shift -a|-alias
12+
branch_prefix=$1
13+
else
14+
argv+=($1) # treat tail '-a' as <name>
15+
fi
16+
;;
17+
* )
18+
argv+=($1)
19+
;;
20+
esac
21+
shift
22+
done
23+
324
concatargs(){
4-
delim='-'
5-
str=
6-
for i in "$@"; do
7-
str="$str$delim$i"
8-
done
9-
branch=feature/${str:1}
25+
str=$(IFS='-'; echo "$*")
26+
branch="$branch_prefix"/$str
1027
}
1128

12-
if test "$1" = "finish"; then
13-
test -z $2 && echo "feature <name> required." 1>&2 && exit 1
14-
branch=feature/$2
15-
git merge --no-ff $branch && git delete-branch $branch
29+
if test "${argv[0]}" = "finish"; then
30+
test -z "${argv[1]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
31+
branch="$branch_prefix"/"${argv[1]}"
32+
git merge --no-ff "$branch" && git delete-branch "$branch"
1633
else
17-
test -z $1 && echo "feature <name> required." 1>&2 && exit 1
18-
if test -n "$2"; then
19-
concatargs ${@:2}
34+
test -z "${argv[0]}" && echo "$branch_prefix" "<name> required." 1>&2 && exit 1
35+
if test -n "${argv[1]}"; then
36+
concatargs "${argv[@]}"
2037
else
21-
branch=feature/$1
38+
branch="$branch_prefix"/"${argv[0]}"
2239
fi
2340
git checkout -b $branch
2441
fi

0 commit comments

Comments
 (0)