]> git.wincent.com - wincent.git/commitdiff
Bash: add "ts" script
authorWincent Colaiuta <win@wincent.com>
Thu, 21 May 2009 18:20:48 +0000 (20:20 +0200)
committerWincent Colaiuta <win@wincent.com>
Thu, 21 May 2009 18:20:48 +0000 (20:20 +0200)
This script can be used from within Bash to apply custom Terminal styles
on the fly. See .bash_profile for an example which changes the style
upon connecting to a particular remote host (the inet() function).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
bin/ts [new file with mode: 0755]

diff --git a/bin/ts b/bin/ts
new file mode 100755 (executable)
index 0000000..57eec4c
--- /dev/null
+++ b/bin/ts
@@ -0,0 +1,35 @@
+#!/usr/bin/osascript
+# Copyright 2007 Tim Wood
+# Copyrght 2008 Wincent Colaiuta
+#
+# Based on snippet published at:
+# http://blog.omnigroup.com/2007/11/03/terminal-scripting-in-105/
+
+on run (set_name)
+       set tty_id to do shell script "tty"
+       set tab_id to tab_for_tty(tty_id)
+       if tab_id is missing value then
+               return "error: failed to get tab"
+       else
+               tell application "Terminal"
+                       try
+                               set set_id to settings set named set_name
+                       on error
+                               return "error: failed to get settings set"
+                       end try
+                       set current settings of tab_id to set_id
+               end tell
+       end if
+end run
+
+on tab_for_tty(tty_id)
+       tell application "Terminal"
+               repeat with win_id in windows
+                       repeat with tab_id in tabs of win_id
+                               if tty of tab_id is tty_id then
+                                       return tab_id
+                               end if
+                       end repeat
+               end repeat
+       end tell
+end tab_for_tty