Skip to content

Commit

Permalink
Merge pull request #505 from tmuxinator/revert-479-Issues-360-462
Browse files Browse the repository at this point in the history
Revert "Support specified config directory and XDG Base Dirs Spec"
  • Loading branch information
ethagnawl committed Feb 5, 2017
2 parents af90ade + d9b1b59 commit 6e529e8
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 238 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,6 @@
- Move gem dependencies from Gemfile to tmuxinator.gemspec
- Add tmux 2.2 and 2.3 the TravisCI test matrix
- Fix typos
- Support user-specified and XDG Base Dirs configuration directories

## 0.9.0
### Misc
Expand Down
4 changes: 1 addition & 3 deletions lib/tmuxinator.rb
@@ -1,10 +1,8 @@
require "yaml"
require "erubis"
require "fileutils"
require "shellwords"
require "thor"
require "thor/version"
require "xdg"
require "yaml"

require "tmuxinator/util"
require "tmuxinator/deprecations"
Expand Down
4 changes: 1 addition & 3 deletions lib/tmuxinator/cli.rb
Expand Up @@ -231,9 +231,7 @@ def delete(*projects)

def implode
if yes?("Are you sure you want to delete all tmuxinator configs?", :red)
Tmuxinator::Config.directories.each do |directory|
FileUtils.remove_dir(directory)
end
FileUtils.remove_dir(Tmuxinator::Config.root)
say "Deleted all tmuxinator projects."
end
end
Expand Down
82 changes: 16 additions & 66 deletions lib/tmuxinator/config.rb
Expand Up @@ -4,38 +4,18 @@ class Config
NO_LOCAL_FILE_MSG = "Project file at ./.tmuxinator.yml doesn't exist."

class << self
# The directory (created if needed) in which to store new projects
def directory
if !environment.nil? && !environment.empty?
FileUtils::mkpath(environment) unless File.directory?(environment)
return environment
end
return xdg if File.directory?(xdg)
return home if File.directory?(home)
# No project directory specified or existant, default to XDG:
FileUtils::mkpath(xdg)
xdg
end

def home
ENV["HOME"] + "/.tmuxinator"
end

# Is ~/.config/tmuxinator unless $XDG_CONFIG_DIR is set
def xdg
XDG["CONFIG"].to_s + "/tmuxinator"
end

def environment
ENV["TMUXINATOR_CONFIG"]
def root
root_dir = File.expand_path("#{ENV['HOME']}/.tmuxinator")
Dir.mkdir(root_dir) unless File.directory?(root_dir)
root_dir
end

def sample
asset_path "sample.yml"
end

def default
"#{directory}/default.yml"
"#{ENV['HOME']}/.tmuxinator/default.yml"
end

def default?
Expand Down Expand Up @@ -66,28 +46,25 @@ def exists?(name)
File.exist?(project(name))
end

def local?
local_project
def project_in_root(name)
projects = Dir.glob("#{root}/**/*.yml")
projects.detect { |project| File.basename(project, ".yml") == name }
end

# Pathname of given project searching only global directories
def global_project(name)
project_in(environment, name) ||
project_in(xdg, name) ||
project_in(home, name)
def local?
project_in_local
end

def local_project
def project_in_local
[LOCAL_DEFAULT].detect { |f| File.exist?(f) }
end

def default_project(name)
"#{directory}/#{name}.yml"
"#{root}/#{name}.yml"
end

# Pathname of the given project
def project(name)
global_project(name) || local_project || default_project(name)
project_in_root(name) || project_in_local || default_project(name)
end

def template
Expand All @@ -98,23 +75,9 @@ def wemux_template
asset_path "wemux_template.erb"
end

# Sorted list of all .yml files, including duplicates
def configs
directories.map do |directory|
Dir["#{directory}/**/*.yml"].map do |path|
path.gsub("#{directory}/", "").gsub(".yml", "")
end
end.flatten.sort
end

# Existant directories which may contain project files
# Listed in search order
# Used by `implode` and `list` commands
def directories
if !environment.nil? && !environment.empty?
[environment]
else
[xdg, home].select { |d| File.directory? d }
Dir["#{Tmuxinator::Config.root}/**/*.yml"].sort.map do |path|
path.gsub("#{Tmuxinator::Config.root}/", "").gsub(".yml", "")
end
end

Expand All @@ -126,7 +89,7 @@ def validate(options = {})
project_file = if name.nil?
raise NO_LOCAL_FILE_MSG \
unless Tmuxinator::Config.local?
local_project
project_in_local
else
raise "Project #{name} doesn't exist." \
unless Tmuxinator::Config.exists?(name)
Expand All @@ -135,24 +98,11 @@ def validate(options = {})
Tmuxinator::Project.load(project_file, options).validate!
end

# Deprecated methods: ignore the 1st, use the 2nd
alias :root :directory
alias :project_in_root :global_project
alias :project_in_local :local_project

private

def asset_path(asset)
"#{File.dirname(__FILE__)}/assets/#{asset}"
end

# The first pathname of the project named 'name' found while
# recursively searching 'directory'
def project_in(directory, name)
return nil if String(directory).empty?
projects = Dir.glob("#{directory}/**/*.yml")
projects.detect { |project| File.basename(project, ".yml") == name }
end
end
end
end
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
34 changes: 8 additions & 26 deletions spec/lib/tmuxinator/cli_spec.rb
@@ -1,5 +1,4 @@
require "spec_helper"

describe Tmuxinator::Cli do
let(:cli) { Tmuxinator::Cli }

Expand Down Expand Up @@ -232,16 +231,16 @@
end
end

context "file exists" do
let(:project_path) { "#{Tmuxinator::Config.project(name)}" }
context "files exists" do
let(:root_path) { "#{ENV['HOME']}\/\.tmuxinator\/#{name}\.yml" }

before do
allow(File).to receive(:exist?).with(anything).and_return(false)
expect(File).to receive(:exist?).with(project_path).and_return(true)
expect(File).to receive(:exist?).with(root_path).and_return(true)
end

it "just opens the file" do
expect(Kernel).to receive(:system).with(%r{#{project_path}})
expect(Kernel).to receive(:system).with(%r{#{root_path}})
capture_io { cli.start }
end
end
Expand All @@ -265,7 +264,7 @@
end
end

context "file exists" do
context "files exists" do
let(:path) { Tmuxinator::Config::LOCAL_DEFAULT }
before do
expect(File).to receive(:exist?).with(path) { true }
Expand Down Expand Up @@ -445,27 +444,10 @@
capture_io { cli.start }
end

it "deletes the configuration directory(s)" do
allow(Tmuxinator::Config).to receive(:directories) \
{ [Tmuxinator::Config.xdg, Tmuxinator::Config.home] }
expect(FileUtils).to receive(:remove_dir).once.
with(Tmuxinator::Config.xdg)
expect(FileUtils).to receive(:remove_dir).once.
with(Tmuxinator::Config.home)
expect(FileUtils).to receive(:remove_dir).never
it "deletes all projects" do
expect(FileUtils).to receive(:remove_dir)
capture_io { cli.start }
end

context "$TMUXINATOR_CONFIG specified" do
it "only deletes projects in that directory" do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("TMUXINATOR_CONFIG").and_return "dir"
allow(File).to receive(:directory?).with("dir").and_return true
expect(FileUtils).to receive(:remove_dir).once.with("dir")
expect(FileUtils).to receive(:remove_dir).never
capture_io { cli.start }
end
end
end

describe "#list" do
Expand Down Expand Up @@ -589,7 +571,7 @@
subject { described_class.new.create_project(params) }

before do
allow(Tmuxinator::Config).to receive_messages(directory: path)
allow(Tmuxinator::Config).to receive_messages(root: path)
end

it_should_behave_like :a_proper_project
Expand Down

0 comments on commit 6e529e8

Please sign in to comment.