Saving dotfiles with symlinks on OSX

I’ve always been impressed with folks who have their dotfiles all backed up to git somewhere, and I’ve finally worked out how to do it myself. The magic answer is symlinks!

STEP 1: DOTFILES

So, dotfiles are basically ‘hidden’ files that contain information about settings you don’t want to keep setting every time you try to do something. Lots of programs use dotfiles to keep track of user-specific configurations. For example. in ~/.gitconfig, Git stores information like your username and user email (and much, MUCH more).

STEP 2: Collect dotfiles into a Git repo

Mostly, dotfiles live in your home directory. But, you don’t really want to put everything in your home directory under git’s watchful eye, so the easier step is to collect all the dotfiles into a git repo that lives elsewhere. Pick a folder, ANY FOLDER! For best experience, I suspect it should live somewhere under your home directory. I’m currently keeping mine in ~/code/dotfiles.

Dotfiles you might want to keep under version control:
– Git config (~/.gitconfig)
– terminal config (~/.bash_profile, ~/.bashrc, ~/.zshrc, etc)
– basically anything were you’ve set prefs that are stored!

Hint The First

In order for the next step to work, you can’t have an existing copy of your dotfiles in your home directory. So if you want to put your .gitconfig under version control, for example, it is better to MOVE it instead of COPYING it.

Hint The Second

The ultimate point of this whole exercise (for me) was to have all my dotfiles backed up somewhere. If (like me) you are not yet ready to publicly publish your dotfiles on Github, there are a number of other Git-based services that will provide private repos for free.

STEP 3: Symlink!

The ln command is used to create links in your (unix-based) system. Use the --help command to get more info on the myriad of options available to you. Just using the ln command creates something called a ‘hard link’, which is not what we want. We want a ‘symbolic’ link instead. The syntax is ln -s + actual location of the file + name and location you want to see that file under.

Example:

ln -s ~/code/dotfiles/gitconfig ~/.gitconfig

will result in the gitconfig in the dotfiles directory to be accessible from the ~/.gitconfig location, which is where Git is expecting to see all the Git preferences you’ve set.

STEP 4: PROFIT!

RESOURCES:

I stumbled across this great article called How to Create and Use Symlinks on a Mac that made the lightbulb go off and instigated this whole song and dance.

Sublime text 2 keyboard shortcuts – delete an entire line

I’ve learned some new shortcuts for Sublime Text 2. I’ve been learning a few vim shortcuts, and I wanted to figure out how to do some of the things I can do in vim in Sublime.

  1. Ctrl + shift + k
    Deletes entire line. Ctrl is the correct key, even for OSX.

  2. Cmd + x
    Cuts the line if you want to move it somewhere. This does not require highlighting anything.

And as a note, many of the usual keyboard shortcuts work this way. Cmd + c will copy the line without needing to select anything.

Sublime Text 2 keyboard shortcuts

Until I started MakerSquare, I hadn’t used a OS X on a regular basis for about 2 years. Since MakerSquare, I’ve hardly touched Windows. I’ve remembered most of the keyboard shortcuts for OS X, and I’ve learned a few new ones for cool apps like SizeUp and the suggested text editor Sublime Text 2. However, I’ve been trying to figure out how to ‘jump to the end of a line’ aka how to replicate the function of the ‘end’ key for a couple weeks now, and just now figured it out. On accident. /o And now I realize why I was getting nowhere with Google. It’s on OS level shortcut, not specific to my text editor.

⌘ + left arrow

So there is the secret for anyone who is new to OS X and trying to find the ‘home’ key or the ‘end’ button. This appears to work for any program, including Sublime Text. And now, I can stop banging my head against this wall!

And for the record:

⌘ + right arrow

gets you to the beginning of the line, and up and down take you to the top and bottom of the entire document.