From a22eb10353ce124829bda4d652dec3a5c53a5934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Mon, 10 Jan 2011 17:41:10 +0100 Subject: [PATCH] Added -- option to support opening filenames beginning with - e.g. $ cat > -test.txt test ^D $ xdg-open -- -test.txt A testcase is included. However the following filenames --help,--version,--manual still won't work! --- scripts/xdg-open.in | 16 +++++++++++----- tests/xdg-open/t.06-open_option | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 tests/xdg-open/t.06-open_option diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in index bc756d0..7c3b86c 100644 --- a/scripts/xdg-open.in +++ b/scripts/xdg-open.in @@ -39,12 +39,12 @@ first_word() open_kde() { if kde-open -v 2>/dev/null 1>&2; then - kde-open "$1" + kde-open -- "$1" else if [ x"$KDE_SESSION_VERSION" = x"4" ]; then - kfmclient openURL "$1" + kfmclient openURL -- "$1" else - kfmclient exec "$1" + kfmclient exec -- "$1" kfmclient_fix_exit_code $? fi fi @@ -59,7 +59,7 @@ open_kde() open_gnome() { if gvfs-open --help 2>/dev/null 1>&2; then - gvfs-open "$1" + gvfs-open -- "$1" else gnome-open "$1" fi @@ -73,7 +73,7 @@ open_gnome() open_xfce() { - exo-open "$1" + exo-open -- "$1" if [ $? -eq 0 ]; then exit_success @@ -199,6 +199,12 @@ while [ $# -gt 0 ] ; do shift case "$parm" in + --) + url="$1" + echo "-- $url" + break + ;; + -*) exit_failure_syntax "unexpected option '$parm'" ;; diff --git a/tests/xdg-open/t.06-open_option b/tests/xdg-open/t.06-open_option new file mode 100644 index 0000000..d057d3e --- /dev/null +++ b/tests/xdg-open/t.06-open_option @@ -0,0 +1,33 @@ +#!/bin/bash + +## Include utility functions. +. "$XDG_TEST_DIR/include/testassertions.sh" +. "$XDG_TEST_DIR/include/testcontrol.sh" + +## Test function +test_open_option() { +test_start "$FUNCNAME: verify opening a file starting with a - test." + +test_init + +require_notroot + +assert_display +get_unique_name TARG 'open.txt' +TARG="-$TARG" +echo "I am open." > $TARG +assert_file "$TARG" + +test_procedure + +assert_exit 0 xdg-open -- "$TARG" +assert_nostdout +assert_nostderr + +assert_interactive "Did a text editor open a file containing the string 'I am open.'?" y +assert_interactive "Please close any windows opened by this test." C + +test_result +} + +run_test test_open_option -- 1.7.1