-
-
Save vangberg/88614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# this program will give you a 'named screen' (ns) command that will create | |
# named screens that will also name Terminal.app tabs, even on re-attach. | |
# save it in ~/bin/ns and use as in | |
# | |
# to create a named screen | |
# | |
# ns foobar | |
# | |
# to detach use the standard | |
# | |
# Ctrl-A d | |
# | |
# to attache to a previously named screen use | |
# | |
# ns foobar | |
# | |
# in both cases (creation and attaching) your terminal tab will get named | |
# appropriately | |
# | |
detach = "#{ Screen } -d #{ ENV['Screen'] }" if ENV['Screen'] | |
wipe = "#{ Screen } -wipe" | |
env = "Screen=#{ Name }" | |
attach = "#{ Screen } -d -r #{ Name}" | |
new = "#{ env } #{ Screen } -S #{ Name }" | |
command = "#{ wipe }; #{ attach } || #{ new }" | |
exec command | |
BEGIN { | |
require 'fileutils' | |
require 'tmpdir' | |
def home | |
home = | |
catch :home do | |
["HOME", "USERPROFILE"].each do |key| | |
throw(:home, ENV[key]) if ENV[key] | |
end | |
if ENV["HOMEDRIVE"] and ENV["HOMEPATH"] | |
throw(:home, "#{ ENV['HOMEDRIVE'] }:#{ ENV['HOMEPATH'] }") | |
end | |
File.expand_path("~") rescue(File::ALT_SEPARATOR ? "C:/" : "/") | |
end | |
File.expand_path home | |
end | |
Name = File.basename(ARGV.shift || 'ns') | |
Fu = FileUtils | |
Screens = File.join(home, '.screens') | |
ScreenProgram = `which screen`.strip | |
Screen = File.join(Screens, Name) | |
Current = ENV['Screen'] | |
begin | |
FileUtils.ln(ScreenProgram, Screen) | |
rescue Errno::EEXIST | |
raise unless test(?e, Screen) | |
end | |
Fu.mkdir_p Screens | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment