Last active
August 29, 2015 14:21
-
-
Save paul-english/c6c5e568279cdc8f5781 to your computer and use it in GitHub Desktop.
Manage git repo organization a bit more like go does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Clones a repo into an organized directory structure at your $CODEPATH. | |
# This organization is similar to how "go get" will organize your code into | |
# $GOPATH/<site>/../../<repo> | |
set -e | |
trap "echo ERRORS DETECTED" err | |
URL=$1 | |
DIR=$(echo ${URL} | sed \ | |
-e "s/https:\/\///g" \ | |
-e "s/git@//g" \ | |
-e "s/:/\//g" \ | |
-e "s/\.git$//g") | |
git clone "$URL" "$CODEPATH/$DIR" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
#set -x | |
CODEPATH=~/c | |
function find_git_config_files() { | |
find .git -name "config" | |
find . -maxdepth 1 -name ".gitmodules" | |
} | |
function remote_origin() { | |
local repo="$1" | |
grep \ | |
-A 1 \ | |
'remote \"origin\"' \ | |
"$repo/.git/config" \ | |
| sed 1d \ | |
| cut -f 2 -d = \ | |
| sed 's/^ *//' | |
} | |
function repo_url_to_path() { | |
local url=$1 | |
dir=$(echo ${url} | sed -e "s/https:\/\///g" \ | |
-e "s/git@//g" \ | |
-e "s/:/\//g" \ | |
-e "s/\.git$//g") | |
echo "$dir" | |
} | |
function prompt_move_git_repo() { | |
local repo=$(echo ${1} | sed -e "s/\/\.git$//") | |
url=$(remote_origin "$repo") | |
dir=$(repo_url_to_path "$url") | |
echo -n "REPO: $repo | |
REPO URL: $url | |
mv $repo $CODEPATH/$dir | |
Auto organize? [y/N] " | |
read confirm | |
if [ "y" = "${confirm:0:1}" -o "Y" = "${confirm:0:1}" ]; then | |
mkdir -p $(dirname "$CODEPATH/$dir") | |
mv "$repo" "$CODEPATH/$dir" | |
fi | |
} | |
function main() { | |
local repos=$(find "$CODEPATH" -type d -name .git -prune \ | |
-not -path "*.bundler/*" \ | |
-not -path "*.cargo/*" \ | |
-not -path "$CODEPATH/src/*") | |
for repo in $repos; do | |
prompt_move_git_repo "$repo" | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment