Class: Tmuxinator::Cli
- Inherits:
-
Object
- Object
- Tmuxinator::Cli
- Extended by:
- Helper
- Defined in:
- lib/tmuxinator/cli.rb
Class Method Summary collapse
- .copy(*args) ⇒ Object (also: c)
- .delete(*args) ⇒ Object (also: d)
- .doctor ⇒ Object
- .implode(*args) ⇒ Object (also: i)
- .list(*args) ⇒ Object (also: l, ls)
- .method_missing(method, *args, &block) ⇒ Object
-
.open(*args) ⇒ Object
(also: o, new, n)
Open a config file, it’s created if it doesn’t exist already.
- .start(*args) ⇒ Object
- .update_scripts ⇒ Object
-
.usage ⇒ Object
(also: help, h)
print the usage string, this is a fall through method.
- .version ⇒ Object (also: v)
Methods included from Helper
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 |
.doctor ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/tmuxinator/cli.rb', line 137 def doctor print " cheking if tmux is installed ==> " puts system("which tmux > /dev/null") ? "Yes" : "No" print " cheking if $EDITOR is set ==> " puts ENV['EDITOR'] ? "Yes" : "No" print " cheking if $SHELL is set ==> " puts ENV['SHELL'] ? "Yes" : "No" puts %{ make sure you have this line in your ~/.bashrc file: [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator } 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
153 154 155 156 |
# File 'lib/tmuxinator/cli.rb', line 153 def method_missing method, *args, &block puts "There's no command called #{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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tmuxinator/cli.rb', line 47 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 FileUtils.mkdir_p(root_dir+"scripts") config_path = "#{root_dir}#{@name}.yml" unless File.exists?(config_path) template = File.exists?(user_config) ? user_config : "#{File.dirname(__FILE__)}/assets/sample.yml" erb = ERB.new(File.read(template)).result(binding) tmp = File.open(config_path, 'w') {|f| f.write(erb) } end system("$EDITOR #{config_path}") update_scripts end |
.start(*args) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/tmuxinator/cli.rb', line 9 def start *args if args.empty? self.usage else self.send(args.shift, *args) end end |
.update_scripts ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/tmuxinator/cli.rb', line 128 def update_scripts Dir["#{root_dir}*.tmux"].each {|p| FileUtils.rm(p) } aliases = [] Dir["#{root_dir}*.yml"].each do |path| aliases << Tmuxinator::ConfigWriter.new(path).write! end Tmuxinator::ConfigWriter.write_aliases(aliases) end |
.usage ⇒ Object 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 |
# File 'lib/tmuxinator/cli.rb', line 18 def usage puts %{ Usage: tmuxinator ACTION [Arg] ACTIONS: 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 update_scripts re-create the tmux scripts and aliases from the configs implode deletes all existing projects! list [-v] list all existing projects doctor look for problems in your configuration help shows this help document version } end |
.version ⇒ Object 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 |