Class: Tmuxinator::Config
- Inherits:
-
Object
- Object
- Tmuxinator::Config
- Defined in:
- lib/tmuxinator/config.rb
Constant Summary collapse
- LOCAL_DEFAULTS =
["./.tmuxinator.yml", "./.tmuxinator.yaml"].freeze
- NO_LOCAL_FILE_MSG =
"Project file at ./.tmuxinator.yml doesn't exist."
- NO_PROJECT_FOUND_MSG =
"Project could not be found."
- TMUX_MASTER_VERSION =
Float::INFINITY
Class Method Summary collapse
-
.active_sessions ⇒ Object
List of all active tmux sessions.
-
.config_file_basenames ⇒ Array<String] a list of config file names
List the names of all config files relative to the config directory.
-
.configs(active: nil) ⇒ Array<String>
Sorted list of all project file basenames, including duplicates.
- .default ⇒ Object
- .default? ⇒ Boolean
- .default_or_sample ⇒ Object
- .default_path_option ⇒ Object
- .default_project(name) ⇒ Object
-
.directories ⇒ Object
Existent 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
- .exist?(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
.active_sessions ⇒ Object
List of all active tmux sessions
132 133 134 |
# File 'lib/tmuxinator/config.rb', line 132 def active_sessions `tmux list-sessions -F "#S"`.split("\n") end |
.config_file_basenames ⇒ Array<String] a list of config file names
List the names of all config files relative to the config directory.
If sub-folders are used, those are part of the name too.
Example:
$CONFIG_DIR/project.yml -> project
$CONFIG_DIR/sub/project.yml -> sub/project
$HOME_CONFIG_DIR/project.yml -> project
162 163 164 165 166 167 168 |
# File 'lib/tmuxinator/config.rb', line 162 def config_file_basenames directories.flat_map do |directory| Dir["#{directory}/**/*.yml"].map do |path| path.gsub("#{directory}/", "").gsub(".yml", "") end end.sort end |
.configs(active: nil) ⇒ Array<String>
Sorted list of all project file basenames, including duplicates.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/tmuxinator/config.rb', line 140 def configs(active: nil) configs = config_file_basenames if active == true configs &= active_sessions elsif active == false configs -= active_sessions end configs end |
.default ⇒ Object
64 65 66 |
# File 'lib/tmuxinator/config.rb', line 64 def default "#{directory}/default.yml" end |
.default? ⇒ Boolean
68 69 70 |
# File 'lib/tmuxinator/config.rb', line 68 def default? exist?(name: "default") end |
.default_or_sample ⇒ Object
56 57 58 |
# File 'lib/tmuxinator/config.rb', line 56 def default_or_sample default? ? default : sample end |
.default_path_option ⇒ Object
84 85 86 |
# File 'lib/tmuxinator/config.rb', line 84 def default_path_option version && version < 1.8 ? "default-path" : "-c" end |
.default_project(name) ⇒ Object
110 111 112 |
# File 'lib/tmuxinator/config.rb', line 110 def default_project(name) "#{directory}/#{name}.yml" end |
.directories ⇒ Object
Existent directories which may contain project files Listed in search order Used by ‘implode` and `list` commands
173 174 175 176 177 178 179 |
# File 'lib/tmuxinator/config.rb', line 173 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
12 13 14 15 16 17 18 19 20 |
# File 'lib/tmuxinator/config.rb', line 12 def directory return environment if environment? return xdg if xdg? return home if home? # No project directory specified or existent, default to XDG: FileUtils::mkdir_p(xdg) xdg end |
.environment ⇒ Object
$TMUXINATOR_CONFIG (and create directory) or “”.
44 45 46 47 48 49 50 |
# File 'lib/tmuxinator/config.rb', line 44 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
52 53 54 |
# File 'lib/tmuxinator/config.rb', line 52 def environment? File.directory?(environment) end |
.exist?(name: nil, path: nil) ⇒ Boolean
88 89 90 91 92 93 |
# File 'lib/tmuxinator/config.rb', line 88 def exist?(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
100 101 102 103 104 |
# File 'lib/tmuxinator/config.rb', line 100 def global_project(name) project_in(environment, name) || project_in(xdg, name) || project_in(home, name) end |
.home ⇒ Object
22 23 24 |
# File 'lib/tmuxinator/config.rb', line 22 def home "#{ENV['HOME']}/.tmuxinator" end |
.home? ⇒ Boolean
26 27 28 |
# File 'lib/tmuxinator/config.rb', line 26 def home? File.directory?(home) end |
.local? ⇒ Boolean
95 96 97 |
# File 'lib/tmuxinator/config.rb', line 95 def local? local_project end |
.local_project ⇒ Object Also known as: project_in_local
106 107 108 |
# File 'lib/tmuxinator/config.rb', line 106 def local_project LOCAL_DEFAULTS.detect { |f| File.exist?(f) } end |
.project(name) ⇒ Object
Pathname of the given project
115 116 117 |
# File 'lib/tmuxinator/config.rb', line 115 def project(name) global_project(name) || local_project || default_project(name) end |
.sample ⇒ Object
60 61 62 |
# File 'lib/tmuxinator/config.rb', line 60 def sample asset_path "sample.yml" end |
.stop_template ⇒ Object
123 124 125 |
# File 'lib/tmuxinator/config.rb', line 123 def stop_template asset_path "template-stop.erb" end |
.template ⇒ Object
119 120 121 |
# File 'lib/tmuxinator/config.rb', line 119 def template asset_path "template.erb" end |
.valid_local_project?(name) ⇒ Boolean
190 191 192 193 194 195 |
# File 'lib/tmuxinator/config.rb', line 190 def valid_local_project?(name) return false if name raise NO_LOCAL_FILE_MSG unless local? true end |
.valid_project_config?(project_config) ⇒ Boolean
181 182 183 184 185 186 187 188 |
# File 'lib/tmuxinator/config.rb', line 181 def valid_project_config?(project_config) return false unless project_config unless exist?(path: project_config) raise "Project config (#{project_config}) doesn't exist." end true end |
.valid_standard_project?(name) ⇒ Boolean
197 198 199 200 201 202 |
# File 'lib/tmuxinator/config.rb', line 197 def valid_standard_project?(name) return false unless name raise "Project #{name} doesn't exist." unless exist?(name: name) true end |
.validate(options = {}) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/tmuxinator/config.rb', line 204 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
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tmuxinator/config.rb', line 72 def version if Tmuxinator::Doctor.installed? tmux_version = `tmux -V`.split(" ")[1] if tmux_version == "master" TMUX_MASTER_VERSION else tmux_version.to_s[/\d+(?:\.\d+)?/, 0].to_f end end end |
.wemux_template ⇒ Object
127 128 129 |
# File 'lib/tmuxinator/config.rb', line 127 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)
33 34 35 36 37 |
# File 'lib/tmuxinator/config.rb', line 33 def xdg xdg_config_directory = ENV.fetch("XDG_CONFIG_HOME", "~/.config") config_home = File.(xdg_config_directory) File.join(config_home, "tmuxinator") end |
.xdg? ⇒ Boolean
39 40 41 |
# File 'lib/tmuxinator/config.rb', line 39 def xdg? File.directory?(xdg) end |