em 936 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. if [ "$1" = "-h" ]; then
  3. cat <<EOF>&2
  4. Usage: ${0##*/} [OPTIONS] [FILES]
  5. Start emacsclient in terminal or in X window if possible. Server is started on
  6. demand.
  7. The calling script can have different names:
  8. - emc: the Emacs instance is opened in the current terminal.
  9. - emw: if graphical, tell the client to wait.
  10. All emacsclient(1) options are supported:
  11. $(emacsclient --help)
  12. EOF
  13. exit
  14. fi
  15. if [ "${0##*/}" = "emc" ]; then
  16. ## Force terminal mode
  17. param="-t"
  18. else
  19. ## If Emacs cannot start in graphical mode, -c will act just like -t.
  20. param="-c"
  21. if [ "${0##*/}" != "emw" ] && [ -n "$DISPLAY" ] && [ "$(emacs --batch -Q --eval='(message (if (fboundp '"'"'tool-bar-mode) "X" "TTY"))' 2>&1)" = X ]; then
  22. ## Don't wait if not called with "emw" and if Emacs can start in graphical mode.
  23. ## The Emacs batch test checks whether it was compiled with GUI suppport.
  24. param="$param -n"
  25. fi
  26. fi
  27. emacsclient $param -a "" "$@"