Class: Tmuxinator::Config

Inherits:
Object
  • 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.".freeze
TMUX_MASTER_VERSION =
Float::INFINITY

Class Method Summary collapse

Class Method Details

.configsObject

Sorted list of all .yml files, including duplicates



105
106
107
108
109
110
111
# File 'lib/tmuxinator/config.rb', line 105

def configs
  directories.map do |directory|
    Dir["#{directory}/**/*.yml"].map do |path|
      path.gsub("#{directory}/", "").gsub(".yml", "")
    end
  end.flatten.sort
end

.defaultObject



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

def default
  "#{directory}/default.yml"
end

.default?Boolean

Returns:

  • (Boolean)


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

def default?
  exists?("default")
end

.default_path_optionObject



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

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

.default_project(name) ⇒ Object



83
84
85
# File 'lib/tmuxinator/config.rb', line 83

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

.directoriesObject

Existant directories which may contain project files Listed in search order Used by ‘implode` and `list` commands



116
117
118
119
120
121
122
# File 'lib/tmuxinator/config.rb', line 116

def directories
  if !environment.nil? && !environment.empty?
    [environment]
  else
    [xdg, home].select { |d| File.directory? d }
  end
end

.directoryObject Also known as: root

The directory (created if needed) in which to store new projects



10
11
12
13
14
15
16
17
# File 'lib/tmuxinator/config.rb', line 10

def directory
  return environment if File.directory?(environment)
  return xdg if File.directory?(xdg)
  return home if File.directory?(home)
  # No project directory specified or existant, default to XDG:
  FileUtils::mkdir_p(xdg)
  xdg
end

.environmentObject

$TMUXINATOR_CONFIG (and create directory) or “”.



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

def environment
  environment = ENV["TMUXINATOR_CONFIG"]
  return "" if environment.to_s.empty? # variable is unset (nil) or blank
  FileUtils::mkdir_p(environment) unless File.directory?(environment)
  environment
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/tmuxinator/config.rb', line 64

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

.global_project(name) ⇒ Object Also known as: project_in_root

Pathname of given project searching only global directories



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

def global_project(name)
  project_in(environment, name) ||
    project_in(xdg, name) ||
    project_in(home, name)
end

.homeObject



19
20
21
# File 'lib/tmuxinator/config.rb', line 19

def home
  ENV["HOME"] + "/.tmuxinator"
end

.local?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/tmuxinator/config.rb', line 68

def local?
  local_project
end

.local_projectObject Also known as: project_in_local



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

def local_project
  [LOCAL_DEFAULT].detect { |f| File.exist?(f) }
end

.project(name) ⇒ Object

Pathname of the given project



88
89
90
# File 'lib/tmuxinator/config.rb', line 88

def project(name)
  global_project(name) || local_project || default_project(name)
end

.sampleObject



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

def sample
  asset_path "sample.yml"
end

.stop_templateObject



96
97
98
# File 'lib/tmuxinator/config.rb', line 96

def stop_template
  asset_path "template-stop.erb"
end

.templateObject



92
93
94
# File 'lib/tmuxinator/config.rb', line 92

def template
  asset_path "template.erb"
end

.validate(options = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/tmuxinator/config.rb', line 124

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?
                   local_project
                 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



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tmuxinator/config.rb', line 48

def version
  if Tmuxinator::Doctor.installed?
    tmux_version = `tmux -V`.split(" ")[1]

    if tmux_version == "master"
      TMUX_MASTER_VERSION
    else
      tmux_version.to_f
    end
  end
end

.wemux_templateObject



100
101
102
# File 'lib/tmuxinator/config.rb', line 100

def wemux_template
  asset_path "wemux_template.erb"
end

.xdgObject

Is ~/.config/tmuxinator unless $XDG_CONFIG_DIR is set



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

def xdg
  XDG["CONFIG"].to_s + "/tmuxinator"
end