Sha256: 05d6427750464b1ffcade2e7b631db6ecc849b2ba035c62c8cf04ec973d546b0

Contents?: true

Size: 1.87 KB

Versions: 13

Compression:

Stored size: 1.87 KB

Contents

#!/usr/bin/env ruby

require 'tins/xt'
include Tins::GO
require 'utils'
include Utils
require 'tempfile'

def usage
  puts <<-EOT
Usage: #{File.basename($0)} [OPTS] [PATHS]

PATHS are the directory and file paths that are opened in the vim.

Options are

  -w          open a buffer in vim and wait until it is deleted
  -s          read files and files:linenumbers from stdin and open them
  -m          make intermediate non existing directories to file
  -c COMMAND  send ex command to the current running editor
  -C COMMAND  send visual command to the current running editor
  -p DURATION pause for this many seconds to wait for vim's reaction
  -S SERVER   specify the server for this edit command
  -h          display this help

Version is #{File.basename($0)} #{Utils::VERSION}.
  EOT
  exit 1
end

$opt = go 'p:S:c:wsmh'
$opt['h'] and usage

config = Utils::Config::ConfigFile.new
config.configure_from_paths

editor = Editor.new do |c|
  c.wait           = $opt['w']
  c.pause_duration = ($opt['p'] || 1).to_i
  s = $opt['S'] and c.servername = s
  c.mkdir = $opt['m']
end

if $opt['s']
  begin
    until STDIN.eof?
      line = STDIN.gets
      line = line.sub(/.*?([^:\s]+:)/, '\1')
      editor.edit(line)
    end
  rescue Interrupt
    exit 1
  end
  exit 0
elsif command = $opt['c']
  editor.edit_remote_send "\e:#{command}\n"
elsif command = $opt['C']
  editor.edit_remote_send command
end

argv = ARGV.dup
if argv.empty?
  unless STDIN.tty?
    file = File.new(File.join(Dir.tmpdir, "edit_tmp.#$$"), 'w')
    until STDIN.eof?
      buffer = STDIN.read(8192)
      file.write buffer
    end
    file.close
    argv << file.path
  end
end
if argv.empty?
  editor.start
else
  if editor.file_linenumber?(argv.first)
    editor.wait = argv.size > 1
    for current_file in argv
      STDOUT.puts "Edit #{current_file}"
      editor.edit current_file
    end
  else
    editor.edit(*argv)
  end
end
exit 0

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
utils-0.2.4 bin/edit
utils-0.2.3 bin/edit
utils-0.2.2 bin/edit
utils-0.2.1 bin/edit
utils-0.2.0 bin/edit
utils-0.1.1 bin/edit
utils-0.1.0 bin/edit
utils-0.0.100 bin/edit
utils-0.0.99 bin/edit
utils-0.0.98 bin/edit
utils-0.0.97 bin/edit
utils-0.0.96 bin/edit
utils-0.0.95 bin/edit