class Tmuxinator::Config

Constants

LOCAL_DEFAULTS
NO_LOCAL_FILE_MSG
NO_PROJECT_FOUND_MSG
TMUX_MASTER_VERSION

Public Class Methods

active_sessions() click to toggle source

List of all active tmux sessions

# File lib/tmuxinator/config.rb, line 130
def active_sessions
  `tmux list-sessions -F "#S"`.split("\n")
end
config_file_basenames() click to toggle source
# 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
configs(active: nil) click to toggle source

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
default() click to toggle source
# File lib/tmuxinator/config.rb, line 62
def default
  "#{directory}/default.yml"
end
default?() click to toggle source
# File lib/tmuxinator/config.rb, line 66
def default?
  exist?(name: "default")
end
default_or_sample() click to toggle source
# File lib/tmuxinator/config.rb, line 54
def default_or_sample
  default? ? default : sample
end
default_path_option() click to toggle source
# File lib/tmuxinator/config.rb, line 82
def default_path_option
  version && version < 1.8 ? "default-path" : "-c"
end
default_project(name) click to toggle source
# File lib/tmuxinator/config.rb, line 108
def default_project(name)
  "#{directory}/#{name}.yml"
end
directories() click to toggle source

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
directory() click to toggle source

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
Also aliased as: root
environment() click to toggle source

$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
environment?() click to toggle source
# File lib/tmuxinator/config.rb, line 50
def environment?
  File.directory?(environment)
end
exist?(name: nil, path: nil) click to toggle source
# 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
global_project(name) click to toggle source

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
Also aliased as: project_in_root
home() click to toggle source
# File lib/tmuxinator/config.rb, line 22
def home
  ENV["HOME"] + "/.tmuxinator"
end
home?() click to toggle source
# File lib/tmuxinator/config.rb, line 26
def home?
  File.directory?(home)
end
local?() click to toggle source
# File lib/tmuxinator/config.rb, line 93
def local?
  local_project
end
local_project() click to toggle source
# File lib/tmuxinator/config.rb, line 104
def local_project
  LOCAL_DEFAULTS.detect { |f| File.exist?(f) }
end
Also aliased as: project_in_local
project(name) click to toggle source

Pathname of the given project

# File lib/tmuxinator/config.rb, line 113
def project(name)
  global_project(name) || local_project || default_project(name)
end
project_in_local()
Alias for: local_project
project_in_root(name)
Alias for: global_project
root()

Deprecated methods: ignore the 1st, use the 2nd

Alias for: directory
sample() click to toggle source
# File lib/tmuxinator/config.rb, line 58
def sample
  asset_path "sample.yml"
end
stop_template() click to toggle source
# File lib/tmuxinator/config.rb, line 121
def stop_template
  asset_path "template-stop.erb"
end
template() click to toggle source
# File lib/tmuxinator/config.rb, line 117
def template
  asset_path "template.erb"
end
valid_local_project?(name) click to toggle source
# 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
valid_project_config?(project_config) click to toggle source
# 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
valid_standard_project?(name) click to toggle source
# 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
validate(options = {}) click to toggle source
# 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
version() click to toggle source
# 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
wemux_template() click to toggle source
# File lib/tmuxinator/config.rb, line 125
def wemux_template
  asset_path "wemux_template.erb"
end
xdg() click to toggle source

~/.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
xdg?() click to toggle source
# File lib/tmuxinator/config.rb, line 37
def xdg?
  File.directory?(xdg)
end

Private Class Methods

asset_path(asset) click to toggle source
# File lib/tmuxinator/config.rb, line 219
def asset_path(asset)
  "#{File.dirname(__FILE__)}/assets/#{asset}"
end
project_in(directory, name) click to toggle source

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