Developer Productivity Tips Part One
As a Software Developer, you might find yourself repeating the same tasks over and over again. From setting up a new laptop for the n-teenth time to executing a sequence of terminal commands to standup your local development environment, here are some of my favorite tools and tips that make everyday programming more efficient and most importantly, more fun.
Table of Contents
- Tip #1: Codify Laptop Setup
- Tip #2: Make Shell Aliases your best friend
- Tip #3: Become a Window Managing Wizard
Tip #1: Codify Laptop Setup
Whether it’s Day One at your new startup or you’ve found yourself once again replacing your MacBook ruined by another coffee spill, there’s nothing more tedious than getting your new hardware to match your oh so specific needs.
Sooo why not write some code to do this for you? Simply put your perfected .zshrc
and other system configuration files into source control, convert all of those application installs into homebrew
commands and write a simple script that will install all of your beloved editors and place their necessary configurations exactly where they need to be. Feel free to borrow from my setup.bash
script below.
Note: VSCode has added Settings Sync support, this is probably a better alternative to source controlling your keybindings.json
, etc.
Tip #2: Make Shell Aliases your best friend
Whether you develop within a single monorepo or several different repositories, you are likely running cd ../insert-path-here
more times everyday than you StackOverflow. I like to wield the power of shell aliases to streamline terminal directory navigation and frequently used commands, for example to run tests or start / stop services. This not only saves keystrokes (and thus ultimately delaying the inevitable carpal tunnel all developers are doomed to), but very valuable development time as well. Below are some example aliases and how they can save you time everyday:
By using absolute paths, you can navigate directly to our example monorepo’s web
or api
directory by simply running either web
or api
in your terminal no matter what your current working directory may be. You can then pair up your handy directory navigation aliases with an npm
command to write other aliases (sweb
and sapi
) that allows you to start these services from any directory.
Below are some more of my favorite aliases to make my everyday terminal interactions as efficient as possible:
Tip #3: Become a Window Managing Wizard
Tired of hitting CMD + TAB
to cycle between the fifteen different Electron applications running on your machine? Do you feel like you are searching for Waldo every time you three finger swipe up to look for the app you need? Do you feel like Bob Ross when you redraw each application’s canvas to perfectly fit your needs, only to have to do it all over again when you share the wrong screen on a Zoom call?
Look no further than the following tools to keep you from ever needing to take those hands off home row, making you feel like Mr. Robot bringing down the Dark Army every time you put your hands on that keyboard.
Window Management Tool: Magnet (paid) or Spectacle (free)
Hotkey Configuration Tools: Karabiner Elements and Hammerspoon
So what exactly can these tools do for me? Let’s compare life before and after these tools:
Before
After
Let’s dive into the tools that make this witchcraft all possible. First up is Magnet. All Magnet does is provide you with handy keyboard shortcuts that will automatically move your focused application window to a designated section of the screen. The ones I use most are CTRL + OPT + Left Arrow
and CTRL + OPT + Right Arrow
to snap the application in focus to either the left or right half of your screen. There are also many more options like Maximize
, Left Third
, and Right Two Thirds
that you may find useful in your everyday window management.
Now you’re probably wondering how those applications came flying into focus without the infamous three finger swipe or CMD + Tab
App Switcher… This is where Karabiner Elements and Hammerspoon come in handy.
In order to make this possible, we need to create a *hyper key* on our keyboard that when reprogrammed, can be used to bring to focus whatever application we want. So let’s make this happen!
Step 1: Decide on an unused keyboard key to convert into your magical *hyper key*
You’re probably thinking “But I use every key on my keyboard I can’t give up any of them!” Now honestly, how often do you hit the CAPS LOCK
key and think to yourself:
THANK GOODNESS I DON’T HAVE TO HOLD DOWN SHIFT RIGHT NOW!
If you have never said the phrase above, then this is an obvious candidate to become your magical new *hyper key*. However, if you are like me and developed on a pre-2019 MacBook Pro with TouchBar, you may have already re-programmed your CAPS LOCK
key to serve as your ESC
key instead 😱 I’m sorry Mavis Beacon, but I do not use both SHIFT
keys when typing, so I have actually reconfigured my Right SHIFT
key to be my magical *hyper key*.
Step 2: Use Karabiner Elements to reassign your magical *hyper key* to an impossible assortment of keystrokes
Karabiner Elements is simply a Keyboard Customizer for Mac. You can take any key on your keyboard and re-assign it to perform any combination of keystrokes.
After installing, simply navigate to the Complex modifications
tab and add the existing example rule for:
Change caps_lock to command+control+option+shift
All we’ve done so far is make it so every time you press your CAPS LOCK
key, your computer actually thinks you are pressing all four modifier keys at the exact same time. Why is this important? Keep reading to find out!
Step 3: Use Hammerspoon to create Keyboard Shortcuts with your new magical *hyper key* that bring applications to Focus
Hammerspoon allows you to write Lua scripts to automate interactions with the Mac OS.
First, download the latest version of Hammerspoon and move Hammerspoon
into your Applications
folder.
Then, we can write a Lua script in our Hammerspoon config directory that will allow us to assign our *hyper key* along with any other key to bring our desired application into focus.
touch ~/.hammerspoon/init.lua
Let’s break down the most important parts of this init.lua
script:
First we assign all four modifier keys into a variable called hyper
which will be used to reference our new *hyper key*.
local hyper = { "cmd", "alt", "ctrl", "shift" }
Then, we define a set of pairs, which maps a keyboard key and a desired application to open when pressed in combination with our *hyper key*. Next, we iterate over said pairs, and tell Hammerspoon
to bind
our *hyper key* and respective keyboard key to perform the action of launchOrFocus
on our desired application.
local applicationHotkeys = {
c = 'Google Chrome',
d = 'Calendar',
f = 'Finder',
g = 'DataGrip',
i = 'Insomnia',
n = 'Notes',
p = 'Spotify',
s = 'Slack',
t = 'iTerm',
v = 'Visual Studio Code',
z = 'zoom.us'
}
for key, app in pairs(applicationHotkeys) do
hs.hotkey.bind(hyper, key, function()
hs.application.launchOrFocus(app)
end)
end
Update local applicationHotkeys
with your frequently used applications along with a designated shortcut key. Finally, open Hammerspoon
and click Reload Config
.
Now you should be able to bring whatever application you want into focus at the convenience of pressing your *hyper key* and newly assigned application shortcut keys 🎉
Conclusion
I hope these tips find their way into your developer toolkit as they will not only make you feel like a master developer, but they will save you valuable time everyday.