tretry added. less-tries.

This commit is contained in:
Denis Knauf 2013-02-17 14:58:58 +01:00
parent 989deed03b
commit e1513810e2
2 changed files with 16 additions and 8 deletions

View file

@ -14,7 +14,7 @@ install: truckle
mkdir -p $(D)$(BIN_PREFIX) mkdir -p $(D)$(BIN_PREFIX)
install -m 0755 truckle $(D)$(BIN_PREFIX)/truckle install -m 0755 truckle $(D)$(BIN_PREFIX)/truckle
for c in `./truckle --list-commands`; do ln -fs truckle $(D)$(BIN_PREFIX)/truckle-$${c} ; done for c in `./truckle --list-commands`; do ln -fs truckle $(D)$(BIN_PREFIX)/truckle-$${c} ; done
for c in trdo tresume; do ln -fs truckle $(D)$(BIN_PREFIX)/$${c} ; done for c in trdo tresume tretry; do ln -fs truckle $(D)$(BIN_PREFIX)/$${c} ; done
README.md: truckle README.pre.md README.md: truckle README.pre.md
( cat README.pre.md ; ./truckle --help ) > README.md.tmp ( cat README.pre.md ; ./truckle --help ) > README.md.tmp

22
truckle
View file

@ -277,7 +277,7 @@ class Truckle
end end
def initialize argv0 def initialize argv0
ENV['LESS'] = "-FR #{ENV['LESS']}" ENV['LESS'] = "-FLRBb-1 #{ENV['LESS']}"
@argv0 = argv0 @argv0 = argv0
@exename = File.basename argv0 @exename = File.basename argv0
@ -497,10 +497,21 @@ EOF
end end
end end
class Shortcut class Shortcut < Hash
attr_reader :argv0 attr_reader :argv0
def initialize argv0 def initialize argv0
@argv0 = argv0 @argv0 = argv0
prepare
end
def on cmd, &exe
self[cmd.to_s.to_sym] = exe
end
def prepare
on( :trdo) { exec :truckle, :do, *ARGV }
on( :tresume) { exec :truckle, :resume, *ARGV }
on( :tretry) { exec :truckle, :retry, *ARGV }
end end
def exec exe, *args def exec exe, *args
@ -510,11 +521,8 @@ class Shortcut
def run def run
exe = File.basename @argv0 exe = File.basename @argv0
case exe.to_sym exe = self[exe.to_sym]
when :trdo then exec :truckle, :do, *ARGV exe.call if exe
when :tresume then exec :truckle, :resume, *ARGV
when :tretry then exec :truckle, :retry, *ARGV
end
end end
alias call run alias call run