diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-08-20 20:12:44 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-08-20 20:12:44 +0100 |
commit | adb6f21dd3f2db293e0791c3a9ea5621da07cd38 (patch) | |
tree | cf7a051b27bfad0c4c455be51f064dfbc457dbf0 | |
parent | 220f602da1f6735f3b180c10a74313ec76c04959 (diff) |
[goforthanddie] user commands
-rwxr-xr-x | goforthanddie.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/goforthanddie.rb b/goforthanddie.rb index 176df46..e81d534 100755 --- a/goforthanddie.rb +++ b/goforthanddie.rb @@ -23,7 +23,7 @@ def handle(str, stack, markermode, markerautoclear, destructiveprint) exit if str.nil? str.split.each do |token| case token - when /[+-][0-9]+/ + when /\A[+-]?[0-9]+\Z/ stack.push(token.to_i) when "+", "add", "plus" a, b = stack.pop(2) @@ -141,6 +141,15 @@ def handle(str, stack, markermode, markerautoclear, destructiveprint) getlist(stack, markermode, markerautoclear) when "m", "mark" stack.push(:mark) + when /\A'(.*)/ + file = File.readlines(File.join(ENV['HOME'], ".goforthanddie")) + cmd = file.map { |line| line.split(?:) }.to_h[$1] + if cmd.nil? + puts "You haven't told me how to #{$1}!" + else + markermode, markerautoclear, destructiveprint = + handle(cmd, stack, markermode, markerautoclear, destructiveprint) + end when "~s", "~stack" puts stack.join(" ") when "~mm", "~markermode" |