Skip to content

Instantly share code, notes, and snippets.

@s7dhansh

s7dhansh/ed.sh Secret

Created May 1, 2011 12:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s7dhansh/a664a61a49296da16e47 to your computer and use it in GitHub Desktop.
Save s7dhansh/a664a61a49296da16e47 to your computer and use it in GitHub Desktop.
Tackle glib-gio errors while firing an app from command line. Usage: ed.sh <command>
#!/bin/bash
exportDbus () {
# Get the pid of nautilus
nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
# If nautilus isn't running, just exit silently
if [ -z "$nautilus_pid" ]; then
exit 0
fi
# Grab the DBUS_SESSION_BUS_ADDRESS variable from nautilus's environment
eval $(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')
# Check that we actually found it
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
echo "Failed to find bus address" >&2
exit 1
fi
# export it so that child processes will inherit it
export DBUS_SESSION_BUS_ADDRESS
}
exportDbus
$@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment