Module: Aliasing

Defined in:
lib/aliasing.rb,
lib/aliasing/cli.rb,
lib/aliasing/history.rb,
lib/aliasing/version.rb

Defined Under Namespace

Classes: CLI, History

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.make_alias(name, command, location) ⇒ Object



7
8
9
10
11
12
# File 'lib/aliasing.rb', line 7

def make_alias(name, command, location)
  existing_alias = verify_uniqueness_of name
  return puts "Error: #{name} is already a bash alias name for #{existing_alias}" if existing_alias

  %x[echo 'alias #{name}="#{command}"' >> #{location}]
end

.verify_uniqueness_of(alias_name) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/aliasing.rb', line 14

def verify_uniqueness_of(alias_name)
  alias_list = %x[source ~/.profile && source ~/.bash_profile && alias].split "\n"
  aliases = {}
  alias_list.each { |a|
    match = a.match(/(.*)=(.*)/)
    aliases[match[1]] = match[2]
  }
  return aliases[alias_name]
end