aboutsummaryrefslogtreecommitdiff
path: root/bash_open
blob: 603d82fc4b88355e6d165fe6f7641ee850e9293f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open_func() {
  file="$1"

  IFS='/' read -r major minor < <(file -ib "$file" 2>/dev/null | cut -d ';' -f 1)

  case "$major/$minor" in
    text/html)
      firefox "$file";;
    application/pdf)
      zathura "$file";;
    image/*)
      feh "$file";;
    text/*)
      xterm -e vim "$file";;
    video/*)
      mplayer "$file";;
    *)
      /usr/bin/xdg-open "$file";;
  esac
}

command -v open >/dev/null 2>&1 && alias o=open || alias o=open_func