Class: Tmuxinator::Config

Inherits:
Object show all
Defined in:
lib/tmuxinator/config.rb

Class Method Summary collapse

Class Method Details

.configsObject



59
60
61
62
63
# File 'lib/tmuxinator/config.rb', line 59

def configs
  Dir["#{Tmuxinator::Config.root}/**/*.yml"].sort.map do |path|
    path.gsub("#{Tmuxinator::Config.root}/", "").gsub(".yml", "")
  end
end

.defaultObject



13
14
15
# File 'lib/tmuxinator/config.rb', line 13

def default
  "#{ENV["HOME"]}/.tmuxinator/default.yml"
end

.default?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/tmuxinator/config.rb', line 17

def default?
  exists?("default")
end

.default_path_optionObject



29
30
31
# File 'lib/tmuxinator/config.rb', line 29

def default_path_option
  version && version < 1.8 ? "default-path" : "-c"
end

.editor?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/tmuxinator/config.rb', line 33

def editor?
  !ENV["EDITOR"].nil? && !ENV["EDITOR"].empty?
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/tmuxinator/config.rb', line 41

def exists?(name)
  File.exists?(project(name))
end

.installed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/tmuxinator/config.rb', line 21

def installed?
  Kernel.system("type tmux > /dev/null")
end

.project(name) ⇒ Object



45
46
47
48
49
# File 'lib/tmuxinator/config.rb', line 45

def project(name)
  projects = Dir.glob("#{root}/**/*.yml")
  project_file = projects.detect { |project| File.basename(project, ".yml") == name }
  project_file || "#{root}/#{name}.yml"
end

.rootObject



4
5
6
7
# File 'lib/tmuxinator/config.rb', line 4

def root
  Dir.mkdir("#{ENV["HOME"]}/.tmuxinator") unless File.directory?(File.expand_path("~/.tmuxinator"))
  "#{ENV["HOME"]}/.tmuxinator"
end

.sampleObject



9
10
11
# File 'lib/tmuxinator/config.rb', line 9

def sample
  "#{File.dirname(__FILE__)}/assets/sample.yml"
end

.shell?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/tmuxinator/config.rb', line 37

def shell?
  !ENV["SHELL"].nil? && !ENV["SHELL"].empty?
end

.templateObject



51
52
53
# File 'lib/tmuxinator/config.rb', line 51

def template
  "#{File.dirname(__FILE__)}/assets/template.erb"
end

.validate(name, custom_name = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/tmuxinator/config.rb', line 65

def validate(name, custom_name = nil)
  unless Tmuxinator::Config.exists?(name)
    puts "Project #{name} doesn't exist."
    exit!
  end

  config_path = Tmuxinator::Config.project(name)

  yaml = begin
    YAML.load(Erubis::Eruby.new(File.read(config_path)).result(binding))
  rescue SyntaxError, StandardError
    puts "Failed to parse config file. Please check your formatting."
    exit!
  end

  project = Tmuxinator::Project.new(yaml, custom_name)

  unless project.windows?
    puts "Your project file should include some windows."
    exit!
  end

  unless project.name?
    puts "Your project file didn't specify a 'project_name'"
    exit!
  end

  project
end

.versionObject



25
26
27
# File 'lib/tmuxinator/config.rb', line 25

def version
  `tmux -V`.split(" ")[1].to_f if installed?
end

.wemux_templateObject



55
56
57
# File 'lib/tmuxinator/config.rb', line 55

def wemux_template
  "#{File.dirname(__FILE__)}/assets/wemux_template.erb"
end