Class: Tmuxinator::Config
- Inherits:
-
Object
- Object
- Tmuxinator::Config
- 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
- NO_PROJECT_FOUND_MSG =
"Project could not be found.".freeze
- TMUX_MASTER_VERSION =
Float::INFINITY
Class Method Summary collapse
-
.configs ⇒ Object
Sorted list of all .yml files, including duplicates.
- .default ⇒ Object
- .default? ⇒ Boolean
- .default_path_option ⇒ Object
- .default_project(name) ⇒ Object
-
.directories ⇒ Object
Existant directories which may contain project files Listed in search order Used by ‘implode` and `list` commands.
-
.directory ⇒ Object
(also: root)
The directory (created if needed) in which to store new projects.
-
.environment ⇒ Object
$TMUXINATOR_CONFIG (and create directory) or “”.
- .environment? ⇒ Boolean
- .exists?(name: nil, path: nil) ⇒ Boolean
-
.global_project(name) ⇒ Object
(also: project_in_root)
Pathname of given project searching only global directories.
- .home ⇒ Object
- .home? ⇒ Boolean
- .local? ⇒ Boolean
- .local_project ⇒ Object (also: project_in_local)
-
.project(name) ⇒ Object
Pathname of the given project.
- .sample ⇒ Object
- .stop_template ⇒ Object
- .template ⇒ Object
- .valid_local_project?(name) ⇒ Boolean
- .valid_project_config?(project_config) ⇒ Boolean
- .valid_standard_project?(name) ⇒ Boolean
- .validate(options = {}) ⇒ Object
- .version ⇒ Object
- .wemux_template ⇒ Object
-
.xdg ⇒ Object
~/.config/tmuxinator unless $XDG_CONFIG_HOME has been configured to use a custom value.
- .xdg? ⇒ Boolean
Class Method Details
.configs ⇒ Object
Sorted list of all .yml files, including duplicates
122 123 124 125 126 127 128 |
# File 'lib/tmuxinator/config.rb', line 122 def configs directories.map do |directory| Dir["#{directory}/**/*.yml"].map do |path| path.gsub("#{directory}/", "").gsub(".yml", "") end end.flatten.sort end |
.default ⇒ Object
55 56 57 |
# File 'lib/tmuxinator/config.rb', line 55 def default "#{directory}/default.yml" end |
.default? ⇒ Boolean
59 60 61 |
# File 'lib/tmuxinator/config.rb', line 59 def default? exists?(name: "default") end |
.default_path_option ⇒ Object
75 76 77 |
# File 'lib/tmuxinator/config.rb', line 75 def default_path_option version && version < 1.8 ? "default-path" : "-c" end |
.default_project(name) ⇒ Object
100 101 102 |
# File 'lib/tmuxinator/config.rb', line 100 def default_project(name) "#{directory}/#{name}.yml" end |
.directories ⇒ Object
Existant directories which may contain project files Listed in search order Used by ‘implode` and `list` commands
133 134 135 136 137 138 139 |
# File 'lib/tmuxinator/config.rb', line 133 def directories if environment? [environment] else [xdg, home].select { |d| File.directory? d } end end |
.directory ⇒ Object Also known as: root
The directory (created if needed) in which to store new projects
11 12 13 14 15 16 17 18 |
# File 'lib/tmuxinator/config.rb', line 11 def directory return environment if environment? return xdg if xdg? return home if home? # No project directory specified or existant, default to XDG: FileUtils::mkdir_p(xdg) xdg end |
.environment ⇒ Object
$TMUXINATOR_CONFIG (and create directory) or “”.
40 41 42 43 44 45 |
# File 'lib/tmuxinator/config.rb', line 40 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 |
.environment? ⇒ Boolean
47 48 49 |
# File 'lib/tmuxinator/config.rb', line 47 def environment? File.directory?(environment) end |
.exists?(name: nil, path: nil) ⇒ Boolean
79 80 81 82 83 |
# File 'lib/tmuxinator/config.rb', line 79 def exists?(name: nil, path: nil) return File.exist?(path) if path return File.exist?(project(name)) if name false end |
.global_project(name) ⇒ Object Also known as: project_in_root
Pathname of given project searching only global directories
90 91 92 93 94 |
# File 'lib/tmuxinator/config.rb', line 90 def global_project(name) project_in(environment, name) || project_in(xdg, name) || project_in(home, name) end |
.home ⇒ Object
20 21 22 |
# File 'lib/tmuxinator/config.rb', line 20 def home ENV["HOME"] + "/.tmuxinator" end |
.home? ⇒ Boolean
24 25 26 |
# File 'lib/tmuxinator/config.rb', line 24 def home? File.directory?(home) end |
.local? ⇒ Boolean
85 86 87 |
# File 'lib/tmuxinator/config.rb', line 85 def local? local_project end |
.local_project ⇒ Object Also known as: project_in_local
96 97 98 |
# File 'lib/tmuxinator/config.rb', line 96 def local_project [LOCAL_DEFAULT].detect { |f| File.exist?(f) } end |
.project(name) ⇒ Object
Pathname of the given project
105 106 107 |
# File 'lib/tmuxinator/config.rb', line 105 def project(name) global_project(name) || local_project || default_project(name) end |
.sample ⇒ Object
51 52 53 |
# File 'lib/tmuxinator/config.rb', line 51 def sample asset_path "sample.yml" end |
.stop_template ⇒ Object
113 114 115 |
# File 'lib/tmuxinator/config.rb', line 113 def stop_template asset_path "template-stop.erb" end |
.template ⇒ Object
109 110 111 |
# File 'lib/tmuxinator/config.rb', line 109 def template asset_path "template.erb" end |
.valid_local_project?(name) ⇒ Boolean
149 150 151 152 153 |
# File 'lib/tmuxinator/config.rb', line 149 def valid_local_project?(name) return false if name raise NO_LOCAL_FILE_MSG unless local? true end |
.valid_project_config?(project_config) ⇒ Boolean
141 142 143 144 145 146 147 |
# File 'lib/tmuxinator/config.rb', line 141 def valid_project_config?(project_config) return false unless project_config unless exists?(path: project_config) raise "Project config (#{project_config}) doesn't exist." end true end |
.valid_standard_project?(name) ⇒ Boolean
155 156 157 158 159 |
# File 'lib/tmuxinator/config.rb', line 155 def valid_standard_project?(name) return false unless name raise "Project #{name} doesn't exist." unless exists?(name: name) true end |
.validate(options = {}) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/tmuxinator/config.rb', line 161 def validate( = {}) name = [:name] [:force_attach] ||= false [:force_detach] ||= false project_config = .fetch(:project_config) { false } project_file = if valid_project_config?(project_config) project_config elsif valid_local_project?(name) local_project elsif valid_standard_project?(name) project(name) else # This branch should never be reached, # but just in case ... raise NO_PROJECT_FOUND_MSG end Tmuxinator::Project.load(project_file, ).validate! end |
.version ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tmuxinator/config.rb', line 63 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_template ⇒ Object
117 118 119 |
# File 'lib/tmuxinator/config.rb', line 117 def wemux_template asset_path "wemux_template.erb" end |
.xdg ⇒ Object
~/.config/tmuxinator unless $XDG_CONFIG_HOME has been configured to use a custom value. (e.g. if $XDG_CONFIG_HOME is set to ~/my-config, the return value will be ~/my-config/tmuxinator)
31 32 33 |
# File 'lib/tmuxinator/config.rb', line 31 def xdg XDG["CONFIG"].to_s + "/tmuxinator" end |
.xdg? ⇒ Boolean
35 36 37 |
# File 'lib/tmuxinator/config.rb', line 35 def xdg? File.directory?(xdg) end |