Class: Tmuxinator::Config

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

Constant Summary collapse

LOCAL_DEFAULT =
"./.tmuxinator.yml".freeze
NO_LOCAL_FILE_MSG =
"Project file at ./.tmuxinator.yml doesn't exist."

Class Method Summary collapse

Class Method Details

.configsObject



78
79
80
81
82
# File 'lib/tmuxinator/config.rb', line 78

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

.defaultObject



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

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

.default?Boolean

Returns:

  • (Boolean)


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

def default?
  exists?("default")
end

.default_path_optionObject



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

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

.default_project(name) ⇒ Object



62
63
64
# File 'lib/tmuxinator/config.rb', line 62

def default_project(name)
  "#{root}/#{name}.yml"
end

.editor?Boolean

Returns:

  • (Boolean)


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

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

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.installed?Boolean

Returns:

  • (Boolean)


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

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

.local?Boolean

Returns:

  • (Boolean)


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

def local?
  project_in_local
end

.project(name) ⇒ Object



66
67
68
# File 'lib/tmuxinator/config.rb', line 66

def project(name)
  project_in_root(name) || project_in_local || default_project(name)
end

.project_in_localObject



58
59
60
# File 'lib/tmuxinator/config.rb', line 58

def project_in_local
  [LOCAL_DEFAULT].detect { |f| File.exists?(f) }
end

.project_in_root(name) ⇒ Object



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

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

.rootObject



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

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

.sampleObject



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

def sample
  asset_path "sample.yml"
end

.shell?Boolean

Returns:

  • (Boolean)


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

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

.templateObject



70
71
72
# File 'lib/tmuxinator/config.rb', line 70

def template
  asset_path "template.erb"
end

.validate(options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tmuxinator/config.rb', line 84

def validate(options = {})
  name = options[:name]
  options[:force_attach] ||= false
  options[:force_detach] ||= false

  project_file = if name.nil?
                   raise NO_LOCAL_FILE_MSG \
                     unless Tmuxinator::Config.local?
                   project_in_local
                 else
                   raise "Project #{name} doesn't exist." \
                     unless Tmuxinator::Config.exists?(name)
                   Tmuxinator::Config.project(name)
                 end
  Tmuxinator::Project.load(project_file, options).validate!
end

.versionObject



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

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

.wemux_templateObject



74
75
76
# File 'lib/tmuxinator/config.rb', line 74

def wemux_template
  asset_path "wemux_template.erb"
end