Class: SkipDirCli

Inherits:
Thor
  • Object
show all
Defined in:
bin/sd

Constant Summary collapse

LOCATION =
"#{Dir.home}/.skipdir"

Instance Method Summary collapse

Instance Method Details

#add(name, dir = Dir.pwd) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'bin/sd', line 11

def add(name, dir=Dir.pwd)
  if name.strip.split(' ').size > 1
    STDERR.puts 'Spaces not allowed for aliases'
  end
  puts "Adding alias '#{name}' => '#{dir}'"

  @skipdir = SkipDir.new(LOCATION)
  @skipdir.add name, dir
end

#go(name) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'bin/sd', line 22

def go(name)
  @skipdir = SkipDir.new(LOCATION)
  dir = @skipdir.get name
  if dir.nil?
    STDERR.puts "Alias #{name} not found"
  else
    Dir.chdir(dir)
  end
end

#listObject



33
34
35
36
37
38
39
# File 'bin/sd', line 33

def list()
  @skipdir = SkipDir.new(LOCATION)
  max_key_len = @skipdir.all.map { |entry| entry[0].size }.max
  @skipdir.all.each do |key, value|
    puts key + ([" "] * (max_key_len + 1 - key.size)).join + value
  end
end

#remove(name) ⇒ Object



42
43
44
45
46
47
# File 'bin/sd', line 42

def remove(name)
  @skipdir = SkipDir.new(LOCATION)
  unless @skipdir.remove(name)
    STDERR.puts "No alias was found"
  end
end