Mercurial > hg > Members > atton > pmux
comparison lib/pmuxinator/config.rb @ 2:67a6071afec7
Rename tmuxinator -> pmuxinator
$ zmv **/*tmuxinator* **/*pmuxinator*
$ gsed -e 's/tmuxinator/pmuxinator/g' -i **/*.*
$ gsed -e 's/Tmuxinator/Pmuxinator/g' -i **/*.*
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 21 Jul 2014 08:32:00 +0900 |
parents | |
children | 73ee80dc9415 |
comparison
equal
deleted
inserted
replaced
1:107d94e009cc | 2:67a6071afec7 |
---|---|
1 module Pmuxinator | |
2 class Config | |
3 class << self | |
4 def root | |
5 Dir.mkdir("#{ENV["HOME"]}/.pmuxinator") unless File.directory?(File.expand_path("~/.pmuxinator")) | |
6 "#{ENV["HOME"]}/.pmuxinator" | |
7 end | |
8 | |
9 def sample | |
10 "#{File.dirname(__FILE__)}/assets/sample.yml" | |
11 end | |
12 | |
13 def default | |
14 "#{ENV["HOME"]}/.pmuxinator/default.yml" | |
15 end | |
16 | |
17 def default? | |
18 exists?("default") | |
19 end | |
20 | |
21 def installed? | |
22 Kernel.system("type tmux > /dev/null") | |
23 end | |
24 | |
25 def version | |
26 `tmux -V`.split(" ")[1].to_f if installed? | |
27 end | |
28 | |
29 def default_path_option | |
30 version && version < 1.7 ? "default-path" : "-c" | |
31 end | |
32 | |
33 def editor? | |
34 !ENV["EDITOR"].nil? && !ENV["EDITOR"].empty? | |
35 end | |
36 | |
37 def shell? | |
38 !ENV["SHELL"].nil? && !ENV["SHELL"].empty? | |
39 end | |
40 | |
41 def exists?(name) | |
42 File.exists?(project(name)) | |
43 end | |
44 | |
45 def project(name) | |
46 projects = Dir.glob("#{root}/**/*.yml") | |
47 project_file = projects.detect { |project| project =~ /^#{name}.yml$/ } | |
48 project_file || "#{root}/#{name}.yml" | |
49 end | |
50 | |
51 def template | |
52 "#{File.dirname(__FILE__)}/assets/template.erb" | |
53 end | |
54 | |
55 def wemux_template | |
56 "#{File.dirname(__FILE__)}/assets/wemux_template.erb" | |
57 end | |
58 | |
59 def configs | |
60 Dir["#{Pmuxinator::Config.root}/*.yml"].sort.map do |path| | |
61 File.basename(path, ".yml") | |
62 end | |
63 end | |
64 | |
65 def validate(name) | |
66 unless Pmuxinator::Config.exists?(name) | |
67 puts "Project #{name} doesn't exist." | |
68 exit! | |
69 end | |
70 | |
71 config_path = Pmuxinator::Config.project(name) | |
72 | |
73 yaml = begin | |
74 YAML.load(File.read(config_path)) | |
75 rescue SyntaxError, StandardError | |
76 puts "Failed to parse config file. Please check your formatting." | |
77 exit! | |
78 end | |
79 | |
80 project = Pmuxinator::Project.new(yaml) | |
81 | |
82 unless project.windows? | |
83 puts "Your project file should include some windows." | |
84 exit! | |
85 end | |
86 | |
87 unless project.name? | |
88 puts "Your project file didn't specify a 'project_name'" | |
89 exit! | |
90 end | |
91 | |
92 project | |
93 end | |
94 end | |
95 end | |
96 end |