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).
First, make sure you have bash-completion installed (on a mac with homebrew, brew install bash-completion
)
Then set your CDPATH in your profile:
export CDPATH=".:$HOME:$HOME/code"
Now you can cd to a repo from anywhere in your system with tab completion!
I also have a script for cloning repos that knows about the directory structure. 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"
Tab completion should work wherever you are too (it does in zsh anyway).