A few notes on how I organize my code lately. It's not the sexiest topic in the world but it matters, especially given that I keep about 160 repos cloned on my system at any given time.
I've spent a couple years now trying to avoid the urge to mirror my personal code working space after github repo pathnames, but I'm a weak man and have given in.
When I want to clone a repo, I'll give it a directory matching the pattern ~/code/<owner>/<repo>
.
Running tree ~/code -L 2
yields something like this for me now:
code
├── bkeepers
│ └── github-notifications
├── emberjs
│ └── data
├── gruntjs
│ └── grunt
├── ios
│ ├── backlog
│ ├── textual
│ └── tutorials
├── java
│ ├── Bukkit
│ ├── BukkitPluginArchetype
│ ├── jasmine-archetype
│ └── jasmine-maven-plugin
├── jimweirich
│ └── wyriki
├── linemanjs
│ ├── angular-cellar-lineman
│ ├── heroku-buildpack-lineman
│ ├── heroku-buildpack-lineman-ruby
│ ├── lineman
│ ├── lineman-angular
│ ├── ...
│ └── lineman-spec-browser
├── searls
│ ├── doing-it
│ ├── gimme
│ ├── ...
│ └── webdriver-sync
└── testdouble
├── arg_that
├── backbone-fixins
├── covet
├── double-takes
├── grunt-asset-fingerprint
├── jasmine-all
├── servme
├── ...
└── yslow-grader
This layout helps me get around a little bit and has actually proven useful with writing some one-off scripts that use the Github API for taking action on multiple repos at once (for example, when I had to use to the Github API to add a webhook to every repo of an org at once).
As a trivial example, one could write a trivial little shell script to get around a little bit more easily. I just type goto linemanjs/lineman
and it'll change my direcotry, print git status, and open my editor for me. Here's a listing from cat bin/run_goto
#!/bin/bash -e
GOTO_DIR="$HOME/code/$@"
if [ -d "$GOTO_DIR" ]; then
cd "$GOTO_DIR"
git status
subl -n .
else
echo "Error: \"$GOTO_DIR\" doesn't exist"
exit 1
fi
And to source it in the host shell (so the directory change sticks) I keep an alias in my ~/.profile
like: alias goto=". run_goto"
My script for cloning repos is very similar. I just run:
$ clone bostonaholic/trigrams
Cloning into 'trigrams'...
remote: Reusing existing pack: 162, done.
remote: Total 162 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (162/162), 23.86 KiB | 0 bytes/s, done.
Resolving deltas: 100% (87/87), done.
Checking connectivity... done
justin@searls:~/code/bostonaholic/trigrams
And I'm in the directory. If the repo already exists, it'll just git pull --rebase
for me.
The listing cat bin/run_clone
:
#!/bin/bash -e
CLONE_URL="git@github.com:$@.git"
CLONE_PATH="$HOME/code/$@"
if [ -d "$CLONE_PATH" ]; then
cd "$CLONE_PATH"
git pull --rebase
else
mkdir -p "$CLONE_PATH"
cd "$CLONE_PATH/.."
git clone "$CLONE_URL"
cd "$CLONE_PATH"
fi
And I have an alias defined to source it to the interactive shell alias clone=". run_clone"