dotfiles

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

commit 2fafc9c026f29746526258612028bc9971f6b79a
parent 1bf5d209f4c5b549bef87d2d0c74fd468b6e8a6b
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Fri,  2 Oct 2020 15:01:28 +0200

open: generic open command dispatching based on OS

Former-commit-id: 224417f288e2246bc6e07105dd09d4f5db13b7fc
Diffstat:
Ascripts/open | 50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/scripts/open b/scripts/open @@ -0,0 +1,50 @@ +#!/bin/sh +os=$(uname -s | tr '[:upper:]' '[:lower:]') + +PARAMS="" +while [ $(("$#")) -ne 0 ]; do + case "$1" in + -g|--background) + background=1 + shift 2 + ;; + -h|--help) + echo "Usage:" + echo "open [-g] file" + exit 0 + ;; + --) # end arg parsing + shift + break + ;; + -*) # unsupported flags + echo "Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done +eval set -- "$PARAMS" + +background=${background:-0} +case $os in + linux*) + # not sure how backgrounding is handled with xdg-open + command xdg-open "$@" + ;; + darwin*) + if [ $background -eq 1 ]; then open -g "$@" + else open "$@" + fi + /usr/bin/open "$@" + ;; + msys*|cygwin*|mingw*|nt|win*) + printf "Windows not supported yet.\n" + ;; + *) + printf "Operating system %s not supported yet.\n" "$os" + ;; +esac