Class: VimDo::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/vimdo/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



32
33
34
35
36
# File 'lib/vimdo/cli.rb', line 32

def initialize(*)
  super
  VimDo.ui = UI::Shell.new(options)
  VimDo.ui.level = "debug" if options["verbose"]
end

Instance Method Details

#commands(*cmd) ⇒ Object



39
40
41
# File 'lib/vimdo/cli.rb', line 39

def commands(*cmd)
  vim.normal(":<C-u>#{cmd.join(' <Bar> ')}<CR>")
end

#diff(from, to) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/vimdo/cli.rb', line 55

def diff(from, to)
  [from, to].each do |f|
    raise PathError "#{f} is not readable!" unless File.readable?(f)
  end
  from = File.expand_path(from)
  to = File.expand_path(to)
  from, to = [from, to].map {|f| File.expand_path(f) }

  commands('tabnew', 'edit '+vim.fesc(from), 'diffsplit '+vim.fesc(to))
end

#edit(filename) ⇒ Object



50
51
52
# File 'lib/vimdo/cli.rb', line 50

def edit(filename)
  vim.edit(filename)
end

#merge(local, merge, remote, base = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vimdo/cli.rb', line 70

def merge(local, merge, remote, base = nil)

  [local, merge, remote].each do |f|
    unless File.readable?(f)
      raise PathError "#{f} is not readable!"
    end
  end
  raise PathError "#{base} is not readable!" unless File.readable?(base) or base.nil?

  local, merge, remote = [local, merge, remote].map {|f| File.expand_path(f) }

  merge_command =
    'tabnew<Bar>edit ' + vim.fesc(local) +
    '<Bar>diffsplit '  + vim.fesc(merge) +
    '<Bar>diffsplit '  + vim.fesc(remote)

  if base
    base_split_command =
      "<Bar>diffsplit #{vim.fesc(File.expand_path(base))}<Bar>wincmd J"
  else
    base_split_command = ''
  end

  switch_command = "<Bar>2wincmd w"

  commands(merge_command + base_split_command + switch_command)
end

#normal(keys = "") ⇒ Object



44
45
46
# File 'lib/vimdo/cli.rb', line 44

def normal(keys = "")
  vim.normal(keys)
end