Class: Aka::Base
- Inherits:
-
Thor
- Object
- Thor
- Aka::Base
- Defined in:
- lib/aka.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #config ⇒ Object
- #destroy(*args) ⇒ Object
- #download(url) ⇒ Object
- #edit(args) ⇒ Object
- #find(*args) ⇒ Object
- #function(args) ⇒ Object
- #generate(args) ⇒ Object
- #groups ⇒ Object
- #init ⇒ Object
- #list(args = nil) ⇒ Object
- #proj(arg = nil) ⇒ Object
- #setup ⇒ Object
- #usage(args = nil) ⇒ Object
- #version ⇒ Object
- #where ⇒ Object
Instance Method Details
#clean ⇒ Object
345 346 347 |
# File 'lib/aka.rb', line 345 def clean Aka.cleanup end |
#config ⇒ Object
353 354 355 |
# File 'lib/aka.rb', line 353 def config Aka.showConfig end |
#destroy(*args) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/aka.rb', line 149 def destroy(*args) args.each_with_index do |value, _index| result = Aka.remove(value) Aka.unalias_the(value) if ![:nounalias] && result == true Aka.reload_dot_file if result == true && ![:no] end true end |
#download(url) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/aka.rb', line 32 def download url # open('image.png', 'wb') do |file| # file << open('http://example.com/image.png').read # end system("curl -O #{url}") end |
#edit(args) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/aka.rb', line 207 def edit(args) if [:group] Aka.change_alias_group_name_with(Aka.parseARGS(args), [:group]) else if args values = args.split('=') if values.size > 1 truth, _alias = Aka.search_alias_return_alias_tokens(args) if truth == true if [:name] # Aka.remove(_alias) #remove that alias Aka.edit_alias_name(values[1], _alias) # edit that alias Aka.reload_dot_file unless [:noreload] else # Aka.remove(_alias) #remove that alias Aka.edit_alias_command(values[1], _alias) # edit that alias Aka.reload_dot_file unless [:noreload] end else Aka.error_statement("Alias '#{args}' cannot be found.") end else puts "this is passed in #{args}" truth, _alias, command, group = Aka.search_alias_return_alias_tokens_with_group(args) if truth == true if [:name] input = ask "Enter a new alias for command '#{command}'?\n" if yes? 'Please confirm the new alias? (y/N)' Aka.remove(_alias) # remove that alias Aka.edit_alias_name_with_group(input, command, group) # edit that alias Aka.reload_dot_file unless [:noreload] end else input = ask "Enter a new command for alias '#{args}'?\n" if yes? 'Please confirm the new command? (y/N)' Aka.remove(_alias) # remove that alias Aka.edit_alias_command_with_group(input, _alias, group) # edit that alias Aka.reload_dot_file unless [:noreload] end end else Aka.error_statement("Alias '#{args}' cannot be found") end end end # if args end # end else no group option end |
#find(*args) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/aka.rb', line 189 def find(*args) if [:group] Aka.search_alias_with_group_name([:group]) else args.each_with_index do |value, _index| Aka.search_alias_return_alias_tokens(value) end end true end |
#function(args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aka.rb', line 45 def function args puts "function" result = Aka.add_a_function(Aka.parseARGS(args), [:group]) # result = false # if options[:last] && args # result = Aka.add_with_group(Aka.add_last_command(Aka.parseARGS(args))) # else # result = Aka.add_with_group(Aka.parseARGS(args), options[:group]) # end Aka.reload_dot_file if result == true && ![:no] true end |
#generate(args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/aka.rb', line 131 def generate(args) result = false if [:last] && args result = Aka.add_with_group(Aka.add_last_command(Aka.parseARGS(args))) else result = Aka.add_with_group(Aka.parseARGS(args), [:group]) end Aka.reload_dot_file if result == true && ![:no] true end |
#groups ⇒ Object
361 362 363 |
# File 'lib/aka.rb', line 361 def groups Aka.list_all_groups end |
#init ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/aka.rb', line 321 def init if [:count] && [:count] < 1 Aka.setup else Aka.setZSHRC if [:zshrc] Aka.setBASHRC if [:bashrc] Aka.setBASH if [:bash] Aka.showConfig if [:config] Aka.setPath([:dotfile], 'dotfile') if [:dotfile] Aka.setPath([:history], 'history') if [:history] Aka.setPath([:home], 'home') if [:home] Aka.setPath([:install], 'install') if [:install] Aka.setPath([:profile], 'profile') if [:profile] Aka.setPath([:list], 'list') if [:list] Aka.setPath([:usage], 'usage') if [:usage] Aka.setPath([:remote], 'remote') if [:remote] end end |
#list(args = nil) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/aka.rb', line 263 def list(args = nil) Aka.print_title('System Alias') if !args.nil? Aka.showlast([:number], args.to_i, [:group]) # user input else value = Aka.readYML("#{CONFIG_PATH}")['list'] if value.class == Integer Aka.showlast([:number], value.to_i, [:group]) else puts "List value is not defined in #{CONFIG_PATH}" Aka.showlast([:number], 50, [:group]) end end Aka.print_all_helpful_statement Aka.reload_dot_file unless [:no] end |
#proj(arg = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/aka.rb', line 98 def proj(arg = nil) if [:load] Aka.export(arg, [:load], [:force]) elsif [:save] Aka.import([:save]) else if [:group] && File.exist?('proj.aka') Aka.list_all_groups_in_proj_aka elsif [:group] && !File.exist?('proj.aka') Aka.error_statement('The proj.aka is missing. Please run [aka proj --load <name_of_group>] to generate proj.aka file') else if File.exist?('proj.aka') if content = File.open('proj.aka').read Aka.print_title('Project Alias') content_array = Aka.product_content_array(content) answer_count = Aka.print_the_aliases(content_array) Aka.print_helpful_statement(answer_count) end else Aka.error_statement('The proj.aka is missing. Please run [aka proj --load <name_of_group>] to generate proj.aka file') end end end # end of when end |
#setup ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/aka.rb', line 163 def setup if [:reset] && File.exist?("#{CONFIG_PATH}") Aka.remove_autosource FileUtils.rm_r("#{CONFIG_PATH}") puts "#{CONFIG_PATH} is removed" end if File.exist?("#{CONFIG_PATH}") puts ".aka exists at #{CONFIG_PATH}" puts 'Please run [aka setup --reset] to remove .aka and setup again' else Aka.setup_config # create and setup .config file Aka.setup_aka # put value in .config file puts 'setting up autosource' Aka.setup_autosource # create, link source file puts "Congratulation, aka is setup at #{CONFIG_PATH}" end end |
#usage(args = nil) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/aka.rb', line 284 def usage(args = nil) if args if [:least] && args Aka.showUsage(args.to_i, true) else Aka.showUsage(args.to_i) end else if [:least] value = Aka.readYML("#{CONFIG_PATH}")['usage'] Aka.showlast(value.to_i, true) # this is unsafe else value = Aka.readYML("#{CONFIG_PATH}")['usage'] Aka.howlast(value.to_i) # this is unsafe end end puts 'clear the dot history file' if [:clear] end |
#version ⇒ Object
377 378 379 |
# File 'lib/aka.rb', line 377 def version puts Aka::VERSION end |
#where ⇒ Object
369 370 371 |
# File 'lib/aka.rb', line 369 def where puts Aka.readYML("#{CONFIG_PATH}")['dotfile'] end |