From 4b519a1a13366d68769cc3960219131f1f43c108 Mon Sep 17 00:00:00 2001 From: Colin P. McCabe <cmccabe@apache.org> Date: Sun, 29 Dec 2024 15:10:00 -0800 Subject: [PATCH] open: fix for MacOS and add jpg --- open | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-) diff --git a/open b/open index dd6be3d..a965886 100755 --- a/open +++ b/open @@ -1,11 +1,28 @@ #!/usr/bin/env bash +# Use the built-in open command on MacOS. +UNAME=$(uname) +case $UNAME in + *Darwin*) exec open "$@";; +esac + +openwith() { + file="${1}" + application="${2}" + if [[ -n "${application}" ]]; then + if which "${application}" > /dev/null ; then + setsid nohup ${application} "${f}" > /dev/null 2> /dev/null + return + fi + fi + setsid nohup xdg-open "${f}" > /dev/null 2> /dev/null +} + +# Determine what command to run based on file extension. for f in "$@"; do - lowercased=`echo "$f" | sed 's/./\L&/g'` - case $lowercased in - *.pdf) - setsid nohup evince "${f}" > /dev/null 2> /dev/null;; - *) - setsid nohup xdg-open "${f}" > /dev/null 2> /dev/null;; + case ${f,,} in + *.jpg) openwith "${f}" ristretto;; + *.pdf) openwith "${f}" evince;; + *) openwith "${f}";; esac done -- 1.6.6.rc1.39.g9a42