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.



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

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

end

Instance Method Details

#autocompleteObject



143
144
145
# File 'lib/vimdo/cli.rb', line 143

def autocomplete()
  raise UndefinedCommandError, "autocomplete should be intercepted."
end

#commands(*cmd) ⇒ Object



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

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

#diff(from, to) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/vimdo/cli.rb', line 78

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

  commands("tabedit #{path(from)}", "diffsplit #{path(to)}")
  vim.foreground
end

#diffpatch(file) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vimdo/cli.rb', line 94

def diffpatch(file)
  patch = options[:patch]
  [file, patch].each do |f|
    unless File.readable?(f)
      raise PathError "#{f} is not readable!"
    end
  end
  file, patch = [file, patch].map {|f| File.expand_path(f) }

  commands("edit #{path(file)}", "vertical diffpatch #{path(patch)}")
  vim.foreground
end

#edit(filename) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vimdo/cli.rb', line 62

def edit(filename)
  linenr = nil
  if /(.*):(\d+):?/.match(filename)
    f = File.expand_path($1)
    linenr = $2
  else
    f = File.expand_path(filename)
  end 

  raise PathError "#{f} is not readable!" unless File.readable?(f)
  vim.edit(f)
  commands(linenr) if linenr
  vim.foreground
end

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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/vimdo/cli.rb', line 113

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 #{path(local)}" +
  "<Bar>diffsplit #{path(merge)}"  +
  "<Bar>diffsplit #{path(remote)}"

  if base
    base_split_command =
    "<Bar>diffsplit #{path(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)
  vim.foreground
end

#normal(keys = "") ⇒ Object



56
57
58
# File 'lib/vimdo/cli.rb', line 56

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