Class: Terminitor::Cli

Inherits:
Thor
  • Object
show all
Includes:
Runner, Thor::Actions
Defined in:
lib/terminitor/cli.rb

Constant Summary

Constants included from Runner

Runner::TERM_PATH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Runner

#capture_core, #config_path, #execute_core, #find_core, #github_clone, #github_repo, #grab_comment_for_file, #open_in_editor, #resolve_path, #return_error_message

Class Method Details

.source_rootObject



8
# File 'lib/terminitor/cli.rb', line 8

def self.source_root; File.expand_path('../../',__FILE__); end

Instance Method Details

#createObject



82
83
84
# File 'lib/terminitor/cli.rb', line 82

def create
  invoke :edit, [], options
end

#delete(project = "") ⇒ Object



89
90
91
92
# File 'lib/terminitor/cli.rb', line 89

def delete(project="")
  path = config_path(project, options[:syntax].to_sym)
  remove_file path
end

#edit(project = "") ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/terminitor/cli.rb', line 47

def edit(project="")
  syntax = project.empty? ? 'term' : options[:syntax] # force Termfile to use term syntax
  path =  config_path(project, syntax.to_sym)
  if options[:capture] && !File.exists?(path)
    # capture settings of currently opened windows and tabs
    if syntax == 'term'
      if core = capture_core(RUBY_PLATFORM)
        term = core.new().capture_settings
        (f = File.new(path, "w") << term).close
      else
        say("No suitable core found!")
        return
      end
    else
      say "Terminal settings can be captured only to DSL format."
      return
    end
  else 
    # use standard template
    template "templates/example.#{syntax}.tt", path, :skip => true
  end
  open_in_editor(path,options[:editor])
end

#fetch(username, project) ⇒ Object



25
26
27
# File 'lib/terminitor/cli.rb', line 25

def fetch(username, project)
  github_repo username, project, options
end

#initObject



38
39
40
# File 'lib/terminitor/cli.rb', line 38

def init
  empty_directory TERM_PATH
end

#listObject



30
31
32
33
34
35
# File 'lib/terminitor/cli.rb', line 30

def list
  say "Global scripts: \n"
  Dir.glob("#{TERM_PATH}/*[^~]").each do |file|
    say "  * #{File.basename(file, '.term')} #{grab_comment_for_file(file)}"
  end
end

#open(project = "") ⇒ Object



74
75
76
77
# File 'lib/terminitor/cli.rb', line 74

def open(project="")
  say "'open' is now deprecated. Please use 'edit' instead"
  invoke :edit, [project], options
end

#setup(project = "") ⇒ Object



18
19
20
# File 'lib/terminitor/cli.rb', line 18

def setup(project="")
  execute_core :setup!, project
end

#start(project = "") ⇒ Object



12
13
14
# File 'lib/terminitor/cli.rb', line 12

def start(project="")
  execute_core :process!, project
end

#updateObject



95
96
97
98
99
100
101
102
103
# File 'lib/terminitor/cli.rb', line 95

def update
  if File.exists?(old_path = File.join(ENV['HOME'],'.terminitor/'))
    FileUtils.cp_r "#{old_path}/.", TERM_PATH
    FileUtils.rm_r old_path
    say "Terminitor has updated your global folder to ~/.config/terminitor/ !"
  else
    say "Old .terminitor/ global path doesn't exist. cool."
  end
end