-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg_clone.sh
More file actions
executable file
·31 lines (25 loc) · 781 Bytes
/
g_clone.sh
File metadata and controls
executable file
·31 lines (25 loc) · 781 Bytes
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
#!/bin/bash
# Base directory for storing all repos
BASE_DIR=~/git
# c (clone/navigate)
g_c() {
local repo_url=$1
if [[ -z "$repo_url" ]]; then
echo "Usage: g c <repository-url>"
return 1
fi
local repo_path=$(echo "$repo_url" | sed -E 's/^(https:\/\/|git@)//; s/:/\//; s/\.git$//')
local dest_dir="$BASE_DIR/$repo_path"
# If we've already cloned this repo, navigate instead
if [[ -d "$dest_dir" ]]; then
echo "Repo exists, navigating to: $dest_dir"
cd "$dest_dir" || return 1
else
# New repo, clone to correct path & navigate
mkdir -p "$(dirname "$dest_dir")"
git clone "$repo_url" "$dest_dir"
echo "Navigating to: $dest_dir"
cd "$dest_dir" || return 1
fi
}
export g_c