X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=g;h=d559b8a80fa4e1104a3a45ad652bd0d7bc57abf7;hb=ca61084446e48fb0703ce2a203c1bd18ceaf4dfb;hp=199b8ade6d4fe0d29eb9ca4ab28492b344d15561;hpb=989554cab0d0c59d1aab20496ba9550acd17e6e6;p=distro-setup diff --git a/g b/g index 199b8ad..d559b8a 100755 --- a/g +++ b/g @@ -36,14 +36,38 @@ # -a = alternate editor, empty string makes it start emacs daemon. # This is also set via env variable, but that doesn't propagate everywhere. -# 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 "$@"