-# emacs will hold open the directory it's started in, which
-# will prevent unmounting it.
-if [[ ! $1 ]]; then
- cd /
-fi
-
-if pgrep -u $EUID emacsclient && (( $# )); then
- emacsclient -a "" -n "$@"
-else
- emacsclient -a "" -nc "$@"
-fi
+
+g() {
+
+ local args gdb=false
+
+ if [[ $DISPLAY ]]; then
+ args=-n
+ fi
+
+ if (( $# == 0 )); then
+ args+=" -c"
+ fi
+ # duplicate -c, but oh well
+ if ! pgrep -u $EUID emacsclient &>/dev/null; then
+ if (( $# == 0 )) && type -p gdb &>/dev/null; then
+ gdb=true
+ else
+ args+=" -c"
+ fi
+ fi
+ if $gdb; then
+ # due to a bug, we cant debug from the start unless we get a new gdb
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=24454
+ # m gdb -ex="set follow-fork-mode child" -ex=r -ex=quit --args emacs --daemon
+ emacsclient -a "" $args "$@"
+ sleep 1
+ cd "/a/opt/emacs-$(distro-name)$(distro-num)"
+ sudo gdb -p "$(pgrep -f 'emacs --daemon')" -ex c
+ cd -
+ else
+ emacsclient -a "" $args "$@"
+ fi
+}
+
+g "$@"