class Aka::Base

Public Instance Methods

clean() click to toggle source
# File lib/aka.rb, line 345
def clean
  Aka.cleanup
end
config() click to toggle source
# File lib/aka.rb, line 353
def config
  Aka.showConfig
end
destroy(*args) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
groups() click to toggle source
# File lib/aka.rb, line 361
def groups
  Aka.list_all_groups
end
init() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
setup() click to toggle source
# 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) click to toggle source
# 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
version() click to toggle source
# File lib/aka.rb, line 377
def version
  puts Aka::VERSION
end
where() click to toggle source
# File lib/aka.rb, line 369
def where
  puts Aka.readYML("#{CONFIG_PATH}")['dotfile']
end