Skip to content

Commit bc7c5c8

Browse files
committed
Make git-get more robust and add man page
1 parent d7b448c commit bc7c5c8

File tree

2 files changed

+74
-9
lines changed

2 files changed

+74
-9
lines changed

git-get

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
#!/bin/bash
22

3-
base_dir=$(git config get.location)
3+
base_dir="$(git config get.location)"
44

55
if [ -z "$base_dir" ]; then
6-
base_dir=~/code
6+
base_dir="$HOME/code"
7+
else
8+
# Replace a tilde with $HOME
9+
base_dir="${base_dir/#~/$HOME}"
710
fi
811

9-
# We will blithely assume that the last argument is the repository
10-
dir=${!#}
1112

12-
dir=$(echo $dir | sed -e 's/^.*:\/\///')
13-
dir=$(echo $dir | sed -e 's/^.*@//')
14-
dir=$(echo $dir | sed -e 's/:/\//g')
15-
dir="$base_dir/$dir"
13+
repo="$1"
1614

17-
git clone $@ $dir
15+
if [ -z "$repo" ]; then
16+
echo "Usage git get <repository>"
17+
echo
18+
echo " git-get clones <repository> into a folder derived from the repository URL"
19+
echo
20+
echo " For example, git get [email protected]:stilvoid/git-get.git"
21+
echo " will be checkout into ~/code/github.com/stilvoid/git-get.git"
22+
echo
23+
echo " You can override the default base path (~/code) with"
24+
echo " git config --global get.loation \"/path/to/your/code\""
25+
exit 1
26+
fi
27+
28+
# Strip scheme
29+
dir="${repo#*://}"
30+
31+
# Strip username
32+
dir="${dir#*@}"
33+
34+
# Replace : with /
35+
dir="${dir/://}"
36+
37+
# Remove .git
38+
dir="${dir%.git}"
39+
40+
dir="${base_dir}/${dir}"
41+
42+
git clone "$repo" "$dir"

git-get.1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.TH "GIT\-GET" "1" "2025-01-10" "https://github.com/stilvoid/git-get" "Git Manual"
2+
.SH NAME
3+
git-git \- clone a git repository into a folder structure derived from the repository URL
4+
.SH SYNOPSIS
5+
.B git-get
6+
.IR repository
7+
.SH DESCRIPTION
8+
.Nm
9+
clones
10+
.IR repository
11+
into a folder derived from the repository URL by removing the scheme (e.g. \fIhttps://\fR),
12+
the username (e.g. \fIgit@\fR),
13+
and the suffix \fI.git\fR if it exists.
14+
.SH EXAMPLE
15+
.PP
16+
Clone the git-get repository:
17+
.PP
18+
.nf
19+
.RS
20+
$ git get [email protected]:stilvoid/git-get
21+
.RE
22+
OR
23+
.RS
24+
$ git get https://github.com/stilvoid/git-get.git
25+
.RE
26+
.fi
27+
.PP
28+
will both result in the repository being checked out to
29+
.PP
30+
.RS
31+
$HOME/code/github.com/stilvoid/git-get
32+
.RE
33+
.PP
34+
You can override the default base path (
35+
.I ~/code
36+
) with:
37+
.PP
38+
.RS
39+
$ git config --global get.loation "/path/to/your/code"
40+
.RE

0 commit comments

Comments
 (0)