Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created December 9, 2015 21:58
Show Gist options
  • Select an option

  • Save ahoward/97d0ddc47f7626b8d1e6 to your computer and use it in GitHub Desktop.

Select an option

Save ahoward/97d0ddc47f7626b8d1e6 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# this program (on osx and probably others) 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 ~/src/foobar
#
# to detach use the standard
#
# Ctrl-A d
#
# to attache to a previously named screen use
#
# ns ~/src/foobar
#
# in both cases (creation and attaching) your terminal tab will get named
# appropriately
#
# the default argument is '.' do
#
# cd ~/src/foobar
# ns
#
# works to create a screen named 'foobar' too
#
system("#{ ScreenProgram } -wipe")
exec(Screen)
#
BEGIN {
require 'fileutils'
require 'tmpdir'
Home = File.expand_path('~')
Name = File.basename(File.expand_path(ARGV.shift || '.')).gsub(%r/\W/,'_').squeeze('_').chomp('_')
Fu = FileUtils
Screens = File.join(Home, '.screens')
ScreenProgram = `which screen`.strip
Screen = File.join(Screens, Name)
Current = ENV['Screen']
FileUtils.mkdir_p(Screens)
script = <<-__.strip
#! /usr/bin/env bash
screen -d -R -S #{ Name.inspect }
__
IO.binwrite(Screen, script)
FileUtils.chmod(0777, Screen)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment