utils 0.0.69 → 0.0.70

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # vim: set filetype=ruby et sw=2 ts=2:
2
2
 
3
- source :rubygems
3
+ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.69
1
+ 0.0.70
data/bin/ssh-tunnel ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ include FileUtils::Verbose
5
+ require 'tins/go'
6
+ include Tins::GO
7
+ require 'utils'
8
+
9
+ SSH_CONFIG = <<SSH_CONFIG_END
10
+ # ~/.ssh/config
11
+
12
+ Host *
13
+ ForwardX11 = yes
14
+ ControlMaster auto
15
+ ControlPath ~/.ssh/%r@%h:%p.sock
16
+ SSH_CONFIG_END
17
+
18
+ def usage
19
+ puts <<EOT
20
+ Usage: #{File.basename($0)} [OPTS] [user@]remote[:port]"
21
+
22
+ OPTS is one of
23
+ -N list all session names on the specified remote
24
+ -n NAME name of the multplexer session to attach to (defaults to $USER)
25
+ -t [HOST[:PORT]] host:port to tunnel if different from LOCALPORT
26
+ -l LOCALPORT the localport to forward to
27
+ -C (ssh|rc)-default|rc output ssh or rc config file
28
+ -h to display this help
29
+
30
+ EOT
31
+ exit 1
32
+ end
33
+
34
+ config = Utils::Config::ConfigFile.new
35
+
36
+ arguments = ARGV
37
+ opts = go 'l:t:n:C:hN', arguments
38
+
39
+ case opts['C']
40
+ when 'ssh-default'
41
+ puts SSH_CONFIG; exit
42
+ when 'rc-default'
43
+ puts config.to_ruby; exit
44
+ when 'rc'
45
+ config.configure_from_paths
46
+ puts config.to_ruby; exit
47
+ end
48
+
49
+ config.configure_from_paths
50
+
51
+ usage if opts['h'] or arguments.size != 1
52
+
53
+ user_remote = arguments.shift
54
+ user, remote, rport =
55
+ case user_remote
56
+ when /\A(?:([^@:]+)@)?([^@:]+)(?::(\d+))?\Z/
57
+ user = $1 || ENV['USER']
58
+ user.to_s.empty? and fail "user required to login"
59
+ [ user, $2, $3 || '22' ]
60
+ else
61
+ usage
62
+ end
63
+ lport = opts['l']
64
+ tunnel, tport = nil, nil
65
+ if tunnel_port = opts['t']
66
+ case tunnel_port
67
+ when /\A([^:]+)(?::(\d+))?\Z/
68
+ tunnel, tport = $1, $2 || '22'
69
+ lport ||= tport
70
+ else
71
+ usage
72
+ end
73
+ else
74
+ tunnel, tport = 'localhost', lport
75
+ end
76
+
77
+ ssh_dir = File.expand_path('~/.ssh')
78
+ mkdir_p ssh_dir
79
+ sock_file = "#{ssh_dir}/#{user}@#{remote}:#{rport}.sock"
80
+ env_user = ENV['USER'] and opts['n'] ||= env_user
81
+ if opts['N']
82
+ exec "ssh -p #{rport} -S #{sock_file} #{user}@#{remote} #{config.ssh_tunnel.multiplexer_list}"
83
+ elsif lport
84
+ rm_f sock_file
85
+ exec "ssh -p #{rport} -Mt -L localhost:#{lport}:#{tunnel}:#{tport}"\
86
+ " -S #{sock_file} #{user}@#{remote} #{config.ssh_tunnel.multiplexer_attach} #{opts['n']}"
87
+ else
88
+ File.exist? sock_file and rm_f sock_file
89
+ exec "ssh -p #{rport} -Mt -S #{sock_file} #{user}@#{remote} #{config.ssh_tunnel.multiplexer_attach} #{opts['n']}"
90
+ end
@@ -148,9 +148,39 @@ class Utils::Config::ConfigFile
148
148
  @strip_spaces ||= StripSpaces.new
149
149
  end
150
150
 
151
+ class SshTunnel < BlockConfig
152
+ config :terminal_multiplexer, 'sshscreen'
153
+
154
+ def initialize
155
+ super
156
+ @multiplexer =
157
+ case terminal_multiplexer.to_s
158
+ when 'sshscreen'
159
+ @multiplexer_list = 'screen -ls'
160
+ @multiplexer_attach = 'screen -DUR'
161
+ when 'tmux'
162
+ @multiplexer_list = 'tmux ls'
163
+ @multiplexer_attach = 'tmux attach'
164
+ else
165
+ fail "invalid terminal_multiplexer #{terminal_multiplexer.inspect} was configured"
166
+ end
167
+ end
168
+
169
+ attr_reader :multiplexer_list
170
+
171
+ attr_reader :multiplexer_attach
172
+ end
173
+
174
+ def ssh_tunnel(&block)
175
+ if block
176
+ @ssh_tunnel = SshTunnel.new(&block)
177
+ end
178
+ @ssh_tunnel ||= SshTunnel.new
179
+ end
180
+
151
181
  def to_ruby
152
182
  result = "# vim: set ft=ruby:\n"
153
- for bc in %w[search discover strip_spaces probe]
183
+ for bc in %w[search discover strip_spaces probe ssh_tunnel]
154
184
  result << "\n" << __send__(bc).to_ruby
155
185
  end
156
186
  result
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.0.69'
3
+ VERSION = '0.0.70'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "utils"
5
- s.version = "0.0.69"
5
+ s.version = "0.0.70"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Florian Frank"]
9
- s.date = "2012-12-14"
9
+ s.date = "2013-02-26"
10
10
  s.description = "This ruby gem provides some useful command line utilities"
11
11
  s.email = "flori@ping.de"
12
- s.executables = ["chroot-exec", "chroot-libs", "classify", "create_tags", "discover", "edit", "edit_wait", "enum", "errf", "git-empty", "irb_connect", "myex", "number_files", "on_change", "path", "probe", "same_files", "search", "sedit", "sshscreen", "strip_spaces", "unquarantine_apps", "untest", "utils-install-config", "utils-utilsrc", "vacuum_firefox_sqlite", "xmp"]
12
+ s.executables = ["create_tags", "untest", "chroot-libs", "edit_wait", "chroot-exec", "irb_connect", "number_files", "search", "strip_spaces", "path", "enum", "edit", "git-empty", "classify", "utils-install-config", "xmp", "discover", "ssh-tunnel", "myex", "probe", "errf", "same_files", "utils-utilsrc", "unquarantine_apps", "vacuum_firefox_sqlite", "on_change", "sedit"]
13
13
  s.extra_rdoc_files = ["README.rdoc", "lib/utils.rb", "lib/utils/config.rb", "lib/utils/config/config_file.rb", "lib/utils/editor.rb", "lib/utils/file_xt.rb", "lib/utils/finder.rb", "lib/utils/grepper.rb", "lib/utils/irb.rb", "lib/utils/md5.rb", "lib/utils/patterns.rb", "lib/utils/version.rb"]
14
- s.files = [".gitignore", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "TODO", "VERSION", "bin/chroot-exec", "bin/chroot-libs", "bin/classify", "bin/create_tags", "bin/discover", "bin/edit", "bin/edit_wait", "bin/enum", "bin/errf", "bin/git-empty", "bin/irb_connect", "bin/myex", "bin/number_files", "bin/on_change", "bin/path", "bin/probe", "bin/same_files", "bin/search", "bin/sedit", "bin/sshscreen", "bin/strip_spaces", "bin/unquarantine_apps", "bin/untest", "bin/utils-install-config", "bin/utils-utilsrc", "bin/vacuum_firefox_sqlite", "bin/xmp", "lib/utils.rb", "lib/utils/config.rb", "lib/utils/config/config_file.rb", "lib/utils/config/gdb/asm", "lib/utils/config/gdb/ruby", "lib/utils/config/gdbinit", "lib/utils/config/irbrc", "lib/utils/config/rdebugrc", "lib/utils/config/rvmrc", "lib/utils/config/screenrc", "lib/utils/config/utilsrc", "lib/utils/editor.rb", "lib/utils/file_xt.rb", "lib/utils/finder.rb", "lib/utils/grepper.rb", "lib/utils/irb.rb", "lib/utils/md5.rb", "lib/utils/patterns.rb", "lib/utils/version.rb", "utils.gemspec"]
14
+ s.files = [".gitignore", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "TODO", "VERSION", "bin/chroot-exec", "bin/chroot-libs", "bin/classify", "bin/create_tags", "bin/discover", "bin/edit", "bin/edit_wait", "bin/enum", "bin/errf", "bin/git-empty", "bin/irb_connect", "bin/myex", "bin/number_files", "bin/on_change", "bin/path", "bin/probe", "bin/same_files", "bin/search", "bin/sedit", "bin/ssh-tunnel", "bin/strip_spaces", "bin/unquarantine_apps", "bin/untest", "bin/utils-install-config", "bin/utils-utilsrc", "bin/vacuum_firefox_sqlite", "bin/xmp", "lib/utils.rb", "lib/utils/config.rb", "lib/utils/config/config_file.rb", "lib/utils/config/gdb/asm", "lib/utils/config/gdb/ruby", "lib/utils/config/gdbinit", "lib/utils/config/irbrc", "lib/utils/config/rdebugrc", "lib/utils/config/rvmrc", "lib/utils/config/screenrc", "lib/utils/config/utilsrc", "lib/utils/editor.rb", "lib/utils/file_xt.rb", "lib/utils/finder.rb", "lib/utils/grepper.rb", "lib/utils/irb.rb", "lib/utils/md5.rb", "lib/utils/patterns.rb", "lib/utils/version.rb", "utils.gemspec"]
15
15
  s.homepage = "http://github.com/flori/utils"
16
16
  s.rdoc_options = ["--title", "Utils - Some useful command line utilities", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
18
- s.rubygems_version = "1.8.24"
18
+ s.rubygems_version = "1.8.25"
19
19
  s.summary = "Some useful command line utilities"
20
20
 
21
21
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.69
4
+ version: 0.0.70
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gem_hadar
@@ -94,33 +94,33 @@ dependencies:
94
94
  description: This ruby gem provides some useful command line utilities
95
95
  email: flori@ping.de
96
96
  executables:
97
- - chroot-exec
98
- - chroot-libs
99
- - classify
100
97
  - create_tags
101
- - discover
102
- - edit
98
+ - untest
99
+ - chroot-libs
103
100
  - edit_wait
104
- - enum
105
- - errf
106
- - git-empty
101
+ - chroot-exec
107
102
  - irb_connect
108
- - myex
109
103
  - number_files
110
- - on_change
111
- - path
112
- - probe
113
- - same_files
114
104
  - search
115
- - sedit
116
- - sshscreen
117
105
  - strip_spaces
118
- - unquarantine_apps
119
- - untest
106
+ - path
107
+ - enum
108
+ - edit
109
+ - git-empty
110
+ - classify
120
111
  - utils-install-config
112
+ - xmp
113
+ - discover
114
+ - ssh-tunnel
115
+ - myex
116
+ - probe
117
+ - errf
118
+ - same_files
121
119
  - utils-utilsrc
120
+ - unquarantine_apps
122
121
  - vacuum_firefox_sqlite
123
- - xmp
122
+ - on_change
123
+ - sedit
124
124
  extensions: []
125
125
  extra_rdoc_files:
126
126
  - README.rdoc
@@ -162,7 +162,7 @@ files:
162
162
  - bin/same_files
163
163
  - bin/search
164
164
  - bin/sedit
165
- - bin/sshscreen
165
+ - bin/ssh-tunnel
166
166
  - bin/strip_spaces
167
167
  - bin/unquarantine_apps
168
168
  - bin/untest
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  segments:
210
210
  - 0
211
- hash: -1440742416268417193
211
+ hash: -3707239069864148424
212
212
  required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  none: false
214
214
  requirements:
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 1.8.24
220
+ rubygems_version: 1.8.25
221
221
  signing_key:
222
222
  specification_version: 3
223
223
  summary: Some useful command line utilities
data/bin/sshscreen DELETED
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'fileutils'
4
- include FileUtils::Verbose
5
- require 'tins/go'
6
- include Tins::GO
7
-
8
- =begin
9
- ~/.ssh/config:
10
-
11
- Host *
12
- ForwardX11 = yes
13
- ControlMaster auto
14
- ControlPath ~/.ssh/%r@%h:%p.sock
15
- =end
16
-
17
- def usage
18
- puts <<EOT
19
- Usage: #{File.basename($0)} [OPTS] [user@]remote[:port]"
20
-
21
- OPTS is one of
22
- -N list all session names on the specified remote
23
- -n NAME name of the screen session to attach to (defaults to $USER)
24
- -t [TUNNEL_HOST[:TUNNEL_PORT]] host:port to tunnel if different from LOCALPORT
25
- -l LOCALPORT the localport to forward to if different from TUNNEL_PORT
26
- -h to display this help
27
-
28
- EOT
29
- exit 1
30
- end
31
-
32
- arguments = ARGV.dup
33
- opts = go 'l:t:n:hN', arguments
34
- usage if opts['h'] || arguments.size != 1
35
- user_remote = arguments.shift
36
- user, remote, rport =
37
- case user_remote
38
- when /\A(?:([^@:]+)@)?([^@:]+)(?::(\d+))?\Z/
39
- user = $1 || ENV['USER']
40
- user.to_s.empty? and fail "user required to login"
41
- [ user, $2, $3 || '22' ]
42
- else
43
- usage
44
- end
45
- lport = opts['l']
46
- tunnel, tport = nil, nil
47
- if tunnel_port = opts['t']
48
- case tunnel_port
49
- when /\A([^:]+)(?::(\d+))?\Z/
50
- tunnel, tport = $1, $2 || '22'
51
- lport ||= tport
52
- else
53
- usage
54
- end
55
- else
56
- tunnel, tport = 'localhost', lport
57
- end
58
- ssh_dir = File.expand_path('~/.ssh')
59
- mkdir_p ssh_dir
60
- sock_file = "#{ssh_dir}/#{user}@#{remote}:#{rport}.sock"
61
- env_user = ENV['USER'] and opts['n'] ||= env_user
62
- if opts['N']
63
- exec "ssh -p #{rport} -S #{sock_file} #{user}@#{remote} screen -ls"
64
- elsif lport
65
- rm_f sock_file
66
- exec "ssh -p #{rport} -Mt -L localhost:#{lport}:#{tunnel}:#{tport}"\
67
- " -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}"
68
- else
69
- rm_f sock_file
70
- exec "ssh -p #{rport} -Mt -S #{sock_file} #{user}@#{remote} screen -DUR #{opts['n']}"
71
- end