-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compile & Execute Single File.tmCommand
131 lines (121 loc) · 3.75 KB
/
Compile & Execute Single File.tmCommand
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string>#!/usr/bin/env bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
#
# Compile a single file to a.out and execute the code in the frontmost Terminal
#
# Get some HTML niceties
. "${TM_SUPPORT_PATH}/lib/html.sh"
. "${TM_SUPPORT_PATH}/lib/webpreview.sh"
# Prepare output HTML in case the compilation fails
html_header "`basename "${TM_FORTRAN:-gfortran}"` compile"
# TIP (from Allan Odgaard)
# command1 &> >(command2)
# pipes the output of 'command1' to 'command2' but the status is still evaluated from 'command1'. Really cool.
# Pipe the output of the compiler to 'pre' which formats it nicely for HTML output
if cd "$TM_DIRECTORY" && "${TM_FORTRAN:-gfortran}" $TM_FFLAGS "`basename "$TM_FILEPATH"`" &> >(pre); then
# if compilation went well, execute the code in the frontmost Terminal
# TIP (from jacobolus): using -SOMETHING as entry point allows the end SOMETHING to be indented with the rest of the code
# TIP (from infinilight): use TM_TERMINAL to detect which terminal to run
TM_TERMINAL=`echo $TM_TERMINAL | tr "[:upper:]" "[:lower:]"`
echo $TM_TERMINAL
if [ "$TM_TERMINAL" == "iterm" ]; then
# iTerm code - simple and not necessarily robust
osascript <<-APPLESCRIPT
tell application "iTerm"
activate
if not (exists current terminal) then
set myterm to (make new terminal)
tell myterm
launch session "Default Session"
end tell
end if
tell current terminal
tell current session
write text "cd " & "$TM_DIRECTORY"
write text "./a.out"
end tell
end tell
end tell
tell application "TextMate"
activate
end tell
APPLESCRIPT
else
# Apple Terminal code - checks that a window exists and is not buzy
osascript <<-APPLESCRIPT
tell application "Terminal"
activate
set windowCount to (count of the windows)
if windowCount is greater than 0 then
repeat with w from 1 to windowCount
if window 1 is busy then
set frontmost of window 1 to false
else
do script "cd " & "$TM_DIRECTORY" in window 1
do script "./a.out" in window 1
set frontmost of window 1 to true
return
end if
end repeat
end if
tell window 1
do script "cd " & "$TM_DIRECTORY" & " && ./a.out"
set frontmost to true
end tell
end tell
tell application "TextMate"
activate
end tell
APPLESCRIPT
fi
exit_discard
else
# if compilation failed, show compiler's output in HTML preview
exit_show_html "<h2>Compilation failed</h2>"
fi
</string>
<key>input</key>
<string>none</string>
<key>inputFormat</key>
<string>text</string>
<key>keyEquivalent</key>
<string>@r</string>
<key>name</key>
<string>Compile & Execute Single File</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>text</string>
<key>outputLocation</key>
<string>discard</string>
<key>requiredCommands</key>
<array>
<dict>
<key>command</key>
<string>gfortran</string>
<key>locations</key>
<array>
<string>/opt/local/bin/gfortran</string>
<string>/usr/local/bin/gfortran</string>
</array>
<key>variable</key>
<string>TM_FORTRAN</string>
</dict>
</array>
<key>scope</key>
<string>source.fortran</string>
<key>semanticClass</key>
<string>process.build-and-run.fortran</string>
<key>uuid</key>
<string>EDD1628F-BB8C-4EC1-AFBD-90EC260F45B9</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>