This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkupfer.in
executable file
·93 lines (79 loc) · 2.64 KB
/
kupfer.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
# kupfer A convenient command and access tool
#
# Copyright 2007--2010 Ulrik Sverdrup <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script invokes kupfer by calling an already running instance, or
# starting a new if none is found running.
_hasprefix () {
test "x${1#$2}" != "x$1"
}
PYTHON="@PYTHON@"
PYTHONDIR="@PYTHONDIR@"
_hasprefix "$PYTHON" "@" && PYTHON=python
_hasprefix "$PYTHONDIR" "@" && PYTHONDIR=$(dirname $(readlink -f -- $0))/..
SERVICE="se.kaizer.kupfer"
OBJ="/interface"
IFACE="se.kaizer.kupfer.Listener"
# We allow reading directly from stdin if we pipe text into Kupfer
if ! tty --quiet
then
echo "kupfer: Reading from stdin" >&2
TEXT_INPUT=$(cat)
fi
# If there are any options, like "--help", we run Kupfer directly
_hasprefix "$1" "--"
KUPFER_HAS_OPTIONS=$?
test $KUPFER_HAS_OPTIONS != 0 && dbus-send --type=method_call --print-reply \
--dest=$SERVICE $OBJ $IFACE.PresentOnDisplay string:"$DISPLAY" \
"string:$DESKTOP_STARTUP_ID" >/dev/null 2>&1
KUPFER_RUNNING=$?
if test \( -n "$TEXT_INPUT" -a $KUPFER_HAS_OPTIONS != 0 \)
then
dbus-send --type=method_call --dest=$SERVICE $OBJ \
$IFACE.PutTextOnDisplay string:"$TEXT_INPUT" \
string:"$DISPLAY" string:"$DESKTOP_STARTUP_ID"
fi
_realpaths () {
# Emit realpaths for arguments, separated by NUL bytes
while test $# != 0
do
LINK=$(readlink -e -- "$1")
if test $? != 0 ; then
echo "Error: $1 does not exist" >&2
shift
continue
fi
printf "%s\0" "$LINK"
shift
done
}
if test \( -n "$1" -a $KUPFER_HAS_OPTIONS != 0 \)
then
# NOTE: We must escape commas here since it is dbus-send's
# array item separator. This is then unescaped by kupfer
ARRAY=$(_realpaths "$@" | sed -e 's/,/%%kupfercomma%%/g' | tr \\0 ,)
dbus-send --type=method_call --dest=$SERVICE $OBJ \
$IFACE.PutFilesOnDisplay array:string:"$ARRAY" \
string:"$DISPLAY" string:"$DESKTOP_STARTUP_ID"
fi
if test $KUPFER_RUNNING != 0
then
exec ${PYTHON} "$PYTHONDIR/kupfer.py" $*
fi
if test -n "$DESKTOP_STARTUP_ID"
then
${PYTHON} -c "import gtk.gdk; gtk.gdk.notify_startup_complete()"
fi