Class: Aka::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/aka.rb

Instance Method Summary collapse

Instance Method Details

#cleanObject



345
346
347
# File 'lib/aka.rb', line 345

def clean
  Aka.cleanup
end

#configObject



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 !options[:nounalias] && result == true
    Aka.reload_dot_file if result == true && !options[: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 options[:group]
    Aka.change_alias_group_name_with(Aka.parseARGS(args), options[:group])
  else
    if args
      values = args.split('=')
      if values.size > 1
        truth, _alias = Aka.search_alias_return_alias_tokens(args)
        if truth == true
          if options[:name]
            # Aka.remove(_alias) #remove that alias
            Aka.edit_alias_name(values[1], _alias) # edit that alias
            Aka.reload_dot_file unless options[:noreload]
          else
            # Aka.remove(_alias) #remove that alias
            Aka.edit_alias_command(values[1], _alias) # edit that alias
            Aka.reload_dot_file unless options[: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 options[: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 options[: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 options[: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 options[:group]
    Aka.search_alias_with_group_name(options[: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), options[: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 && !options[: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 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 && !options[:no]
  true
end

#groupsObject



361
362
363
# File 'lib/aka.rb', line 361

def groups
  Aka.list_all_groups
end

#initObject



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 options[:count] && options[:count] < 1
    Aka.setup
  else
    Aka.setZSHRC if options[:zshrc]
    Aka.setBASHRC if options[:bashrc]
    Aka.setBASH if options[:bash]

    Aka.showConfig if options[:config]
    Aka.setPath(options[:dotfile], 'dotfile') if options[:dotfile]
    Aka.setPath(options[:history], 'history') if options[:history]
    Aka.setPath(options[:home], 'home') if options[:home]
    Aka.setPath(options[:install], 'install') if options[:install]
    Aka.setPath(options[:profile], 'profile') if options[:profile]
    Aka.setPath(options[:list], 'list') if options[:list]
    Aka.setPath(options[:usage], 'usage') if options[:usage]
    Aka.setPath(options[:remote], 'remote') if options[: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(options[:number], args.to_i, options[:group]) # user input
  else
    value = Aka.readYML("#{CONFIG_PATH}")['list']
    if value.class == Integer
      Aka.showlast(options[:number], value.to_i, options[:group])
    else
      puts "List value is not defined in #{CONFIG_PATH}"
      Aka.showlast(options[:number], 50, options[:group])
    end
  end
  Aka.print_all_helpful_statement
  Aka.reload_dot_file unless options[: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 options[:load]
    Aka.export(arg, options[:load], options[:force])
  elsif options[:save]
    Aka.import(options[:save])
  else
    if options[:group] && File.exist?('proj.aka')
      Aka.list_all_groups_in_proj_aka
    elsif options[: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

#setupObject



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 options[: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 options[:least] && args
      Aka.showUsage(args.to_i, true)
    else
      Aka.showUsage(args.to_i)
    end
  else
    if options[: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 options[:clear]
end

#versionObject



377
378
379
# File 'lib/aka.rb', line 377

def version
  puts Aka::VERSION
end

#whereObject



369
370
371
# File 'lib/aka.rb', line 369

def where
  puts Aka.readYML("#{CONFIG_PATH}")['dotfile']
end