Mac command line niceties

I've made some additions to my .bashrc today based on this article. First, the usage:

Screenshot of Quick Look invoked from the command line, waiting for a key press

Then I press any key (Return, Esc, Space, whatever), and...

Screenshot of command line after Quick Look exits

I can also do this:

Screenshot of a Finder window opened from the command line for the shell's current working directory

That is, I can open a finder window in the current directory just by typing open—no need to explicitly specify '.' as the argument.

Here's the code:

function ql () {
  (qlmanage -p "$@" > /dev/null 2>&1 &
    local qlmanage_pid=$!
    read -sn 1
    kill ${qlmanage_pid}) > /dev/null 2>&1
}

function open () {
  if [ -z "$*" ]; then
    /usr/bin/open .
  else
    /usr/bin/open "$@"
  fi
}

About this entry