class Tmuxinator::Config
Constants
- LOCAL_DEFAULTS
- NO_LOCAL_FILE_MSG
- NO_PROJECT_FOUND_MSG
- TMUX_MASTER_VERSION
Public Class Methods
List of all active tmux sessions
# File lib/tmuxinator/config.rb, line 130 def active_sessions `tmux list-sessions -F "#S"`.split("\n") end
# File lib/tmuxinator/config.rb, line 150 def config_file_basenames directories.flat_map do |directory| Dir["#{directory}/**/*.yml"].map do |path| path.gsub("#{directory}/", "").gsub(".yml", "") end end.sort end
Sorted list of all project .yml file basenames, including duplicates
@param active filter configs by active project sessions @return [Array<String>] list of project names
# File lib/tmuxinator/config.rb, line 138 def configs(active: nil) configs = config_file_basenames if active == true configs &= active_sessions elsif active == false configs -= active_sessions end configs end
# File lib/tmuxinator/config.rb, line 62 def default "#{directory}/default.yml" end
# File lib/tmuxinator/config.rb, line 66 def default? exist?(name: "default") end
# File lib/tmuxinator/config.rb, line 54 def default_or_sample default? ? default : sample end
# File lib/tmuxinator/config.rb, line 82 def default_path_option version && version < 1.8 ? "default-path" : "-c" end
# File lib/tmuxinator/config.rb, line 108 def default_project(name) "#{directory}/#{name}.yml" end
Existent directories which may contain project files Listed in search order Used by ‘implode` and `list` commands
# File lib/tmuxinator/config.rb, line 161 def directories if environment? [environment] else [xdg, home].select { |d| File.directory? d } end end
The directory (created if needed) in which to store new projects
# 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
$TMUXINATOR_CONFIG (and create directory) or “”.
# File lib/tmuxinator/config.rb, line 42 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
# File lib/tmuxinator/config.rb, line 50 def environment? File.directory?(environment) end
# File lib/tmuxinator/config.rb, line 86 def exist?(name: nil, path: nil) return File.exist?(path) if path return File.exist?(project(name)) if name false end
Pathname of given project searching only global directories
# File lib/tmuxinator/config.rb, line 98 def global_project(name) project_in(environment, name) || project_in(xdg, name) || project_in(home, name) end
# File lib/tmuxinator/config.rb, line 22 def home ENV["HOME"] + "/.tmuxinator" end
# File lib/tmuxinator/config.rb, line 26 def home? File.directory?(home) end
# File lib/tmuxinator/config.rb, line 93 def local? local_project end
# File lib/tmuxinator/config.rb, line 104 def local_project LOCAL_DEFAULTS.detect { |f| File.exist?(f) } end
Pathname of the given project
# File lib/tmuxinator/config.rb, line 113 def project(name) global_project(name) || local_project || default_project(name) end
# File lib/tmuxinator/config.rb, line 58 def sample asset_path "sample.yml" end
# File lib/tmuxinator/config.rb, line 121 def stop_template asset_path "template-stop.erb" end
# File lib/tmuxinator/config.rb, line 117 def template asset_path "template.erb" end
# File lib/tmuxinator/config.rb, line 178 def valid_local_project?(name) return false if name raise NO_LOCAL_FILE_MSG unless local? true end
# File lib/tmuxinator/config.rb, line 169 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
# File lib/tmuxinator/config.rb, line 185 def valid_standard_project?(name) return false unless name raise "Project #{name} doesn't exist." unless exist?(name: name) true end
# File lib/tmuxinator/config.rb, line 192 def validate(options = {}) name = options[:name] options[:force_attach] ||= false options[:force_detach] ||= false project_config = options.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, options).validate! end
# File lib/tmuxinator/config.rb, line 70 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
# File lib/tmuxinator/config.rb, line 125 def wemux_template asset_path "wemux_template.erb" end
~/.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)
# File lib/tmuxinator/config.rb, line 33 def xdg XDG["CONFIG"].to_s + "/tmuxinator" end
# File lib/tmuxinator/config.rb, line 37 def xdg? File.directory?(xdg) end
Private Class Methods
# File lib/tmuxinator/config.rb, line 219 def asset_path(asset) "#{File.dirname(__FILE__)}/assets/#{asset}" end
The first pathname of the project named ‘name’ found while recursively searching ‘directory’
# File lib/tmuxinator/config.rb, line 225 def project_in(directory, name) return nil if String(directory).empty? projects = Dir.glob("#{directory}/**/*.{yml,yaml}").sort projects.detect { |project| File.basename(project, ".*") == name } end