Skip to content

Instantly share code, notes, and snippets.

@LazyRen

LazyRen/cpp_cmd.sh

Created Aug 23, 2018
Embed
What would you like to do?
mac sublime-text c++ build&execute shell script
#!/bin/sh
osascript -e '
on run parameters
set TID to text item delimiters
set text item delimiters to " "
set myfile to parameters as text
set text item delimiters to TID
tell application "Finder"
set fileName to name of (POSIX file myfile as alias)
set filePath to do shell script ("dirname " & quoted form of myfile)
end tell
set fileBaseName to text 1 thru ((offset of "." in fileName) - 1) of fileName
tell application "System Events"
if not (exists (processes where name is "Terminal")) then
tell application "Terminal"
activate
do script ("cd " & quoted form of filePath & "; clear") in first window
delay 0.1
do script ("./" & fileBaseName & ".out") in first window
end tell
else
tell application "Terminal"
activate
delay 0.1
tell application "System Events" to tell process "Terminal.app" to keystroke "n" using command down
delay 0.1
do script ("cd " & quoted form of filePath & "; clear") in selected tab of the front window
delay 0.1
do script ("./" & fileBaseName & ".out") in first window
end tell
end if
end tell
end run
' $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.