Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

--machine + --fortune modes

  • Loading branch information...
commit 21fcb554ccbf8d28a455cce4317542786d439975 1 parent 4bc95c5
Walter Stanish authored
Showing with 54 additions and 0 deletions.
  1. +5 −0 README.md
  2. +49 −0 taoup
5 README.md
View
@@ -9,6 +9,11 @@ To get it running, make sure you have `ruby` and `gem` installed, then run:
After that, it should work fine.
+There are two modes other than standard invocation, `--machine` which drops any
+ANSI colors from the output, and `--fortune` which converts the wisdom to an
+assumed imitation of the fortune format (untested, may need header/footer
+massaging or character set tweaking).
+
To have it display on login, you could try something like this in your `.profile`:
```
49 taoup
View
@@ -4,6 +4,55 @@ require 'ansi/code'
include ANSI::Code
+# ... but optionally make sure ANSI escape sequences are filtered out
+zero_colors=false
+fortunify=false
+if ARGV[0] == '--machine' then
+ ARGV.shift
+ zero_colors = true
+elsif ARGV[0] == '--fortune' then
+ zero_colors = true
+ fortunify = true
+else
+ if `which tput` then
+ colors = `tput colors`
+ if colors.chop == "-1" then
+ zero_colors = true
+ end
+ end
+end
+if zero_colors then
+ alias :puts_old :puts
+ alias :print_old :print
+ if fortunify==false then
+ # normal drop-ansi mode
+ def puts(*args)
+ args = args.join('')
+ args.gsub!(/\x1b\[[;0-9]*[a-zA-Z]/,'') # ie. remove ansi sequences
+ puts_old(args)
+ end
+ def print(*args)
+ args = args.join('')
+ args.gsub!(/\x1b\[[;0-9]*[a-zA-Z]/,'') # ie. remove ansi sequences
+ print_old(args)
+ end
+ else
+ # fortune mode
+ def puts(*args)
+ args = args.join('')
+ args.gsub!(/\x1b\[[;0-9]*[a-zA-Z]/,'') # ie. remove ansi sequences
+ if not args.match(/^--/) and not args.match(/^$/) then
+ puts_old(args + "\n%\n")
+ end
+ end
+ def print(*args)
+ args = args.join('')
+ args.gsub!(/\x1b\[[;0-9]*[a-zA-Z]/,'') # ie. remove ansi sequences
+ print_old(args)
+ end
+ end
+end
+
# spatial / architectural
puts '------------ Eric S. Raymond, The Art of Unix Programming --------------------------'
Please sign in to comment.
Something went wrong with that request. Please try again.