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
- 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 “”.
- .exists?(name) ⇒ Boolean
-
.global_project(name) ⇒ Object
(also: project_in_root)
Pathname of given project searching only global directories.
- .home ⇒ Object
- .local? ⇒ Boolean
- .local_project ⇒ Object (also: project_in_local)
-
.project(name) ⇒ Object
Pathname of the given project.
- .sample ⇒ Object
- .stop_template ⇒ Object
- .template ⇒ Object
- .validate(options = {}) ⇒ Object
- .version ⇒ Object
- .wemux_template ⇒ Object
-
.xdg ⇒ Object
Is ~/.config/tmuxinator unless $XDG_CONFIG_DIR is set.
Class Method Details
.configs ⇒ Object
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 |
.default ⇒ Object
40 41 42 |
# File 'lib/tmuxinator/config.rb', line 40 def default "#{directory}/default.yml" end |
.default? ⇒ Boolean
44 45 46 |
# File 'lib/tmuxinator/config.rb', line 44 def default? exists?("default") end |
.default_path_option ⇒ Object
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 |
.directories ⇒ Object
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 |
.directory ⇒ Object 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 |
.environment ⇒ Object
$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
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 |
.home ⇒ Object
19 20 21 |
# File 'lib/tmuxinator/config.rb', line 19 def home ENV["HOME"] + "/.tmuxinator" end |
.local? ⇒ Boolean
68 69 70 |
# File 'lib/tmuxinator/config.rb', line 68 def local? local_project end |
.local_project ⇒ Object 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 |
.sample ⇒ Object
36 37 38 |
# File 'lib/tmuxinator/config.rb', line 36 def sample asset_path "sample.yml" end |
.stop_template ⇒ Object
96 97 98 |
# File 'lib/tmuxinator/config.rb', line 96 def stop_template asset_path "template-stop.erb" end |
.template ⇒ Object
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( = {}) name = [:name] [:force_attach] ||= false [: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, ).validate! end |
.version ⇒ Object
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_template ⇒ Object
100 101 102 |
# File 'lib/tmuxinator/config.rb', line 100 def wemux_template asset_path "wemux_template.erb" end |
.xdg ⇒ Object
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 |