DEV Community

Cover image for I spend one hour a week optimizing my development environment.
Oryan Moshe
Oryan Moshe

Posted on

I spend one hour a week optimizing my development environment.

The story of my unreasonable efficiency obsession - and the tools I use to fuel it

If you're a productivity freak like me you probably found yourself in the following situation (presumably in the last week):

You have a task to complete, you sit down, open up your laptop and suddenly, it happens.
That annoying little thing you have to do every single time. It might happen once an hour, once a day, maybe once a week, but it drives you bananas.

It could be something small like inserting your MFA codes, closing a pop-up or even switching to "normal" mode on vim.
It could be something more time consuming like rearranging your displays layout after replugging your Mac, changing your connection string to a readonly production database, or restarting your environment when changes are not affecting it.

It doesn't matter, the point is it's something you're doing instead of what you'd rather be doing.

8 months ago I decided to stop the madness. I started reserving 1 hour a week to get rid of these little nuisances.


Let's talk tools

So there are many tools that help me work towards my goal of ultimate efficiency. Some of them are free, some of them cost some bucks, heck, I even paid 50 bucks for one of them. You don't have to use the ones I suggest, and for every paid one I'm sure you can find a free one or create one yourself.

BetterTouchTool > $7.5 - $21

BetterTouchTool is the first tool I used to customize my development experience, I installed it even before starting my current position (I received my laptop beforehand) and I can't believe how much I use it every day.
In a nutshell - it allows you to customize everything "input related" in your Mac, including your Magic Mouse, trackpad, keyboard and even your Touch Bar (if you use a compatible version)

Karabiner-Elements > Free - Open source

Karabiner is one of those tools I expect every OS to have built in. It allows you to remap any key on your keyboard to do anything you want. Why isn't it a standard??

Alfred + Powerpack > £23 - £39

Alfred is probably the first tool I'll ever go to when trying to solve a workflow issue. Alfred (a free tool, massively extended by a paid "Powerpack") has way too many functions to tell you about here, but it's essentially Spotlight on steroids. It allows countless customizations and features out-of-the-box improvements that'll make you wish you met it before.


The changes that changed my life

1. Customizing my Touch Bar

If you have a Macbook pro with a Touch Bar, sooner or later you probably thought to yourself: "Damn, that is one piece of unutilized potentiel".
And it is, Apple definitely dropped the ball on that front.
Luckily, I used BetterTouchTool to customize it and make it not suck!



As you can see I left the esc key in the top left corner (we'll talk about the esc situation later), and I put a few shortcuts to applications I frequently use (Finder, Hyper terminal, VS Code)

That red Production / green Development block indicates what is the current state of my database.yml file (in rails based applications your connection strings are kept there), this allows me to know whether I'm working against my local DB or readonly production DB in a glance.

I also added a block that shows me my current internal IP address (useful when I want to share a link to a local server with a colleague), a mute button, a DateTime block with seconds (important when wanting to get a feel about query performance) that also takes me to my calendar on tap, and a "Coffee Break" button that locks my laptop.

Obviously when Spotify or Youtube are playing I have a block appear in the middle with some useful functions.

Another cool feature I utilized is 2 fingers drag to control brightness, and 3 fingers drag to control volume.

2. Replacing my Caps Lock with ESC

If you know me, you probably know I have a mild case of keyboard fetish. I build them, I collect them, I try to make the ones that best suit my style.

One thing I have to do on every system I use is remap my Caps Lock key to ESC, and especially in this specific Mac. I mean, who on earth would prefer § over a physical esc key??

If you use vim you know how important it is to have the esc key as close to you as possible, and as I started using it more and more I realized I'm using it for things other than vim. Closing pop-ups, blurring inputs, opening the console in Chrome devtools. Escape is the unsung hero of keys.

I use Karabiner-Elements to remap the useless Caps Lock (it's 2019, if you use Caps Lock it's time for some re-education) into an esc. Can't get easier than that.

3. Space Cadet Shift

In case you haven't read this excellent article by Steve Losh, I highly recommend you do, but the customization I liked (and used) the most ever since I read it is the "Space Cadet Shift Parentheses".

It turns your left_shift key into a ( and your right_shift key into a ) if they're pressed briefly, and treats them as normal shift modifier keys when held and combined with another key.

This allows me to type parentheses with one keystroke, which makes much more sense than the traditional way of shift + 9, as I probably use parentheses hundreds of times a day.

4. Clipboard history

This is truly a game changer. I specifically use Alfred's clipboard from the Powerpack binded to a cmd + shift + v shortcut, but you can use the free software "Jumpcut" instead.
What this essentially does is keep a history of your copied items, including text and images.

Originally, I started using it to stop these "F*ck, I copied over that super important thing I had in my clipboard and now I have to go back and copy it again" moments I kept having, but as time went on I started using it as an actual tool.

I copy multiple items from one application, then go to another application and paste them as needed without having to switch back.

5. Rearranging the display layout

If you have a Mac and 2 displays you're probably familiar with the issue.
You disconnect your laptop to go to a meeting, and when you come back your screens are all messed up, the spaces go to wherever they feel like and you're left there dragging windows from one display to the other for 2 minutes.

What I discovered is that you can change your main display 3 times (if you do it in the correct order) and the displays will go back to where you want them!
This in itself is a huge time-saver, but I wanted to take it to the next level, so I created an Alfred workflow.

A workflow is a set of actions, these can be scripts, changes in settings, push notifications and a ton of other actions, executed in order and triggered by a keyword in Alfred or a keyboard shortcut.

Using the free cli tool displayplacer, I was able to record the current displays state after each "main display change", and after I had all 3 I chained them together in a workflow triggered by the keyword arr (short for arrange).

Now every time I sit at my desk, I plug in my displays, press + space (my Alfred shortcut), type arr in, and the displays are fixed!

6. Changing my DB connection string

The amounts of data we work with don't allow us to pull the data to our local machine and work on it, so we sometimes have to change our connection string (our database.yml file) to connect to a read-only replica of our production DB to see how the data looks on a new dashboard or what not.

This process happens about 6-7 times a day, and every time I have to open the database.yml in my editor, uncomment / comment the lines of the production DB, save the file and restart my rails server (which we'll solve later)

I created an Alfred workflow that simply replaces my database.yml with the correct one according to the command I typed in, and saves a file stating which file is currently in use (remember that red/green block in the Touch Bar?)

Typing dbd changes my DB to development, and dbp to production.

7. Automatically restarting a local server

Anyone who developed some node.js knows nodemon, a great utility that allows you to run a node server, and restarts it whenever the files change.
But did you know nodemon can work on any cli tool and watch any file type?

Changing my rs alias (rails server) to

alias rs="nodemon --watch config -e rb,yml --exec \"rails server -b 0.0.0.0 -p 3002\"
Enter fullscreen mode Exit fullscreen mode

Allows me to run my server, and whenever a file in the config directory with an rb or yml extension is changed, it restarts the server! No more manual restart on database.yml change!

8. sudo TouchID

Whenever I need to type the master password of my Mac I'm annoyed. Why? Because I have TouchID! Why should I type a password instead of biometrically identifying myself?

I discovered that I can add a simple line to the sudo PAM (Pluggable Authentication Module) and from now on every time I need to sudo a command I just have to put my finger on the sensor!
Just add the following line to the top of your /private/etc/pam.d/sudo file:

auth sufficient pam_tid.so
Enter fullscreen mode Exit fullscreen mode

9. MFA without my phone

For this one I'll refer you to this fantastic workflow that inspired me, but in short - you can create an Alfred workflow that pastes an MFA code without you having to open your phone.

To keep my accounts secure (there's a reason for MFA after all) I changed the script permissions to "root only" and ran it as sudo.
If you remember from #8, sudoing on my Mac requires a fingerprint, and this allows me to protect my MFA tokens with a fingerprint, while not having to reach for my phone every time GitHub invalidates my session.

10. Starting my development environment

Our development environment is semi-complex, and personally I like to work in a specific way.
My terminal is Hyper, customized exactly as I like it, I have one tab split into 3 sections, one for docker-compose, one for our npm transpiler, and one for the rails server.

Other than that tab I have 2 more tabs, one for a rails console and the other for git management.

Instead of opening all of these tabs and typing all of these commands every time I'm starting my devenv, I created an Alfred workflow triggered by the keyboard shortcut cmd + shift + b that does all of that for me!


Honorable mentions

Not all of my optimizations have a story behind them, some are trivial and are still huge time savers

Aliases

Use shell aliases.
Whenever you have a long command you have to type more than once in a lifetime, throw it into an alias. You'll be surprised by how much you use it.

Terminal configuration

Apart from aliases there are a lot of customizations to do in your terminal. From shell customization including fzf and history auto-complete to better tab management and better remoting tools (like mosh)
The terminal is your friend and you spend a lot of time in it. Treat it nicely.

Calculator

You can use Spotlight / Alfred as a calculator. Apparently this isn't as known as I thought it was.

Using spaces

I know it's hard to get used to compared to Windows windows, but honestly spaces are the best way to get around a Mac. Take the time, learn to use them and learn all the gestures. Navigating spaces is way faster than dragging windows around.

Trackpad 3 fingers drag

You can drag with 3 fingers instead of click and dragging on the trackpad. Turn on this gesture, your fingers will thank you!
You can find it in Preferences > Accessibility > Mouse & Trackpad > Trackpad Options... > Enable dragging > three finger drag.


I have many more optimizations just like the ones posted here, if you'd like me to create a follow-up post just say 🙃

You spend hours in front of your computer, make sure every minute counts.

Top comments (34)

Collapse
 
gypsydave5 profile image
David Wickes • Edited

Lovely list!

Replacing my Caps Lock with ESC

If you're looking to take this hack a little further (and I'm sure you are if you've gone Spacecadet with your shift keys), try the Karabiner modification that changes Caps Lock to Escape on a single press, Control on hold.

Making Control easier to press will open up using the Emacs-like key bindings that are prevalent across OSX and its applications (i.e. Ctrl-p and Ctrl-n to navigate up and down in menus, terminal history, etc.)

I probably use parentheses hundreds of times a day.

I sincerely hope you're writing Common Lisp and loving it.

Calculator

While I love Alfred, if I'm doing any on the fly calculation I'll tend to use dc. Because it plays nicely with the rest of my unix tooling it's good if I can stay familiar with how it works- and the only way to stay familiar with something is to keep using it!

Collapse
 
oryanmoshe profile image
Oryan Moshe

Love the Control on hold idea, would definitely try it out and see if it suits my style!
As much as I love cli tools, dc is a bit too hardcore for me, usually the calculations I do are stuff like 24*60.

Collapse
 
gypsydave5 profile image
David Wickes

As much as I love cli tools, dc is a bit too hardcore for me, usually the calculations I do are stuff like 24*60.

For me it really shines as a part of an editor workflow. You can write the calculation on a line in Vim (or whatever), and then pipe it into dc and see the result in your editor.

bc is also available if you're not a fan of reverse Polish notation :D

Thread Thread
 
oryanmoshe profile image
Oryan Moshe

For vim this definitely works better than Alfred.
When I'm in a vim zone I usually don't use much of the GUI so it might be worthwhile to learn dc better!

Thread Thread
 
kungtotte profile image
Thomas Landin • Edited

For quick calculations you don't even have to leave vim or pipe out to anything!

<C-r>= in insert mode lets you type mathematical expressions and have the result inserted into your buffer. You need to add a decimal point if you want a floating point result otherwise it truncates to integers.

Bonus tip:
[num]<C-a> and [num]<C-x> will add or subtract num from the number under the cursor or the next number on the line if there's no number under the cursor. It defaults to 1 if you leave [num] out.

Collapse
 
kbilleter profile image
kbilleter

qalc is good

Collapse
 
havespacesuit profile image
Eric Sundquist

For Windows, AutoHotkey is a great scripting language that you can use to map all sorts of commands and macros to any keyboard shortcut. I even have it set up to have custom keyboard shortcuts depending on the title of the open window.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

1 hour a week, damn that's relatively a lot of time! I am a recovering tweaker, resist all temptation to do anything like this, the only thing I couldn't help. Change my PS1 to yellow with a branch name. Ultimately I have used a MacBook Pro for 2 years and I'm not impressed really anymore, I want something I don't have to change a trillion settings to feel productive. I'd better stay away from Linux then too.

Collapse
 
oryanmoshe profile image
Oryan Moshe

One hour seems excessive, but it's sort of a hobby so I guess It doesn't seem as much from my POV (:
My shell is customized out of control, adding a branch name to the prompt is definitely a must on every system!
I might make another post specifically about shell customization.

I'd better stay away from Linux then too.

As a former Arch / Gentoo Linux user, if you don't have time to tweak the system, I completely agree :P

Collapse
 
nolansym profile image
Jordan Gilliam

+1 for Alfred, but honestly I feel lost on any mac that doesn't have Spectacle installed. I know this might be a character flaw - but I physically cringe when someone spends 10 seconds using their mouse to rearrange window size.

spectacleapp.com/ 😍🔥💯📈

Collapse
 
oryanmoshe profile image
Oryan Moshe

As I said, I think the best way to navigate around a mac is by using spaces (built in fullscreen)
I literally never use any app in windowed mode.

But most of my co-workers do use spectacle so I can definitely agree it works for most people!

Collapse
 
kbilleter profile image
kbilleter

There's also HammerSpoon for .. any automation really :-) But it's good for navigation / moving stuff around

Collapse
 
logicxd profile image
David Moe

Great article! I'm going to try #3, #4, and #5!

For #3, the article for turing left_shift into ( is a little outdated.

Here's how I got it to work:

  • Download Karabiner-Elements
  • Open the link: karabiner://karabiner/assets/complex_modifications/import?url=https%3A%2F%2Fgist.githubusercontent.com%2Feyemyth%2Fdb4f923bcbd640b2d71a5f3fa0670e3a%2Fraw%2Fe62566f8db8985c07eb33df9459f247561218614%2Fshift_to_parentheses.json taken from github.com/tekezo/Karabiner-Elemen...
Collapse
 
oryanmoshe profile image
Oryan Moshe

I linked that article mainly for the philosophy behind Space Cadet, and not for practical info.
Thanks for sharing this Karabiner recipe! I'm sure it'll help a lot of people who didn't have a chance to get dirty with complex modifications (:

Collapse
 
attacomsian profile image
Atta

Thank you for a wonderful post 🙌

Clipboard history is very useful especially if you do a lot of copy paste (like me). I used to use ClipX on Windows a lot for copying multiple things and pasting them one by one. Last year, I switched to Ubuntu and it was terrible to work without ClipX for few months. I wish to see something similar to ClipX for Linux too (happy to pay $$).

Collapse
 
oryanmoshe profile image
Oryan Moshe

It'll probably be hard to find something similar to ClipX, as it uses the context menu which isn't really a key part of *nix systems.
Did you try CopyQ?

Collapse
 
attacomsian profile image
Atta

Yes. I tried CopyQ but it is not as good as ClipX is. I really liked the shortcuts and context menu.

Collapse
 
anas2204 profile image
Anas Siddiqui

I love Better Touch Tool as well, and it has added immense productivity on my Mac. Being table to customize Tab-changing on VS-Code/Chrome/Terminal saves so much effort (I have made 3-finger swipe left/right on all possible apps)

Collapse
 
fnky profile image
Christian Petersen

I use Karabiner-Elements to remap the useless Caps Lock (it's 2019, if you use Caps Lock it's time for some re-education) into an esc. Can't get easier than that.

You can also set this directly in macOS through System Preferences > Keyboard > Modifier Keys…. Of course, if you wan't a more advanced setup where you'd like to use Caps Lock for both ESC and Control, depending on how long you hold the button, or to support the Space Cadet Shift, then Karabiner is indispensable.

Personally, I use Karabiner solely for the remapping keys for my external keyboards to match the macOS key mapping and otherwise use the OS features to do the rest.

Trackpad 3 fingers drag

I cannot live without this feature. I miss it every time I use someone else's Mac for even a brief moment.

Collapse
 
lardissone profile image
Leandro Ardissone

Nice list!

I use Workspaces to accomplish many of your launch things.

Also use tmux + tmuxinator in my terminal to load dev environments.

For example, this script launches my MongoDB and Redis servers in a single iTerm2 tab:

# ~/.tmuxinator/dbs.yml

name: dbs
root: ~/dev

windows:
  - dbs:
      layout: even-vertical
      panes:
        - mongod --notablescan
        - redis-server /usr/local/etc/redis.conf

And I can launch it using: tmuxinator dbs (or mux dbs with my fish-shell alias).

Collapse
 
jwkicklighter profile image
Jordan Kicklighter

These are great! Would you mind sharing the details of the Alfred workflows (specifically that last one) and maybe the related Applescripts?

Collapse
 
oryanmoshe profile image
Oryan Moshe

I can share the workflows themselves, but honestly they're pretty boring 😅
Nothing too crazy going on there.
Here's the Applescripts for the last one, hope you can adjust them to your use case!

on alfred_script(q)
    tell application "Hyper.app"
            activate
        tell application "System Events"
            keystroke "bb"
            key code 36
            keystroke "rs"
        end tell
    end tell
end alfred_script

bb is my alias for switching to my dev folder, 36 is the keycode for enter, and rs is my alias for rails server over nodemon