Skip to content

Instantly share code, notes, and snippets.

@slumos
Created March 18, 2013 17:04
Show Gist options
  • Save slumos/5188836 to your computer and use it in GitHub Desktop.
Save slumos/5188836 to your computer and use it in GitHub Desktop.
Magical DWIM show the thing
function l {
if [[ ! -t 0 ]]; then
# stdin is not connected to a tty
pager -
elif [[ $# -eq 1 && -f "$1" ]]; then
# single argument names a file
pager "$1"
else
ls -CFL $*
fi
}
function pager {
case "$1" in
*asc)
gpg -dq "$1" | pager -
clear
;;
*bz|*bz2)
LESSOPEN='|bzip2 -cdq -- %s' "$PAGER" "$1"
;;
*gz)
LESSOPEN='|gzip -cdq -- %s' "$PAGER" "$1"
;;
*pdf|*png|*jpg)
ql "$1"
;;
*xz)
LESSOPEN='|xz -cdq -- %s' "$PAGER" "$1"
;;
*)
"$PAGER" "$1"
;;
esac
}
function ql {
qlmanage -p $*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment