โค้ดแก้ไข C Bundle ใน Textmate
June 15th, 2007 Posted in Programmingตอนนี้ต้องใช้ Textmate ในการเรียน C++ Programming
แต่มีปัญหาว่า Textmate เจ้ากรรมนั้น ไม่สามารถที่จะ Compile และ Run ไฟล์เดียวโดดๆ ได้
เพราะว่าเวลามันจะ Build มันจะต้องสร้างโปรเจค X Code ก่อน
สองวันมานี้ ก็เลยลองแก้ Bundle ดูเรื่อยๆ
ใช้ร่วมกันระหว่าง Ruby กับ AppleScript
แล้วก็ เปิด Google จนตาลายเลย ..
จนได้ออกมา อย่างนี้ !
Compile Single File to Tool
#!/usr/bin/env ruby## Compile the active file to an executable.# Executable name is prefixed with "Test".
require 'English'
FilePath = ENV['TM_FILEPATH']FileDir = ENV['TM_DIRECTORY']FileBaseName = File.basename(FilePath)FileExtension = File.extname(FilePath)FileNoExtension = FileBaseName.sub(/#{FileExtension}$/, "")
Dir.chdir(ENV['TM_DIRECTORY'])
# have to use g++ to bring in C++ runtime librariescc = case FileExtensionwhen /\.c(pp?|xx|\+\+)/,'.C','.ii' 'g++'else 'gcc'end
puts "<pre>"%x{ "#{cc}" -g -Wmost -Os -o "#{FileNoExtension}" "$TM_FILEPATH"}puts "</pre>"
puts "<font color='#499914'>Successfully created #{FileNoExtension}</font>" unless $CHILD_STATUS != 0
(อาจจะแก้ไขอีกนิด เพราะอยากให้มันแสดงหน้าจอ Build สวยๆ หน่อย)
Run Single File in Terminal Window
#!/usr/bin/env ruby## Compile the active file to an executable.# Executable name is prefixed with "Test".
require 'English'
FilePath = ENV['TM_FILEPATH']FileDir = ENV['TM_DIRECTORY']FileBaseName = File.basename(FilePath)FileExtension = File.extname(FilePath)FileNoExtension = FileBaseName.sub(/#{FileExtension}$/, "")
puts %x{ osascript <<EOF tell application "Terminal" activate do script "cd '#{FileDir}'; clear; echo 'Running #{FileNoExtension} ...'; echo ; ./#{FileNoExtension} ; echo ; read -p 'Please return to exit ..'; exit" end tellEOF }
ดูๆ แล่้วก็เวิร์คดีเหมือนกันแฮะ
Tags: C++, Ruby, Textmate