Class: Tmuxinator::Cli

Inherits:
Object
  • Object
show all
Extended by:
Helper
Defined in:
lib/tmuxinator/cli.rb

Class Method Summary collapse

Methods included from Helper

confirm!, exit!

Class Method Details

.copy(*args) ⇒ Object Also known as: c



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tmuxinator/cli.rb', line 65

def copy *args
  @copy = args.shift
  @name = args.shift
  @config_to_copy = "#{root_dir}#{@copy}.yml"

  exit!("Project #{@copy} doesn't exist!")             unless File.exists?(@config_to_copy)
  exit!("You must specify a name for the new project") unless @name

  file_path = "#{root_dir}#{@name}.yml"

  if File.exists?(file_path)
    confirm!("#{@name} already exists, would you like to overwrite it? (type yes or no):") do
      FileUtils.rm(file_path)
      puts "Overwriting #{@name}"
    end
  end
  open @name
end

.delete(*args) ⇒ Object Also known as: d



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/tmuxinator/cli.rb', line 85

def delete *args
  puts "warning: passing multiple arguments to delete will be ignored" if args.size > 1
  filename  = args.shift
  file_path = "#{root_dir}#{filename}.yml"

  if File.exists?(file_path)
    confirm!("Are you sure you want to delete #{filename}? (type yes or no):") do
      FileUtils.rm(file_path)
      puts "Deleted #{filename}"
    end
  else
    exit! "That file doesn't exist."
  end
end

.doctorObject



128
129
130
131
132
133
134
135
# File 'lib/tmuxinator/cli.rb', line 128

def doctor
  print "  checking if tmux is installed ==> "
  puts system("which tmux > /dev/null") ?  "Yes" : "No"
  print "  checking if $EDITOR is set ==> "
  puts ENV['EDITOR'] ? "Yes" : "No"
  print "  checking if $SHELL is set ==> "
  puts ENV['SHELL'] ? "Yes" : "No"
end

.implode(*args) ⇒ Object Also known as: i



101
102
103
104
105
106
107
# File 'lib/tmuxinator/cli.rb', line 101

def implode *args
  exit!("delete_all doesn't accapt any arguments!") unless args.empty?
  confirm!("Are you sure you want to delete all tmuxinator configs? (type yes or no):") do
    FileUtils.remove_dir(root_dir)
    puts "Deleted #{root_dir}"
  end
end

.list(*args) ⇒ Object Also known as: l, ls



110
111
112
113
114
115
116
117
118
# File 'lib/tmuxinator/cli.rb', line 110

def list *args
  verbose = args.include?("-v")
  puts "tmuxinator configs:"
  Dir["#{root_dir}**"].each do |path|
    next unless verbose || File.extname(path) == ".yml"
    path = path.gsub(root_dir, '').gsub('.yml','') unless verbose
    puts "    #{path}"
  end
end

.method_missing(method, *args, &block) ⇒ Object



149
150
151
152
153
# File 'lib/tmuxinator/cli.rb', line 149

def method_missing method, *args, &block
  start method if File.exists?("#{root_dir}#{method}.yml")
  puts "There's no command or project '#{method}' in tmuxinator"
  usage
end

.open(*args) ⇒ Object Also known as: o, new, n

Open a config file, it’s created if it doesn’t exist already.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tmuxinator/cli.rb', line 49

def open *args
  exit!("You must specify a name for the new project") unless args.size > 0
  puts "warning: passing multiple arguments to open will be ignored" if args.size > 1
  @name = args.shift
  config_path = "#{root_dir}#{@name}.yml"
  unless File.exists?(config_path)
    template = File.exists?(user_config) ? user_config : sample_config
    erb      = ERB.new(File.read(template)).result(binding)
    tmp      = File.open(config_path, 'w') {|f| f.write(erb) }
  end
  system("$EDITOR #{config_path}")
end

.run(*args) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/tmuxinator/cli.rb', line 9

def run *args
  if args.empty?
    self.usage
  else
    self.send(args.shift, *args)
  end
end

.start(*args) ⇒ Object Also known as: s

build script and run it



138
139
140
141
142
143
144
145
146
# File 'lib/tmuxinator/cli.rb', line 138

def start *args
  exit!("You must specify a name for the new project") unless args.size > 0
  puts "warning: passing multiple arguments to open will be ignored" if args.size > 1
  project_name = args.shift
  config_path = "#{root_dir}#{project_name}.yml"
  config = Tmuxinator::ConfigWriter.new(config_path).render
  # replace current proccess by running compiled tmux config
  exec(config)
end

.usageObject Also known as: help, h

print the usage string, this is a fall through method.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tmuxinator/cli.rb', line 18

def usage
  puts %{
  Usage: tmuxinator ACTION [Arg] 
  or 
  tmuxinator [project_name]

  ACTIONS:
  start [project_name]
start a tmux session using project's tmuxinator config
  open [project_name]
create a new project file and open it in your editor
  copy [source_project] [new_project]
copy source_project project file to a new project called new_project
  delete [project_name]
deletes the project called project_name
  implode
deletes all existing projects!
  list [-v]
list all existing projects
  doctor
    look for problems in your configuration
  help
shows this help document
  version
shows tmuxinator version number
}
end

.versionObject Also known as: v



122
123
124
125
# File 'lib/tmuxinator/cli.rb', line 122

def version
  system("cat #{File.dirname(__FILE__) + '/../../VERSION'}")
  puts
end