Class: Tmuxinator::Cli
- Includes:
- Util
- Defined in:
- lib/tmuxinator/cli.rb
Constant Summary collapse
- COMMANDS =
{ commands: "Lists commands available in tmuxinator", completions: "Used for shell completion", new: "Create a new project file and open it in your editor", open: "Alias of new", start: "Start a tmux session using a project's tmuxinator config, with an optional [ALIAS] for project reuse", debug: "Output the shell commands that are generated by tmuxinator", copy: "Copy an existing project to a new project and open it in your editor", delete: "Deletes given project", implode: "Deletes all tmuxinator projects", version: "Display installed tmuxinator version", doctor: "Look for problems in your configuration", list: "Lists all tmuxinator projects" }
Instance Method Summary collapse
- #commands(shell = nil) ⇒ Object
- #completions(arg) ⇒ Object
- #copy(existing, new) ⇒ Object
- #debug(name, custom_name = nil) ⇒ Object
- #delete(project) ⇒ Object
- #doctor ⇒ Object
- #implode ⇒ Object
- #list ⇒ Object
- #new(name) ⇒ Object
- #start(name, custom_name = nil) ⇒ Object
- #version ⇒ Object
Methods included from Util
Instance Method Details
#commands(shell = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tmuxinator/cli.rb', line 24 def commands(shell = nil) out = if shell == "zsh" COMMANDS.map do |command, desc| "#{command}:#{desc}" end.join("\n") else COMMANDS.keys.join("\n") end puts out end |
#completions(arg) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/tmuxinator/cli.rb', line 38 def completions(arg) if %w(start open copy delete).include?(arg) configs = Tmuxinator::Config.configs puts configs end end |
#copy(existing, new) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tmuxinator/cli.rb', line 91 def copy(existing, new) existing_config_path = Tmuxinator::Config.project(existing) new_config_path = Tmuxinator::Config.project(new) exit!("Project #{existing} doesn't exist!") unless Tmuxinator::Config.exists?(existing) if !Tmuxinator::Config.exists?(new) or yes?("#{new} already exists, would you like to overwrite it?", :red) say "Overwriting #{new}" if Tmuxinator::Config.exists?(new) FileUtils.copy_file(existing_config_path, new_config_path) end Kernel.system("$EDITOR #{new_config_path}") end |
#debug(name, custom_name = nil) ⇒ Object
82 83 84 85 |
# File 'lib/tmuxinator/cli.rb', line 82 def debug(name, custom_name = nil) project = Tmuxinator::Config.validate(name, custom_name ) puts project.render end |
#delete(project) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tmuxinator/cli.rb', line 109 def delete(project) if Tmuxinator::Config.exists?(project) config = "#{Tmuxinator::Config.root}/#{project}.yml" if yes?("Are you sure you want to delete #{project}?(y/n)", :red) FileUtils.rm(config) say "Deleted #{project}" end else exit!("That file doesn't exist.") end end |
#doctor ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tmuxinator/cli.rb', line 151 def doctor say "Checking if tmux is installed ==> " yes_no Tmuxinator::Config.installed? say "Checking if $EDITOR is set ==> " yes_no Tmuxinator::Config.editor? say "Checking if $SHELL is set ==> " yes_no Tmuxinator::Config.shell? end |
#implode ⇒ Object
125 126 127 128 129 130 |
# File 'lib/tmuxinator/cli.rb', line 125 def implode if yes?("Are you sure you want to delete all tmuxinator configs?", :red) FileUtils.remove_dir(Tmuxinator::Config.root) say "Deleted all tmuxinator projects." end end |
#list ⇒ Object
136 137 138 139 140 |
# File 'lib/tmuxinator/cli.rb', line 136 def list say "tmuxinator projects:" print_in_columns Tmuxinator::Config.configs end |
#new(name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tmuxinator/cli.rb', line 52 def new(name) config = Tmuxinator::Config.project(name) unless Tmuxinator::Config.exists?(name) template = Tmuxinator::Config.default? ? Tmuxinator::Config.default : Tmuxinator::Config.sample erb = Erubis::Eruby.new(File.read(template)).result(binding) File.open(config, "w") { |f| f.write(erb) } end Kernel.system("$EDITOR #{config}") || doctor end |
#start(name, custom_name = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tmuxinator/cli.rb', line 67 def start(name, custom_name = nil) project = Tmuxinator::Config.validate(name, custom_name ) if project.deprecations.any? project.deprecations.each { |deprecation| say deprecation, :red } puts print "Press ENTER to continue." STDIN.getc end Kernel.exec(project.render) end |
#version ⇒ Object
145 146 147 |
# File 'lib/tmuxinator/cli.rb', line 145 def version say "tmuxinator #{Tmuxinator::VERSION}" end |