File tree Expand file tree Collapse file tree 2 files changed +74
-9
lines changed
Expand file tree Collapse file tree 2 files changed +74
-9
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
22
3- base_dir=$( git config get.location)
3+ base_dir=" $( git config get.location) "
44
55if [ -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 } "
710fi
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 "
Original file line number Diff line number Diff line change 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. \fI https:// \fR ),
12+ the username (e.g. \fI git@ \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
You can’t perform that action at this time.
0 commit comments