Class: VimSitter::VimDir

Inherits:
Object
  • Object
show all
Defined in:
lib/vim_sitter/vim_dir.rb

Class Method Summary collapse

Class Method Details

.add_to_vimrc(s) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vim_sitter/vim_dir.rb', line 40

def self.add_to_vimrc s
  new_lines = s.split("\n").map {|item| item + "\n"}
  lines = IO.readlines(vimrc_path)
  unless lines & new_lines == new_lines
    require 'tempfile'
    begin
      tmp = Tempfile.new('vimrc')
      tmp.binmode
      tmp.print new_lines.join
      tmp.print lines.join
      tmp.close
      FileUtils.copy_file(tmp.path, vimrc_path)
    ensure
      tmp.close
      tmp.unlink
    end
  end
end

.autoload_dirObject



77
78
79
# File 'lib/vim_sitter/vim_dir.rb', line 77

def self.autoload_dir
  "#{base_dir}/autoload"
end

.base_dirObject



69
70
71
# File 'lib/vim_sitter/vim_dir.rb', line 69

def self.base_dir
  File.expand_path("~/#{windows? ? 'vimfiles' : '.vim'}")
end

.bundle_dirObject



73
74
75
# File 'lib/vim_sitter/vim_dir.rb', line 73

def self.bundle_dir
  "#{base_dir}/bundle"
end

.cd_to_bundle(repo_name = '') ⇒ Object



28
29
30
# File 'lib/vim_sitter/vim_dir.rb', line 28

def self.cd_to_bundle repo_name=''
  FileUtils.cd "#{bundle_dir}/#{repo_name}"
end

.cp_to_autoload(path) ⇒ Object



36
37
38
# File 'lib/vim_sitter/vim_dir.rb', line 36

def self.cp_to_autoload path
  FileUtils.cp "#{bundle_dir}/#{path}", autoload_dir
end

.create_autoloadObject



12
13
14
# File 'lib/vim_sitter/vim_dir.rb', line 12

def self.create_autoload
  FileUtils.mkdir_p autoload_dir
end

.create_backupObject



20
21
22
# File 'lib/vim_sitter/vim_dir.rb', line 20

def self.create_backup
  FileUtils.mkdir_p(data_dir + '/backup')
end

.create_bundleObject

TODO need linux



8
9
10
# File 'lib/vim_sitter/vim_dir.rb', line 8

def self.create_bundle
  FileUtils.mkdir_p(bundle_dir)
end

.create_swapObject



16
17
18
# File 'lib/vim_sitter/vim_dir.rb', line 16

def self.create_swap
  FileUtils.mkdir_p(data_dir + '/swap')
end

.create_undoObject



24
25
26
# File 'lib/vim_sitter/vim_dir.rb', line 24

def self.create_undo
  FileUtils.mkdir_p(data_dir + '/undo')
end

.data_dirObject



59
60
61
62
63
64
65
66
67
# File 'lib/vim_sitter/vim_dir.rb', line 59

def self.data_dir
  if windows?
    ENV['AppData'].gsub('\\','/') + '/Vim'
  elsif mac?
    File.expand_path "~/Library/Vim"
  else
    raise "os '#{RUBY_PLATFORM}' not recognized!"
  end
end

.mac?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/vim_sitter/vim_dir.rb', line 89

def self.mac?
  RUBY_PLATFORM =~ /darwin/
end

.repo_exists?(repo_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/vim_sitter/vim_dir.rb', line 32

def self.repo_exists? repo_name
  File.exists? "#{bundle_dir}/#{repo_name}"
end

.vimrc_pathObject



81
82
83
# File 'lib/vim_sitter/vim_dir.rb', line 81

def self.vimrc_path
  File.expand_path("~/#{windows? ? '_vimrc' : '.vimrc'}")
end

.windows?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/vim_sitter/vim_dir.rb', line 85

def self.windows?
  RUBY_PLATFORM =~ /(win|w)32$/
end