Skip to content

Instantly share code, notes, and snippets.

@fletch
Last active August 29, 2015 14:24
Show Gist options
  • Save fletch/3d2cc18ba192ecb55c38 to your computer and use it in GitHub Desktop.
Save fletch/3d2cc18ba192ecb55c38 to your computer and use it in GitHub Desktop.
shell function sending messages to sauron using dbus
# -*- sh -*-
sauron () {
local opt_f=zsh opt_S=3 action=AddMsgEvent
local myname=${(%):-%N}
local -a extra_args
while getopts "S:f:u:" opt; do
if [[ $opt = "?" ]]; then
print -r -- "$myname: unrecognized option: -$OPTARG" >&2
return 1
fi
eval "opt_$opt=\${OPTARG:--\$opt}"
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
if [[ -n $opt_u ]] ; then
action=AddUrlEvent
extra_args=( "string:$opt_u" )
fi
dbus-send --session --dest="org.gnu.Emacs" \
--type=method_call "/org/gnu/Emacs/Sauron" \
"org.gnu.Emacs.Sauron.${action}" \
string:"$opt_f" uint32:${opt_S} string:"$*" "${extra_args[@]}"
}
sauron "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment