-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-emacs-shortcut
162 lines (145 loc) · 4.3 KB
/
make-emacs-shortcut
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Adapted by Ken Brown from Chuck Wilson's config-run2-example.sh in
# the run2 package.
CYGUTILS_VER_REQD=1.4.2
CYGUTILS_VER_INST=$(cygcheck -cd cygutils | grep cygutils | awk '{print $2}')
XMLFILE=/usr/local/bin/emacs.xml
_version_parse_pkg_major=
_version_parse_pkg_minor=
_version_parse_pkg_micro=
# ======================================================================
# Routine: version_parse
# safely parses a version string of the form x.y.z into three
# separate values.
# ======================================================================
version_parse () {
local pkg_version="$1"
# remove any non-digit characters from the version numbers to permit numeric
_version_parse_pkg_major=`echo $pkg_version | cut -d. -f1 | sed s/[a-zA-Z\-].*//g`
_version_parse_pkg_minor=`echo $pkg_version | cut -d. -f2 | sed s/[a-zA-Z\-].*//g`
_version_parse_pkg_micro=`echo $pkg_version | cut -d. -f3 | sed s/[a-zA-Z\-].*//g`
test -z "$_version_parse_pkg_major" && _version_parse_pkg_major=0
test -z "$_version_parse_pkg_minor" && _version_parse_pkg_minor=0
test -z "$_version_parse_pkg_micro" && _version_parse_pkg_micro=0
}
readonly -f version_parse
# ======================================================================
# Routine: version_ge
# Compares two version strings: $1 ad $2 should both be version
# strings of the form x.y.z
# returns true if $1 >= $2, when compared as normal version strings
# returns false otherwise
# ======================================================================
version_ge() {
local lh_pkg_version="$1"
local rh_pkg_version="$2"
local lh_pkg_major
local lh_pkg_minor
local lh_pkg_micro
local rh_pkg_major
local rh_pkg_minor
local rh_pkg_micro
version_parse "$lh_pkg_version"
lh_pkg_major=$_version_parse_pkg_major
lh_pkg_minor=$_version_parse_pkg_minor
lh_pkg_micro=$_version_parse_pkg_micro
version_parse "$rh_pkg_version"
rh_pkg_major=$_version_parse_pkg_major
rh_pkg_minor=$_version_parse_pkg_minor
rh_pkg_micro=$_version_parse_pkg_micro
if [ $lh_pkg_major -gt $rh_pkg_major ]
then
return 0
elif [ $lh_pkg_major -eq $rh_pkg_major ]
then
if [ $lh_pkg_minor -gt $rh_pkg_minor ]
then
return 0
elif [ $lh_pkg_minor -eq $rh_pkg_minor ]
then
if [ $lh_pkg_micro -ge $rh_pkg_micro ]
then
return 0
fi
fi
fi
return 1
} # === End of version_ge() === #
readonly -f version_ge
errorMsg ()
{
local errorcode=$?
if ((errorcode == 0))
then
errorcode=1
fi
echo -e "\e[1;31m*** ERROR:\e[0;0m ${1:-no error message provided}"
exit ${errorcode};
}
warnMsg()
{
echo -e "\e[1;33m*** Warning:\e[0;0m ${1}"
}
infoMsg()
{
echo -e "\e[1;32m*** Info:\e[0;0m ${1}"
}
readonly -f errorMsg warnMsg infoMsg
if version_ge "$CYGUTILS_VER_INST" "$CYGUTILS_VER_REQD"
then
:
else
msg="This script requires cygutils-$CYGUTILS_VER_REQD or better."
if cygcheck -cd cygutils | grep cygutils >/dev/null
then
msg="$msg You have $CYGUTILS_VER_INST.\n"
else
msg="$msg You don't have cygutils installed.\n"
fi
errorMsg "$msg"
fi
if [ -e $XMLFILE ]
then
mv $XMLFILE $XMLFILE.bak
bn=${XMLFILE##*/}
infoMsg "Moved existing file $XMLFILE to ${bn}.bak."
fi
cat >${XMLFILE} <<"EOF"
<?xml version="1.0" encoding="us-ascii"?>
<!-- This file was created by the script /usr/bin/make-emacs-shortcut. -->
<!-- See /usr/share/doc/emacs/README.Cygwin for more information. -->
<Run2Config
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="run2.xsd">
<SelfOptions />
<Global>
<Environment />
</Global>
<GDI>
<Environment />
<Target filename="/usr/bin/bash.exe" startin="~">
<Arg>-l</Arg>
<Arg>-c /usr/bin/emacs-w32.exe</Arg>
</Target>
</GDI>
<X11>
<Environment>
<Set var="DISPLAY" value="127.0.0.1:0.0"/>
</Environment>
<Target filename="/usr/bin/bash.exe" startin="~">
<Arg>-l</Arg>
<Arg>-c emacs</Arg>
</Target>
</X11>
</Run2Config>
EOF
infoMsg "Created ${XMLFILE}."
mkshortcut --desc="Emacs" \
--icon="/usr/bin/emacs.ico" \
--arguments="--display 127.0.0.1:0.0 ${XMLFILE}" \
--name="emacs" \
/usr/bin/run2.exe
infoMsg "Created ${PWD}/emacs.lnk."
infoMsg "You should move it to the desired location."
infoMsg "Feel free to edit its properties"
infoMsg "or the contents of ${XMLFILE}."