Preserve bash history across multiple terminals and sessions

I use the bash command line on my Mac a lot. I typically have multiple tabs with multiple terminal panes open in iTerm2, often with multiple ssh sessions running. By default, the last terminal session to close trashes the bash history of all the other sessions. Is it possible to configure the terminal to preserve bash history?

Terminal windows with multiple panes to preserve bash history

Preserve bash history

It’s actually fairly straightforward to preserve the history.

Open up your ~/.bash_profile configuration file in an editor of your choice such as nano. Once you have it open, add these lines at the end:

# Maximum number of history lines in memory
export HISTSIZE=50000
# Maximum number of history lines on disk
export HISTFILESIZE=50000
# Ignore duplicate lines
export HISTCONTROL=ignoredups:erasedups
# When the shell exits, append to the history file 
#  instead of overwriting it
shopt -s histappend

# After each command, append to the history file 
#  and reread it
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"

Save the file an exit. In order for your configuration change to take effect, you will need to reload the configuration in all your open terminal sessions:

source ~/.bash_profile

This configuration change has to be done per user per machine.

Backup your bash configuration

I use mackup together with Dropbox to keep my bash and other command line configuration files backed up. This makes it easy to transfer your command line configuration to a new primary machine.


Preserve bash history in iTerm2

iTerm2 is my terminal of choice on the Mac. It has great tab and pane management accessible via both keyboard and mouse, and some subtle quality of life features.

For example, if you ssh somewhere, it sets the tab title to the hostname of the remote machine, or the name of the local directory.


One drastic alternative would be to migrate from Bash to an alternate shell like Fish or, in the future, the Next Generation Shell (NGS).

Setting up a new Macbook

I’ve just migrated to a new Macbook Pro as my primary work machine. As part of setting it up, I installed the following:

  • Caffeine to prevent it from going to sleep when I don’t want it to go to sleep
  • BetterTouchTool so that I can middle-click (three finger tap) to close tabs and paste in the terminal
  • f.lux to reduce eye-strain at night
  • Firefox as my web browser
  • Chrome so that I can run Authy for two-factor authentication on the desktop
  • Ditto for running Google Hangouts
  • iTerm2 as a superior, multi-pane terminal
  • Atom because it’s handy to have a text editor
  • Homebrew as an excellent package manager for installing Unix services and tools
  • Divvy for resizing windows to fractions of the screen


  • System Preferences > Trackpad > Tap to Click, so that I can click without mashing the trackpad
  • System Preferences > Accessibility > Cursor Size > Larger, so that the cursor is easy to find
  • System Preferences > Accessibility > “Reduce transparency” to get a solid menu bar
  • System Preferences > Sound > “Show volume in menu bar”, so that I can quickly adjust sound (and configure devices by option-clicking the icon)

    Option-clicking the volume icon
    Option-clicking the volume icon
  • Keychain Access > Preferences > “Show keychain status in menu bar”, so that I can quickly lock my laptop

    Quickly lock the screen
    Quickly lock the screen

Tuning wifi on Mac OS 10.10.3 Yosemite

I’ve experienced increasingly bad wifi performance on my Macbook Air over time. This has been accentuated further by me being somewhere with a lot of network lag. I did some research and the following suggestions made the wifi faster and more responsive with Mac OS 10.10.3 Yosemite.

1. Disable Bluetooth. I don’t use any wireless mice/keyboard/headsets, so Bluetooth doesn’t do anything for me.

2. Disable Facetime. Command+Space, Facetime. File > Preferences > [ ] Enable this account. I’ve never used Facetime, but from what I understand it’s Apple’s clone of Skype that only works with other Apple users.

3. Disable Handoff. System Preferences > General > [ ] Allow Handoff between this Mac and your iCloud devices. Handoff is Apple’s recent attempt to increase platform lock-in for those unfortunate souls who use non-Macbook Apple devices. Seemingly, it negatively affects network performance.

These three steps noticeably improved my wifi performance.

If that doesn’t help, there are more involved things you can do to tune Yosemite wifi performance or work around other Yosemite bugs.

I, for one, look forward to the forthcoming release of Mac OS 10.11 El Capitan.


How to run and install IPMIView on Mac

Edit: The download link doesn’t work anymore, but it looks like IPMIView is now available in the Mac App Store. Also, just in case, someone suggested running the Linux version on Mac.

Softlayer cloud uses IPMIView for direct console access to bare metal hardware. SuperMicro makes a Mac version of IPMIView available for download.

Bizarrely, SuperMicro doesn’t appear to have ever tested it, because double-clicking on the downloaded IPMIView20 application doesn’t do anything. This is because someone forgot to set the execute permission on the installer.

Supposing it’s in your downloads folder, open up Terminal and run the following commands:

cd /Users/$( whoami )/Downloads/
chmod u+x IPMIView20

This will open up the installer for you. Once it’s installed, it will show up in your Launchpad like a normal application.




How to rename a file in a File upload dialog on Mac

Windows users will scoff at this, but renaming a file in a File Upload dialog box on Mac is a surprisingly obscure action. Renaming is not available in the context menu, nor does the usual shortcut work.

Screenshot 2014-03-24 18.01.26To rename a file in a regular Finder window, you can select it and hit the Enter key. However, you can’t do this in a File Upload dialog as the Enter key has a different meaning.

To rename a file, select it, hit Cmd+I, open up the Name & Extension pane, and change the name.

Windows to Mac: Keyboard shortcuts

In December, I got a Macbook Air that I’m now using as a primary development machine. Before that, I was developing on a Windows 7 machine with heavy reliance on Git bash and Cygwin, and using Linux on the server. I’ve used Linux as a primary desktop at times, but found both dual-boot and VMs too much of a hassle.

I’m enjoying the Mac, but one of the biggest adjustments is keyboard shortcuts.

Here are some shortcuts that are specific to the Mac Terminal (and Terminal alternatives like iTerm 2):

[vtftable ]
Mac ;;; Mac Terminal ;;; Windows ;;; Action ;nn;
Cmd+Left Arrow ;;; Ctrl+A ;;; Home ;;; Go to start of line ;nn;
Cmd+Right Arrow ;;; Ctrl+E ;;; End ;;; Go to end of line ;nn;
Shift+Cmd+Left Arrow ;;; ;;; Shift+Home ;;; Select to start of line ;nn;
Shift+Cmd+Right Arrow ;;; ;;; Shift+End ;;; Select to end of line ;nn;
;;; Ctrl+K ;;; ;;; Clear line after cursor ;nn;
;;; Ctrl+U ;;; ;;; Clear line before cursor;nn;

Some general shortcuts:

[vtftable ]
Mac ;;; Windows ;;; Action ;nn;
Cmd+Down Arrow;;; PageDn ;;; Go one page down ;nn;
Cmd+Up Arrow ;;; PageUp ;;; Go one page up ;nn;
;;; ;;; ;nn;
Cmd+Space ;;; Windows key ;;; Start menu/Spotlight ;nn;
Cmd+Opt+Esc ;;; Ctrl+Shift+Esc ;;; Open Task Manager ;nn;
Cmd+Delete ;;; Delete ;;; Delete selected files ;nn;
;;; ;;; ;nn;
Cmd+Delete ;;; Delete ;;; Delete character in front of the cursor ;nn;
;;; ;;; ;nn;
Cmd+R ;;; F5 ;;; Reload current webpage ;nn;
;;; ;;; ;nn;
Cmd+Shift+3 ;;; ;;; Save screenshot to desktop/Dropbox ;nn;
Cmd+Ctrl+Shift+3 ;;; PrtScr ;;; Copy screenshot to clipboard ;nn;
Cmd+Shift+4 ;;; ;;; Save screenshot of an area of screen to desktop/Dropbox ;nn;
Cmd+Ctrl+Shift+4 ;;; PrtScr (SnagIt) ;;; Copy screenshot of an area of screen to clipboard ;nn;

Of course, there are many more shortcuts.