-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathge
executable file
·130 lines (117 loc) · 5.44 KB
/
ge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
# SH FILE: ge
#
# Purpose : Launch an independent, detached, GUI Emacs process. Supports macOS and Linux.
# Created : Tuesday, August 3 2021.
# Author : Pierre Rouleau <[email protected]>
# Time-stamp: <2024-08-01 11:21:03 EDT, updated by Pierre Rouleau>
# ----------------------------------------------------------------------------
# Description
# -----------
#
# Launch an independent GUI Emacs that is detached from the terminal shell
# executing the command. The current directory of the GUI Emacs process is
# set to the current directory of the terminal shell from which the 'ge'
# command was issued.
#
# ----------------------------------------------------------------------------
# Code
# ----
#
print_usage()
{
printf -- "\
ge : Open an independent, detached, graphical-mode instance of Emacs.
Usage: ge [-h|--help]
ge [FILE..]
Note: All command line arguments are passed to the Emacs application
unchanged. See Emacs man page for more options.
Emacs is launched inside an independent OS window, but
that process inherit the current directory.
Control is returned right away to the terminal shell.
"
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
print_usage
exit 0
fi
# Pass to emacs:
# - --chdir to the current working directory so we open the same files
# as what is specified on the command line. If we don't do that the GUI
# based Emacs might use a different directory (most often the home directory)
# and if you specify files that are not in that directory they
# will not be opened, another file file open which will most likely be
# in an empty buffer (if the file does not exists in the home directory).
#
# Emacs 27+ support for PEL:
# - To allow Emacs early-init.el code to distinguish whether Emacs is
# running in terminal mode or in graphics mode. When running
# early-init.el Emacs does not know and the function
# display-graphic-p does not work at that moment. The only way I
# have found is to use an environment variable. So the following
# code sets one up: PEL_EMACS_IN_GRAPHICS
# See: https://emacs.stackexchange.com/questions/66268/how-to-set-package-user-dir-with-emacs-27-with-package-quickstart-and-distinguis
#
case $(uname) in
Darwin)
if [ -d /Applications/Emacs.app/Contents ]; then
# Under macOS use the open application to launch the GUI Emacs application.
# -n : open a new instance on each invocation
# -a application: identify the path of the application
# --env : allows passing environment variable definitions to the launched application
#
# The macOS GUI build packs multiple binaries.
# The umbrella/dispatcher binary is: /Applications/Emacs.app/Contents/MacOS/Emacs
# There are other architecture specific binaries.
# Invoke them if they can be identified. The value of the arch variable is not set,
# so the `arch' command must be used.
case "$(arch)" in
arm64)
# Running on Apple Silicon: use the arm64 specific binary if present
if [ -x /Applications/Emacs.app/Contents/MacOS/Emacs-arm64-11 ]; then
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs-arm64-11 --env PEL_EMACS_IN_GRAPHICS=1 --args --chdir="$(pwd)" "$@"
else
# since it's likely an older macOS system where open did not have the --env option, don't use it.
export PEL_EMACS_IN_GRAPHICS=1
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs --args --chdir="$(pwd)" "$@"
fi
;;
*)
# Use the general dispatcher for all others
# It will check what version of macOS and use the appropriate one.
# since it's likely an older macOS system where open did not have the --env option, don't use it.
export PEL_EMACS_IN_GRAPHICS=1
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs --args --chdir="$(pwd)" "$@"
;;
esac
else
echo "*** ge: ERROR ***"
echo "The required /Applications/Emacs.app is missing."
echo "Please install Emacs from https://emacsformacosx.com/ "
echo "*****************"
exit 1
fi
;;
Linux)
# Under Linux, invoke emacs passing the current working directory
# setting the PEL_EMACS_IN_GRAPHICS environment variable to inform
# PEL about the graphics mode and ensure it runs detached.
export PEL_EMACS_IN_GRAPHICS=1
# On some Linux distros, emacs-lucid is the X-Windows capable
# GUI version of Emacs. If available use it.
# At this point I don't see a reason to provide an overriding
# mechanism using an environment variable.
# If someone sees one please let me know.
if which emacs-lucid > /dev/null ; then
emacs-lucid --chdir="$(pwd)" "$@" &
else
emacs --chdir="$(pwd)" "$@" &
fi
;;
*)
echo "Sorry, the $(uname) Operating System is not supported yet."
echo "Please create a bug report in the PEL project to request it."
exit 1
;;
esac
# ----------------------------------------------------------------------------