From c3f41f43d702109f99bed9a992baeb6d0cff5199 Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Sun, 30 Oct 2016 07:16:33 +0000 Subject: [PATCH 3/4] xdg-open: support multiple arguments To avoid changing lots of code, the open_* functions are called in a subshell (they all end up exiting the process). --- scripts/desc/xdg-open.xml | 12 ++--- scripts/xdg-open.in | 125 +++++++++++++++++++++++----------------------- 2 files changed, 67 insertions(+), 70 deletions(-) diff --git a/scripts/desc/xdg-open.xml b/scripts/desc/xdg-open.xml index 2bfdf0b..d89fd57 100644 --- a/scripts/desc/xdg-open.xml +++ b/scripts/desc/xdg-open.xml @@ -30,13 +30,13 @@ xdg-open - opens a file or URL in the user's preferred application + opens files and/or URLs in the user's preferred applications xdg-open - + @@ -54,11 +54,7 @@ Description - xdg-open opens a file or URL in the user's preferred application. - If a URL is provided the URL will be opened in the user's preferred - web browser. If a file is provided the file will be opened in the - preferred application for files of that type. xdg-open supports - file, ftp, http and https URLs. + xdg-open opens the given files and/or URLs in the user's preferred applications. xdg-open is for use inside a desktop session only. @@ -131,7 +127,7 @@ - The action failed. + At least one file or URL could not be opened. diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in index b6528d5..886b474 100644 --- a/scripts/xdg-open.in +++ b/scripts/xdg-open.in @@ -424,30 +424,56 @@ open_lxde() fi } -[ x"$1" != x"" ] || exit_failure_syntax +open_one_argument() +{ + case "$DE" in + kde) + open_kde "$1" + ;; -url= -while [ $# -gt 0 ] ; do - parm="$1" - shift + gnome3|cinnamon) + open_gnome3 "$1" + ;; - case "$parm" in - -*) - exit_failure_syntax "unexpected option '$parm'" - ;; + gnome) + open_gnome "$1" + ;; - *) - if [ -n "$url" ] ; then - exit_failure_syntax "unexpected argument '$parm'" - fi - url="$parm" - ;; + mate) + open_mate "$1" + ;; + + xfce) + open_xfce "$1" + ;; + + lxde) + open_lxde "$1" + ;; + + enlightenment) + open_enlightenment "$1" + ;; + + cygwin) + open_cygwin "$1" + ;; + + darwin) + open_darwin "$1" + ;; + + generic) + open_generic "$1" + ;; + + *) + exit_failure_operation_impossible "no method available for opening '$1'" + ;; esac -done +} -if [ -z "${url}" ] ; then - exit_failure_syntax "file or URL argument missing" -fi +[ x"$1" != x"" ] || exit_failure_syntax detectDE @@ -467,48 +493,23 @@ case "${BROWSER}" in ;; esac -case "$DE" in - kde) - open_kde "$url" - ;; - - gnome3|cinnamon) - open_gnome3 "$url" - ;; - - gnome) - open_gnome "$url" - ;; - - mate) - open_mate "$url" - ;; - - xfce) - open_xfce "$url" - ;; - - lxde) - open_lxde "$url" - ;; - - enlightenment) - open_enlightenment "$url" - ;; - - cygwin) - open_cygwin "$url" - ;; - - darwin) - open_darwin "$url" - ;; +err=0 +while [ $# -gt 0 ]; do + parm="$1" + shift - generic) - open_generic "$url" - ;; + case "$parm" in + -*) + exit_failure_syntax "unexpected option '$parm'" + ;; - *) - exit_failure_operation_impossible "no method available for opening '$url'" - ;; -esac + *) + (open_one_argument "$parm") + this_err=$? + if [ $err -eq 0 ]; then + err=$this_err + fi + ;; + esac +done +exit $err -- 2.7.4