Last Updated: February 25, 2016
·
148
· slumos

DWIM List/Viewer

Came up with this a few years ago and later refactored and added QuickLook. I love it for exploring a directory tree. I think of it as "show me thing" and don't make me think too much about what thing is.

Usage:

  • List a directory: l dirname
  • List some files: l **/*rb
  • Page a file: l filename
  • Uncompress and page: l filename.(gz|bz2)
  • View with quicklook: l filename.(pdf|png|jpg)
function l {
  if [[ $# -eq 1 && -f "$1" ]]; then
    pager "$1"
  else
    ls -CFL $*
  fi
}

function pager {
  case "$1" in
    *gz)
      LESSOPEN='|gzip -cdfq -- %s' "$PAGER" "$1"
      ;;
    *bz|*bz2)
      LESSOPEN='|bzip2 -cdfq -- %s' "$PAGER" "$1"
      ;;
    *pdf|*png|*jpg)
      ql "$1"
      ;;
    *)
      "$PAGER" "$1"
      ;;
  esac
}
  function ql {
    # Open QuickLook on file (OSX)
    qlmanage -p $*
  }