Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. #!/bin/bash
  2. force_tty=false
  3. force_wait=false
  4. stdin_mode=""
  5. args=()
  6. while :; do
  7. case "$1" in
  8. -t | -nw | --tty)
  9. force_tty=true
  10. shift ;;
  11. -w | --wait)
  12. force_wait=true
  13. shift ;;
  14. -m | --mode)
  15. stdin_mode=" ($2-mode)"
  16. shift 2 ;;
  17. -h | --help)
  18. echo -e "\033[1mUsage: e [-t] [-m MODE] [OPTIONS] FILE [-]\033[0m
  19. Emacs client convenience wrapper.
  20. \033[1mOptions:\033[0m
  21. \033[0;34m-h, --help\033[0m Show this message
  22. \033[0;34m-t, -nw, --tty\033[0m Force terminal mode
  23. \033[0;34m-w, --wait\033[0m Don't supply \033[0;34m--no-wait\033[0m to graphical emacsclient
  24. \033[0;34m-\033[0m Take \033[0;33mstdin\033[0m (when last argument)
  25. \033[0;34m-m MODE, --mode MODE\033[0m Mode to open \033[0;33mstdin\033[0m with
  26. Run \033[0;32memacsclient --help\033[0m to see help for the emacsclient."
  27. exit 0 ;;
  28. --*=*)
  29. set -- "$@" "${1%%=*}" "${1#*=}"
  30. shift ;;
  31. *)
  32. if [ "$#" = 0 ]; then
  33. break; fi
  34. args+=("$1")
  35. shift ;;
  36. esac
  37. done
  38. if [ ! "${#args[*]}" = 0 ] && [ "${args[-1]}" = "-" ]; then
  39. unset 'args[-1]'
  40. TMP="$(mktemp /tmp/emacsstdin-XXX)"
  41. cat > "$TMP"
  42. args+=(--eval "(let ((b (generate-new-buffer \"*stdin*\"))) (switch-to-buffer b) (insert-file-contents \"$TMP\") (delete-file \"$TMP\")${stdin_mode})")
  43. fi
  44. if [ -z "$DISPLAY" ] || $force_tty; then
  45. if [ "$TERM" = "st-256color" ]; then
  46. TERM=xterm-256color emacsclient --tty -create-frame --alternate-editor="nvim" "${args[@]}"
  47. else
  48. emacsclient --tty -create-frame --alternate-editor="nvim" "${args[@]}"
  49. fi
  50. else
  51. if ! $force_wait; then
  52. args+=(--no-wait); fi
  53. emacsclient -create-frame --alternate-editor="nvim" "${args[@]}"
  54. fi