Shot myself in the foot with Command-Option-Delete in Mac Mail

I use Mac (Mountain Lion, aka, OS X 10.8) Mail with Microsoft Office 365 at work and from time to time, I shoot myself in the foot by accidentally clicking Command-Option-Delete on a selected message(s).

The undesired outcome – the message(s) is gone forever – it is not in Trash folder, not in “Deleted Items” folder on the Office 365 Exchange server and not even in “Recover Deleted Items” context menu on “Deleted Items” folder. There is no confirmation dialog (as designed) and the action cannot be undone.

I think this happens to me because I frequently use Command-Shift-Delete to empty the Trash folder and Command-Option-0 to see Mail Activity window (it takes a while to sync between Microsoft Office 365 exchange server and local Mail app). The Command-Option-Delete combination is too close to the other two that I use frequently.

Yesterday, I ended up nuking an important message from my CTO at work and decided enough is enough.

My goal is to reassign Command-Option-Delete to something benign in the Mail app.

I tried going into System Preferences > Keyboard > Keyboard Shortcuts > Application Shortcuts and added an entry for Mail app (use the + button to bring up a list of applications to choose from). I typed in “Message Viewer” (that’s the benign action I picked because message viewer is always open and hence, Command-Option-Delete would do nothing but momentarily highlight the Mail app menu). However, when I got to the keyboard shortcut assignment field, I realized I cannot “type” the Delete key into that field. Hmm….

Some Googling later, I came across two posts on the venerable Stack Exchange network – the first post gave me a sense of how to specify Delete key on keyboard shortcuts (hint: you need to use the command line) and the second post showed me how to get settings into the Mail app via command line.

Steps to make Command-Option-Delete benign in Mac Mail app:

  1. Launch the Terminal application to get to a command line (/Applications/Utilities/Terminal.app)
  2. Type the following command and press <Enter>.
    defaults write com.apple.mail NSUserKeyEquivalents -dict-add "Message Viewer" "@~\U0008"
  3. If you are curious, @ = Command key, ~ = Option key and \U0008 is the Delete key.
  4. Close and re-open Mac Mail app (if it was open, when you did step 2 above)
  5. In Mac Mail app menu, navigate to Window > Message Viewer. You should see Command-Option-Delete is assigned to this action.

Happy feet!!

Work around slowness of oh-my-zsh Git plugins on large repositories

I spend more than half my work life using a command line terminal. I recently switched from the BASH shell to ZSH via oh-my-zsh.

I love oh-my-zsh!!

However, I have to work with a relatively large Git repository. This means, once navigate into this Git repo via the ZSH command line, each time the prompt is painted, there is a painful 2-3 sec wait. This doesn’t sound like much, but it really gets in the way of the flow of work when it continuously happens over several hours of work.

I am using the sunrise oh-my-zsh theme and the zsh prompt with this theme displays both the current Git branch and the dirty state of the repo. I had a strong inkling the latter dirty state computation was the culprit causing the slowness for me.

Looking into the ~/.oh-my-zsh/themes/sunrise.zsh.theme file, I found the custom_git_function() which is responsible for constructing the command prompt. The actual line of interest looks like:

echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$(git_prompt_ahead)$(custom_git_prompt_status)$ZSH_THEME_GIT_PROMPT_SUFFIX"

The parse_git_dirty, git_prompt_ahead and custom_git_prompt_status sections seemed like the problem. For me, all I want to know is the current branch. I really don’t care about these status flags.

I dropped these three status sections, resulting in a line like:

echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"

I saved this change to sunrise.zsh.theme file and re-launched my ZSH command prompt.

Voila! Speedy painting of the prompt in my large Git repo.

I am sure there is a cleaner way to override the ZSH prompts specified in an oh-my-zsh theme. If anyone out there knows or can point me to the documentation for this, I’d really appreciate it.