Permanently change hostname in Mac OS X

I've forgotten this more times than I've had hot meals (well, almost).

Changing your machine's hostname permanently so it doesn't reflect what it picks up from DHCP is as simple as these two commands:

% sudo scutil --set HostName [new hostname]
% sudo reboot

A change would do you good

Recently, my partner and I moved from rented accommodation to a house of our own. This gave us an opportunity to properly configure the environment in which we work. Like anyone, the choice to customise our new space was a natural one, though the benefits we've seen, well, they were somewhat unexpected.

I'd be stating the obvious if I were to say a pleasant environment makes one more productive, but I'd go so far as to say improving my workspace has, by a good deal, been the best investment in productivity. Beyond research, knowledge or even the tools I use, the place where I get things done is a huge contributing factor to my productivity; it'll allow me to make the best of my tools and experience.

This story starts with an investment in property and ends with a simple learning exercise, a broken computer and a few crows.

From the old

Before we moved, my partner and I had what I imagine would be a setup that a lot of people constrained on space would choose. In our flat, she put her computer in the living room and I took the second bedroom for my office. We'd use her machine for entertainment when she wasn't working. I'd use my machine mainly for work, and then for entertainment after she went to sleep (I have real trouble getting to sleep before midnight, and my partner's an "early to bed; early to rise" kind of person).

My partner's office contained her computer, the open-plan kitchen and a sofa we used for filing, which we'd hastily clean up when the parents would visit. My office contained all my music gear, my computers and objets d'art like a top hat, a Bakelite telephone and a disused ironing board. Both spaces separated us; neither joined the concerns of work and play. Add to this the fact that we were renting so couldn't decorate or put up shelves to contain all this paraphernalia and we had some pretty messy arrangements indeed.

To the new

When we finally bought our own house, we made the decision that this would all change: we'd work together in the same room (but allow ourselves the opportunity to work separately if we wanted); we'd have a space we'd enjoy being in; and we'd have a totally different space for entertainment and relaxing. No top hats, no sofas full of paperwork, all work and all play.

I'm most happy with the fact that my partner suggested I hang my guitars on the wall. I didn't prompt her, or even make hints. She suggested, of her own volition, that after 20 years of waiting I should have my guitars on the wall.

Guitars hanging on a wall

In reality, this was simply a space-saving exercise, but to me it feels like I finally have a place to come to relax, knowing that my instruments are right there, should the muse come to me.

At roughly the same time as my guitars went up, my partner's computer went down. After several years' good service, her Windows XP desktop just refused to connect to the internet, and finally to boot at all. The natural choice was to buy a laptop, and that she did. This not only means she has a nice, new, fast machine, but we can now do work in the office and in bed (where we spend most of our weekend mornings hacking on projects or keeping up to date with the news). This is great for so many reasons, but mainly because we can still work together even if one of us can't be bothered to go to the office.

Then there's the artwork. Another great choice from my partner: while we were in Rome a few years ago, she picked up a print of Michelangelo's Delphic Sibyl from the Sistine Chapel. She (the sibyl, that is) is now hanging on the opposing wall from my guitars. If there ever was an image that represented human inspiration and prophecy of greatness, this is it:

The Delphic Sibyl

The final touch on the workspace, for me, is my father's old standard-issue office desk, which he brought home from work more than fifteen years ago and gave to me. You can see it in the image at the top of this page. This beat-up old thing has been a workhorse for many years and still supports all my music gear, random paperwork and stationery.

Why write about this now?

Well, just yesterday, I was sat here at my father's old desk with my guitars and a prophet; my partner in the bedroom applying for jobs and me making a start at learning how to create a Django site. I decided that I should really modify my virtual environment as well as the real one I'm sat in. I'd recently downloaded the incredible Monument Valley for iOS and I thought of the impossible, beautiful worlds therein, matching my exploration of the infinite realm of Python web frameworks and my partner's journey into the unknown of a new job. I decided to change the hostname of my machine and the colourscheme of my terminal to match my mood. My MacBook Air is now called the-rookery after one of the chapters in the game. Unlike the derogatory term for city slums, 'the rookery' puts me in mind of vast spaces where the flightless can only dream of their possibilities and where those with wings can exploit the skies for pleasure and freedom.

Screenshot of the game, Monument Valley

How has this helped?

The rookery seems like a nice place to work. I thought of all the changes my partner and I have made over the last few weeks and how where we are now is equally pleasing and inspirational. I changed iTerm2's colours to a dark Base16 scheme to match the feathers on the Corvidae family of birds. Both the hostname and the colourscheme are the finishing touches on the work we've put in to our office space. Every time I hit the enter key, there I am at the rookery.

I must admit, since designing this space, I've felt more at ease, more likely to take healthy risks and more focused on working towards a goal. None of the changes we made was specifically designed for this; it just seems that a pleasant working environment really does boost productivity in ways we couldn't have measured until we did it.

So, as I learn Django with a light heart and dreams of flight, and as my partner continues her search for enlightenment, we can be sure that this little office and its tiny pleasures will help us on our way.

Productivity by spacial proxy, I shall call it until someone can tell me otherwise. Go create your own productivity proxy; I guarantee you'll enjoy it.

Take the conflict out of merging with Kaleidoscope

I generally dislike GUIs and love the command line, but one thing that has always terrified me is resolving Git merge conflicts. Especially in large, complex codebases. Try as I might, I can never remember which version of the file is placed between those crazy markers Git puts in. When I'm deciding on what to accept or reject in a complex merge, I don't want to be trying to navigate a file in search of conflicts. I need to concentrate on which lines of code won't break the world when they're mashed together. I want to point and click at something, definitely and surely. Did I think I'd ever say that as someone who would defend the command line 'til death? No. But one app changed my mind.

Spot the difference

I must admit, I was skeptical when I first read Black Pixel's description of their file comparison app, Kaleidoscope:

Use Kaleidoscope to spot the differences in text, images, and folders. Review and merge changes in seconds with the world's most advanced file comparison application.

I thought I'd give it a try and probably end up going back to the tools I know, like the humble diff. What could be more advanced than Unix commands, and why would I want to compare two images? Indeed, I tried it at a time when I wasn't using Git and, once the trial period ended, I removed the app and went about my day.

Fast forward to present day and, after a few hairy merge conflicts, wading through files searching for <<< or >>> over and over again, I was ready for an alternative.

Tim Pope's Vim plugin, Fugitive, in his words:

may very well be the best Git wrapper of all time.

And he's right, but still, while using it, I couldn't shake that fear of the merge conflict. Too many key commands. Too much to remember. What if people die as a result of this merge?

No. I needed to command the merge. I needed to point, with my trackpad, at the offending lines and direct them into place, like generals in days of yore with their troops on horseback (albeit without the trackpad). I hung up my hacker utility belt and decided to buy Kaleidoscope, jump in, and see what would happen.

To me, for all its features, Kaleidoscope shines most brilliantly during a merge. Using the unified layout, I'm presented with two panes for the three-way merge: one for the two versions that are conflicting, and one for the result. I can navigate through the conflicts – ignoring the rest of the code – and choose lines from either version A or B. I can edit text in the result pane too, if I wish. Once I'm done, I hit save, close the window, and Kaleidoscope throws me the next file with conflicts. Rinse, repeat, and the merge is complete.

It's for that reason alone that I'll stick with Kaleidoscope; it's there to guide me through the murky waters of learning how to code and I'm glad for it. If time is money, I'm getting pretty close already to recouping the $69.99 price tag. That and the savings on treatment for stress.

Only scratching the surface

There's so much more to Kaleidoscope than saving you from merge-conflict hell. As Black Pixel says, it'll compare your images and even your file system. The former, after some experimentation, very well indeed. These extras might prove essential to me in the future, but for now, it's all about the text.

Beta 2.1 includes some performance enhancements and the much-needed facility to ignore whitespace in comparisons. This is great if you're working with someone else who has their text editor set up to use tabs instead of spaces (or who is too lazy to remove spaces at the end of lines).

This is a healthy app that will continue only to improve.

It's worth noting a small, but important detail that might make moving to Kaleidoscope easier. I bought the Mac App Store (MAS) version, which is sandboxed and, therefore, can't integrate with Git. (Well, it can, just not through the app's preferences; you have to set it up manually.) For those who don't know how to specify an external tool for Git, I can see how this would be frustrating. Luckily, and cleverly, you can download a trial version directly from Black Pixel and it will authorise itself based on the receipt for the MAS version on your Mac. I've not seen this implemented in any other app that differs from the MAS sandboxed version. Nice touch.

Final thoughts

So, with all that in mind, it seems I'm willing to make an about face on my total love of the command line. There are apps out there that can surpass their text-based ancestors. Black Pixel's Kaleidoscope is one of them, and I thoroughly recommend you give it a chance.


Have you had a good experience with Kaleidoscope, or do you find other tools more useful? Comment on this post on Twitter.

Vim cheat sheet

Often I'll learn something cool about Vim: a new command, a new way to use a familiar command, or how to 'shell out' with fun results. Until these nuggets of wonder are written immutably to memory, I'll post them here so I can look them up wherever I am, and hopefully help others discover some small, useful aspects of the best text editor ever made.

I'll remove commands I can successfully recall, so be sure to note these down if you find them useful. But some of these commands will stay here for a while because I won't use them often.
I think it might be best to just keep adding for the time being.

If you're familiar with Vim's basic principles and want to level up, I recommend having a look at Vimcasts.org.

Inserting

  • Insert the current file name in normal mode with %p, or in insert mode with <C-R>%.

  • Insert (read) an entire file's contents at the specified line with :<line number>r </path/to/file>.

  • Insert (read) the output of an external command at the specified line, for instance: :3r !echo Hello will insert the word 'Hello' at line three. I'm sure you can think of more creative uses for this.

Deleting

  • Delete from the cursor back to the previous matching pair (like () or []) which contains the cursor with d%.

Searching

  • Substitue using last search pattern: [range]s//[replacement text]/.
  • Find lines longer than 25 characters: /^.\{25,}$/.
  • Find lines shorter than 25 characters: /^.\{,25}$/.
  • Count the number of matches without replacing with :%s/<pattern>//n.

Basic

  • Go to just before the end of the line, not including the carriage return with g_. Good with an action, so yg_ would yank the whole line and allow you to paste inline somewhere else without the carriage return.

Help tags

  • Go to the help tag under the cursor with <C-]>.
  • Retrun to the previous help tag with <C-o>.

Registers

  • Clear out a register with qaq. This essentially records a blank macro to your register of choice, in this case, register a.
  • Append to a register using its uppercase equivalent. To append a word to register a, type "Ayw.

History

  • In normal mode, show the command history with q: or the search history with q/. Navigate to the command or expression you want and type enter.

File handling

  • Save and quit the current file with ZZ.