Module: Mark

Defined in:
lib/mark/jump.rb,
lib/mark/main.rb,
lib/mark/error.rb,
lib/mark/label.rb,
lib/mark/storage.rb,
lib/mark/version.rb

Constant Summary collapse

CWD =
Dir.pwd
STORAGE_UNIT =
"#{ENV['HOME']}/.mark"
VERSION =
'0.0.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.marksObject

Returns the value of attribute marks.



7
8
9
# File 'lib/mark/storage.rb', line 7

def marks
  @marks
end

Class Method Details

.error!(command, *argv) ⇒ Object



4
5
6
# File 'lib/mark/error.rb', line 4

def self.error!(command, *argv)
  puts "Command \"#{command}\" not found: [#{command} #{argv.join(' ')}]"
end

.jump(label, *argv) ⇒ Object



5
6
7
8
9
# File 'lib/mark/jump.rb', line 5

def jump(label, *argv)
  target = @marks[label]

  puts "cd #{target}"
end

.label(label, *argv) ⇒ Object



7
8
9
# File 'lib/mark/label.rb', line 7

def label(label, *argv)
  @marks[label] = argv.first || CWD
end

.loadObject



9
10
11
12
13
14
# File 'lib/mark/storage.rb', line 9

def load
  return @marks = [] unless File.exist?(STORAGE_UNIT)

  f = File.open(STORAGE_UNIT)
  @marks = YAML.load(f.read)
end

.process(command, *argv) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mark/main.rb', line 4

def self.process(command, *argv)
  self.load

  case command
  when 'label'
    self.label(*argv)
  when 'jump'
    self.jump(*argv)
  else
    self.error!(command, *argv)
  end

  self.save
end

.saveObject



16
17
18
19
20
# File 'lib/mark/storage.rb', line 16

def save
  f = File.open(STORAGE_UNIT, 'w')

  YAML.dump(@marks ||= [], f)
end