Class: VimSitter::VimDir
- Inherits:
-
Object
- Object
- VimSitter::VimDir
- Defined in:
- lib/vim_sitter/vim_dir.rb
Class Method Summary collapse
- .add_to_vimrc(s) ⇒ Object
- .autoload_dir ⇒ Object
- .base_dir ⇒ Object
- .bundle_dir ⇒ Object
- .cd_to_bundle(repo_name = '') ⇒ Object
- .cp_to_autoload(path) ⇒ Object
- .create_autoload ⇒ Object
- .create_backup ⇒ Object
-
.create_bundle ⇒ Object
TODO need linux.
- .create_swap ⇒ Object
- .create_undo ⇒ Object
- .data_dir ⇒ Object
- .mac? ⇒ Boolean
- .repo_exists?(repo_name) ⇒ Boolean
- .vimrc_path ⇒ Object
- .windows? ⇒ Boolean
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_dir ⇒ Object
77 78 79 |
# File 'lib/vim_sitter/vim_dir.rb', line 77 def self.autoload_dir "#{base_dir}/autoload" end |
.base_dir ⇒ Object
69 70 71 |
# File 'lib/vim_sitter/vim_dir.rb', line 69 def self.base_dir File.("~/#{windows? ? 'vimfiles' : '.vim'}") end |
.bundle_dir ⇒ Object
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_autoload ⇒ Object
12 13 14 |
# File 'lib/vim_sitter/vim_dir.rb', line 12 def self.create_autoload FileUtils.mkdir_p autoload_dir end |
.create_backup ⇒ Object
20 21 22 |
# File 'lib/vim_sitter/vim_dir.rb', line 20 def self.create_backup FileUtils.mkdir_p(data_dir + '/backup') end |
.create_bundle ⇒ Object
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_swap ⇒ Object
16 17 18 |
# File 'lib/vim_sitter/vim_dir.rb', line 16 def self.create_swap FileUtils.mkdir_p(data_dir + '/swap') end |
.create_undo ⇒ Object
24 25 26 |
# File 'lib/vim_sitter/vim_dir.rb', line 24 def self.create_undo FileUtils.mkdir_p(data_dir + '/undo') end |
.data_dir ⇒ Object
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. "~/Library/Vim" else raise "os '#{RUBY_PLATFORM}' not recognized!" end end |
.mac? ⇒ 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
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_path ⇒ Object
81 82 83 |
# File 'lib/vim_sitter/vim_dir.rb', line 81 def self.vimrc_path File.("~/#{windows? ? '_vimrc' : '.vimrc'}") end |
.windows? ⇒ Boolean
85 86 87 |
# File 'lib/vim_sitter/vim_dir.rb', line 85 def self.windows? RUBY_PLATFORM =~ /(win|w)32$/ end |