aboutsummaryrefslogtreecommitdiffstats
path: root/LICENSE.MIT
blob: a6919eb7e1fdbda5d53fd9d8e0f7114f2274457b (plain)
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
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Note:
Individual files contain the following tag instead of the full license text.

    SPDX-License-Identifier: MIT

This enables machine processing of license information based on the SPDX
License Identifiers that are here available: http://spdx.org/licenses/
/ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/bin/bash

if [ "x" = "x${DBUS_SESSION_BUS_ADDRESS}" ]; then
	DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
fi
export DBUS_SESSION_BUS_ADDRESS

pretty() {
	sed '	/^method return .*/d
		s/^Error org.freedesktop.DBus.Error.Failed: "\?\(.*\)"\?$/ERROR: \1/
		s/^   string "\(.*\)"/\1/
		s:[[{,]:&\n:g
		s: *[]}]:\n&:g
	' |
	sed '	s:^ *::
		s: *$::
		/[]}],*$/ {x;s:...::;x}
		G
		/[[{]\n/ {x;s:$:   :;x}
		s:^\(.*[^\n]\)\n\( *\)$:\2\1:
	'
}

send() {
	dbus-send --session --print-reply \
		--dest=org.AGL.afm.user \
		/org/AGL/afm/user \
		org.AGL.afm.user.$1 \
		"string:$2" |
	pretty
	return ${PIPESTATUS[0]}
}

case "$1" in

  list|runnables)
    send runnables true
    ;;

  add|install)
    f=$(realpath $2)
    send install '{"wgt":"'"$f"'","force":true}'
    ;;

  remove|uninstall)
    i=$2
    send uninstall "\"$i\""
    ;;

  info|detail)
    i=$2
    send detail "\"$i\""
    ;;

  ps|runners)
    send runners true
    ;;

  run|start)
    i=$2
    send start "\"$i\""
    ;;

  run-remote|start-remote)
    i=$2
    send start '{"id":"'"$i"'","mode":"remote"}'
    ;;

  once)
    i=$2
    send once "\"$i\""
    ;;

  terminate|kill)
    i=$2
    send terminate "$i"
    ;;

  stop|pause)
    i=$2
    send pause "$i"
    ;;

  resume|continue)
    i=$2
    send resume "$i"
    ;;

  state|status)
    i=$2
    send state "$i"
    ;;

  -h|--help|help)
    cat << EOC
usage: $(basename $0) command [arg]

The commands are:

  list
  runnables      list the runnable widgets installed

  add wgt
  install wgt    install the wgt file

  remove id
  uninstall id   remove the installed widget of id

  info id
  detail id      print detail about the installed widget of id

  ps
  runners        list the running instance

  run id
  start id       start an instance of the widget of id

  once id        run once an instance of the widget of id

  kill rid
  terminate rid  terminate the running instance rid

  stop rid
  pause rid      pause the running instance rid

  resume rid
  continue rid   continue the previously paused rid

  status rid
  state rid      get status of the running instance rid

EOC
    ;;

  *)
    echo "unknown command $1" >&2
    exit 1
    ;;
esac