[kupfer: 3/4] kupfer-activate.sh: Rewrite to allow reading stdin input



commit f5bafe7961be0fc5a7549b2715af070ad21d7916
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Nov 2 01:16:30 2009 +0100

    kupfer-activate.sh: Rewrite to allow reading stdin input
    
    Write kupfer-activate.sh in a bit clearer style. We now read stdin, if
    we detect that we are not connected to a terminal, and the stdin text
    is posted to kupfer with PutText.

 kupfer-activate.sh |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/kupfer-activate.sh b/kupfer-activate.sh
index bf398ad..3fe99a7 100755
--- a/kupfer-activate.sh
+++ b/kupfer-activate.sh
@@ -6,15 +6,33 @@ test ${PYTHON:0:1} = "@" && PYTHON=python
 # Try to spawn kupfer via dbus, else go to python
 
 # Figure out if there are any options "--help" etc, then launch kupfer
-# If there are any non-option arguments, send them to kupfer with PutText
 test "x${1:0:2}" = "x--"
 KUPFER_HAS_OPTIONS=$?
-test -n "$*"
-KUPFER_HAS_CLIARGS=$?
+
+# If there are any non-option arguments, send them to kupfer with PutText
+# Grab text input either from command line or from stdin
+if tty --quiet
+then
+	TEXT_INPUT="$*"
+else
+	echo "kupfer: Reading from stdin"
+	TEXT_INPUT=$(cat)
+fi
+
 
 test $KUPFER_HAS_OPTIONS != 0 && dbus-send --print-reply --dest=se.kaizer.kupfer /interface se.kaizer.kupfer.Listener.Present >/dev/null 2>&1
 KUPFER_RUNNING=$?
 
-test \( $KUPFER_HAS_CLIARGS = 0 -a $KUPFER_HAS_OPTIONS != 0 \) && dbus-send --print-reply --dest=se.kaizer.kupfer /interface se.kaizer.kupfer.Listener.PutText string:"$PWD" string:"$*" >/dev/null 2>&1
+if test \( -n "$TEXT_INPUT" -a $KUPFER_HAS_OPTIONS != 0 \)
+then
+	dbus-send --print-reply --dest=se.kaizer.kupfer /interface \
+	se.kaizer.kupfer.Listener.PutText string:"$PWD" string:"$TEXT_INPUT" \
+	>/dev/null 2>&1
+fi
+
+if test $KUPFER_RUNNING != 0
+then
+	exec ${PYTHON} -m kupfer.__init__ $*
+fi
 
-test $KUPFER_RUNNING != 0 && exec ${PYTHON} -m kupfer.__init__ $* || ${PYTHON} -c "import gtk.gdk; gtk.gdk.notify_startup_complete()"
+${PYTHON} -c "import gtk.gdk; gtk.gdk.notify_startup_complete()"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]