dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

open (1150B)


      1 #!/bin/sh
      2 # A wrapper around xdg-open and macOS's open
      3 
      4 PARAMS=""
      5 while [ $(($#)) -ne 0 ]; do
      6   case "$1" in
      7     -g|-j|-gj)
      8       background=1
      9       shift
     10       ;;
     11     -a)
     12       app="$2"
     13       shift 2
     14       ;;
     15     -h|--help)
     16       echo "Usage:"
     17       echo "open [-g] file"
     18       exit 0
     19       ;;
     20     --) # end arg parsing
     21       shift
     22       break
     23       ;;
     24     -*) # unsupported flags
     25       echo "Unsupported flag $1" >&2
     26       exit 1
     27       ;;
     28     *) # preserve positional arguments
     29       { [ -z "$PARAMS" ] && PARAMS="$(printf '%q' "$1")"; }|| PARAMS="$PARAMS $(printf '%q' "$1")"
     30       shift
     31       ;;
     32   esac
     33 done
     34 eval set -- "$PARAMS"
     35 
     36 background=${background:-0}
     37 os=$(uname -s | tr '[:upper:]' '[:lower:]')
     38 
     39 case "$os" in
     40   linux*)
     41     # not sure how backgrounding is handled with xdg-open
     42     command xdg-open "$@"
     43     ;;
     44   darwin*)
     45     if [ $background -eq 1 ]; then /usr/bin/open -gj "$@"
     46     elif [ -n "$app" ]; then /usr/bin/open -a "$app" "$@"
     47     else /usr/bin/open "$@"
     48     fi
     49     ;;
     50   msys*|cygwin*|mingw*|nt|win*)
     51     printf "Windows not supported yet.\n"
     52     ;;
     53   *)
     54     printf "Operating system %s not supported yet.\n" "$os"
     55     ;;
     56 esac