wire-edit 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/wired +9 -0
- data/lib/wire-edit.rb +65 -0
- metadata +49 -0
data/bin/wired
ADDED
data/lib/wire-edit.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rb-fsevent'
|
3
|
+
|
4
|
+
# cases:
|
5
|
+
# user@server w/ password, w/o password. server w/password, w/o password.
|
6
|
+
# pass it a file. pass it a directory.
|
7
|
+
# file exists, doesn't exist. directory exists, doesn't exist.
|
8
|
+
# absolute path vs relative path
|
9
|
+
# prefixed w home dir ~
|
10
|
+
class WireEdit
|
11
|
+
attr_accessor :user, :server_name, :remote_dir, :ssh_cmd
|
12
|
+
|
13
|
+
def initialize ssh_opt
|
14
|
+
@m = /(?<ssh_cmd>((?<user>.*)@)?(?<server_name>.*)):(?<remote_dir>.*)/.match(ssh_opt)
|
15
|
+
flunk("require the ssh parameter!") unless @m
|
16
|
+
[:user, :server_name, :remote_dir, :ssh_cmd].each { |attr| self.send("#{attr}=", @m[attr]) }
|
17
|
+
|
18
|
+
FileUtils.mkdir_p local_path
|
19
|
+
|
20
|
+
download
|
21
|
+
edit
|
22
|
+
fsevent = FSEvent.new
|
23
|
+
puts "Watching #{local_path}"
|
24
|
+
fsevent.watch(local_path) do |dirs|
|
25
|
+
puts "Upload changes from: #{dirs.join(' ')}"
|
26
|
+
upload
|
27
|
+
end
|
28
|
+
fsevent.run
|
29
|
+
end
|
30
|
+
|
31
|
+
def download
|
32
|
+
puts 'Downloading...'
|
33
|
+
# dl = @sftp.download!(remote_dir, local_path, :recursive => true)
|
34
|
+
puts %x{ rsync -avz #{ssh_cmd}:#{remote_dir} #{File.dirname(local_path)} }
|
35
|
+
end
|
36
|
+
|
37
|
+
def upload
|
38
|
+
# @sftp.upload!(local_path, File.dirname(remote_dir))
|
39
|
+
puts %x{ rsync -avz #{local_path} #{ssh_cmd}:#{File.dirname(remote_dir)} }
|
40
|
+
end
|
41
|
+
|
42
|
+
# def read_ssh_config
|
43
|
+
# config = Net::SSH.configuration_for(server_name)
|
44
|
+
# flunk("No user specified and no ~/.ssh/config entry for the server name.") if config.empty?
|
45
|
+
# self.user = config[:user]
|
46
|
+
# self.server_name = config[:host_name]
|
47
|
+
# end
|
48
|
+
|
49
|
+
def edit
|
50
|
+
%x{ mate #{local_path} }
|
51
|
+
end
|
52
|
+
|
53
|
+
def servername_dir
|
54
|
+
@local_dir ||= (user ? (user + '-') : '') + server_name
|
55
|
+
end
|
56
|
+
|
57
|
+
def local_path
|
58
|
+
"/tmp/wire-edit/#{servername_dir}/#{remote_dir}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def flunk(msg)
|
62
|
+
STDERR << msg << "\n"
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wire-edit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Duke Jones
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Edit files on a server in TextMate and they are uploaded back to the
|
15
|
+
server automatically!
|
16
|
+
email: dukeofjones@gmail.com
|
17
|
+
executables:
|
18
|
+
- wired
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/wire-edit.rb
|
23
|
+
- bin/wired
|
24
|
+
homepage: ''
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.18
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Edit files on a server in TextMate and they are uploaded back to the server
|
48
|
+
automatically!
|
49
|
+
test_files: []
|