Skip to content

Instantly share code, notes, and snippets.

@vangberg
Forked from ahoward/gist:88505
Created April 1, 2009 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vangberg/88614 to your computer and use it in GitHub Desktop.
Save vangberg/88614 to your computer and use it in GitHub Desktop.
#! /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