globalcitizen / taoup Goto Github PK
View Code? Open in Web Editor NEWThe Tao of Unix Programming (Ruby-powered ANSI colored fortunes)
License: GNU General Public License v3.0
The Tao of Unix Programming (Ruby-powered ANSI colored fortunes)
License: GNU General Public License v3.0
So I wrote a bash
function (or is it awk
, really?) to do so:
just_one_taoup() {
# ChatGPT4 wrote 99% of this. I preserved the conversation with it about it: https://gist.github.com/pmarreck/339fb955a74caed692b439038c9c1c9d
needs taoup please install taoup: https://github.com/globalcitizen/taoup && \
taoup | awk -v seed=`date +%N` 'BEGIN{srand(seed)} /^-{3,}/{header=$0; next} !/^$/{lines[count++]=$0; headers[count-1]=header} END{randIndex=int(rand()*count); print headers[randIndex]; print lines[randIndex]}'
}
(my needs
dependency-check function, for anyone curious:)
needs() {
local bin=$1;
shift;
command -v $bin > /dev/null 2>&1 || {
echo "I require $bin but it's not installed or in PATH; $*" 1>&2;
return 1
}
}
It would be nice if this was built-in, though. Instead of outputting immediately with puts
, you could assemble all the quote data into an array (including headers), count the number of quotes (excluding headers), pick a random number between 0 and (that count - 1), find that quote through iteration (skipping headers but noting the last one seen), and then output the last header seen and the quote.
gem install ansi
You can puts this in a bundle file or have the taoup check for it's existence and install it
begin
gem "ansi"
rescue Gem::LoadError
`gem install ansi`
end
Can we help out users of non-dark terminals by adding a flag to use different colors? I wanna read but it hurts my eyes to do so:D
Are you planning on creating a macOS build and releasing it on homebrew?
when i checked whether shuf
was installed on my machine with type shuf
or which shuf
, both of them confirmed that shuf is /usr/bin/shuf
.
but as this log below showed what i observed as i executed bash -x taoup-fortune 2>&1
, the program seemed to assume that shuf
was unavailable.
++ dirname taoup-fortune
+ dir=.
++ which md5sum
+ '[' /usr/bin/md5sum ']'
++ md5sum ./taoup
++ cut -d ' ' -f1
+ MD5SUM=260d2085d6fdc421c1faf9505dcf2898
+ cachefile=./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898
+ '[' '!' -r ./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898 ']'
++ which cowsay
+ '[' /usr/bin/cowsay ']'
++ shuf -e
+ '[' ']'
++ echo test
++ sort -R
+ '[' test ']'
+ cat ./.taoup-fortune.cache.260d2085d6fdc421c1faf9505dcf2898
+ grep -v '^---'
+ sort -R
+ head -n 1
+ cowsay -f eyes -n
+ head -n 2
+ tail -n 1
< �[37mBetween Plan 9 and Erlang we missed a bus somewhere.�[0m�[30m�[1m - @jacquesm�[0m�[0m >
+ echo ''
+ cowsay -f eyes
+ tail -n 10
+ sed 's/^/�[0;32;40m/'
�[0;32;40m \
�[0;32;40m .::!!!!!!!:.
�[0;32;40m .!!!!!:. .:!!!!!!!!!!!!
�[0;32;40m ~~~~!!!!!!. .:!!!!!!!!!UWWW$$$
�[0;32;40m :$$NWX!!: .:!!!!!!XUWW$$$$$$$$$P
�[0;32;40m $$$$$##WX!: .<!!!!UW$$$$" $$$$$$$$#
�[0;32;40m $$$$$ $$$UX :!!UW$$$$$$$$$ 4$$$$$*
�[0;32;40m ^$$$B $$$$\ $$$$$$$$$$$$ d$$R"
�[0;32;40m "*$bd$$$$ '*$$$$$$$$$$$o+#"
�[0;32;40m """" """""""
+ echo '�(B�[m'
�(B�[m
apparently the test for shuf
's functionality in the program is by testing whether shuf -e 2>/dev/null
doesn't return a null string, which it would as no strings or files were passed into the command.
even if the test was to verify whether -e
was a valid option for the machine's shuf
, that would be redundant as -e
was implemented in the first public version of shuf
, per the git history of the program in coreutils
.
a solution could be to adapt the test for cowsay
's existence to shuf
, such as which shuf 2>/dev/null
.
Hi,
as far as I can tell, a comment indicating that the script is in utf-8 is needed:
$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
$ ./taoup > /dev/null
./taoup:313: invalid multibyte char (US-ASCII)
./taoup:313: invalid multibyte char (US-ASCII)
./taoup:313: syntax error, unexpected $end, expecting '}'
...d{ " - Douglas Hofstadter, 'Gödel, Escher, Bach: An Eternal...
...
$ git diff
diff --git a/taoup b/taoup
index 4b20c0d..ac3cdc0 100755
--- a/taoup
+++ b/taoup
@@ -1,4 +1,5 @@
#!/usr/bin/ruby
+# encoding: utf-8
require 'ansi/code'
$ ./taoup > /dev/null
(No error output)
FYI, my locale settings:
$ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
I like to run taoup at shell startup.
But after a pass of cleanup/optimization, I ended up removing it, after noticing it takes a big chunk of my shell's startup time:
[ronj@t ~]$ time taoup-fortune
< Law of Communications: The inevitable result of improved and enlarged communications between different levels in a hierarchy is a vastly increased area of misunderstanding. >
real 0m0,305s
user 0m0,237s
sys 0m0,119s
For me on a recent laptop with ruby 2.6.3p62, it takes between 0.2 and 0.4s, which is a noticeable delay, especially given the small task it accomplishes.
Anyway, thanks for the collection and frequent additions 🙂.
EDIT workaround: why always calling ruby at each call when you can simply dumping the fortunes to a static cache and shuffle that:
After git clone,
./taoup | grep -v '^---' > taoup.txt
Then taoup-fortune
can be as simple as a call to unix shuf
:
#!/usr/bin/env sh
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
shuf -n 1 "$dir/taoup.txt"
Hi
./taoup-fortune triggers an error on Mac OSX with ZSH
sort: invalid option -- R
Try `sort --help' for more information.
So I was doing some research into this particular message, and I have a few concerns:
Line 1307 in 40f7a68
I couldn't find any groups of electrical engineers that advertised this as their motto. From what I understand, this isn't actually a motto at all, but just a really mediocre old joke from list servs.
Engineering has plenty of inappropriate acronyms and jokes. Should we add resistor color codes as well? I can prepare a pr for that if you like.
Are you supposed to consult your doctor if your computer works for longer than four hours? Asking for a friend.
Hi, thanks for this excellent piece of software! 🎉
I just want to ask for clarification WRT GPL3 licensing - is this going to use GPL3 only, or GPL3 or any later version? I ask because I'm packaging this for Nix, see NixOS/nixpkgs#136751, and even when checking the taoup
script itself I didn't find the recommended notice to guide me to knowing under what GPL3 license this software is under.
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.