about summary refs log tree commit diff
path: root/pkgs/tools/misc/taoup
diff options
context:
space:
mode:
authorZak B. Elep <zakame@zakame.net>2021-09-05 02:54:01 +0800
committerZak B. Elep <zakame@zakame.net>2021-09-20 18:08:16 +0800
commit6c6435090571c5255ea9c596995dff85ff079d11 (patch)
treeb28f2014762a5f14bb984a83573b0fe64ead6213 /pkgs/tools/misc/taoup
parentd050e7dfc3af49c97f740319c15dd33de56598a5 (diff)
taoup: init at 1.1.14
Diffstat (limited to 'pkgs/tools/misc/taoup')
-rw-r--r--pkgs/tools/misc/taoup/cachefile.patch35
-rw-r--r--pkgs/tools/misc/taoup/default.nix62
-rw-r--r--pkgs/tools/misc/taoup/help.patch21
-rw-r--r--pkgs/tools/misc/taoup/tput.patch17
4 files changed, 135 insertions, 0 deletions
diff --git a/pkgs/tools/misc/taoup/cachefile.patch b/pkgs/tools/misc/taoup/cachefile.patch
new file mode 100644
index 0000000000000..7c92b2180c67e
--- /dev/null
+++ b/pkgs/tools/misc/taoup/cachefile.patch
@@ -0,0 +1,35 @@
+--- a/taoup-fortune	2021-09-05 12:16:23.408295791 +0800
++++ b/taoup-fortune	2021-09-05 13:02:52.286440200 +0800
+@@ -5,31 +5,9 @@
+ #        - https://github.com/matheuss/parrotsay
+ #        - https://github.com/busyloop/lolcat
+ #        - https://github.com/sckott/cowsay (enhanced version)
+-dir=`dirname "${BASH_SOURCE[0]}"`
+-
+-# USER ALERT!!! @ronjouch complained about execution speed at https://github.com/globalcitizen/taoup/issues/11 
+-#  ... therefore we add caching ... therefore first ensure we have an up to date cache via one of ...
+-# md5sum
+-if [ `which md5sum 2>/dev/null` ]; then
+- MD5SUM=`md5sum ${dir}/taoup | cut -d ' ' -f1`
+-# md5
+-elif [ `which md5 2>/dev/null` ]; then
+- MD5SUM=`md5 -q ${dir}/taoup | cut -d ' ' -f1`
+-# openssl
+-elif [ `which openssl 2>/dev/null` ]; then
+- MD5SUM=`cat ${dir}/taoup | openssl md5 | grep -o '[[:xdigit:]][[:xdigit:]]*$' |cut -d '=' -f2- |cut -c 2-`
+-# ruby
+-elif [ `which ruby 2>/dev/null` ]; then
+- MD5SUM=`ruby -rdigest/md5 -e"puts Digest::MD5.file'${dir}/taoup'"`
+-fi
+ 
+ # determine cachefile name
+-cachefile=${dir}/.taoup-fortune.cache.${MD5SUM}
+-
+-# create if necessary
+-if [ ! -r $cachefile ]; then
+- ${dir}/taoup $@ >${cachefile}
+-fi
++cachefile=@out@/lib/taoup/cache
+ 
+ # handle all classes of society
+ if [ `which cowsay 2>/dev/null` ]; then
diff --git a/pkgs/tools/misc/taoup/default.nix b/pkgs/tools/misc/taoup/default.nix
new file mode 100644
index 0000000000000..969df132be82d
--- /dev/null
+++ b/pkgs/tools/misc/taoup/default.nix
@@ -0,0 +1,62 @@
+{ lib, stdenv, fetchFromGitHub, ruby, bash, ncurses }:
+let
+  rubyEnv = ruby.withPackages (ps: with ps; [ ansi ]);
+in
+stdenv.mkDerivation rec {
+  pname = "taoup";
+  version = "1.1.14";
+
+  src = fetchFromGitHub {
+    owner = "globalcitizen";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "1gs6f66fg1l504riw481nvyw7cchbr3qjks4mkj2qb3s9147ad8j";
+  };
+
+  buildInputs = [ rubyEnv bash ncurses ];
+
+  patches = [
+    # Pre-create a cache within this derivation
+    ./cachefile.patch
+    # Remove the need to test for `tput`, depend on ncurses directly
+    ./tput.patch
+    # Fix the script name in `taoup --help` output
+    ./help.patch
+  ];
+
+  postPatch = ''
+    substituteInPlace taoup \
+     --subst-var-by ncurses ${ncurses} \
+     --subst-var-by pname ${pname}
+    substituteInPlace taoup-fortune \
+      --subst-var-by out $out \
+      --replace "/bin/bash" "${bash}/bin/bash"
+  '';
+
+  dontConfigure = true;
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p $out/{bin,lib/taoup}
+
+    cp taoup $out/lib/taoup
+    cat > $out/bin/taoup <<EOF
+    #!${bash}/bin/bash
+    exec ${rubyEnv}/bin/ruby "$out/lib/taoup/taoup" "\$@"
+    EOF
+    chmod +x $out/bin/taoup
+
+    # Populate the cache created by cachedir.patch above
+    $out/bin/taoup > $out/lib/taoup/cache
+
+    cp taoup-fortune $out/bin
+    chmod +x $out/bin/taoup-fortune
+  '';
+
+  meta = {
+    description = "The Tao of Unix Programming (Ruby-powered ANSI colored fortunes)";
+    homepage = "https://github.com/globalcitizen/taoup";
+    license = lib.licenses.gpl3Only;
+    maintainers = [ lib.maintainers.zakame ];
+  };
+}
diff --git a/pkgs/tools/misc/taoup/help.patch b/pkgs/tools/misc/taoup/help.patch
new file mode 100644
index 0000000000000..e8b5f91f3c8a1
--- /dev/null
+++ b/pkgs/tools/misc/taoup/help.patch
@@ -0,0 +1,21 @@
+--- a/taoup	2021-09-07 16:45:00.000000000 +0800
++++ b/taoup	2021-09-07 16:46:00.000000000 +0800
+@@ -7,12 +7,12 @@
+ 
+ # show help if requested
+ if ARGV[0] == '--help' or ARGV[0] == '-h' then
+- puts "usage: " + $0 + " [arguments]"
+- puts "       " + $0 + "                    Display all fortunes and sections."
+- puts "       " + $0 + " < --help | -h >    This help."
+- puts "       " + $0 + " --whitetrash       Convert ANSI colors for light/white terminals."
+- puts "       " + $0 + " --machine          Remove ANSI colors."
+- puts "       " + $0 + " --fortune          Convert output to fortune format (and lose colors)."
++ puts "usage: " + "@pname@" + " [arguments]"
++ puts "       " + "@pname@" + "                    Display all fortunes and sections."
++ puts "       " + "@pname@" + " < --help | -h >    This help."
++ puts "       " + "@pname@" + " --whitetrash       Convert ANSI colors for light/white terminals."
++ puts "       " + "@pname@" + " --machine          Remove ANSI colors."
++ puts "       " + "@pname@" + " --fortune          Convert output to fortune format (and lose colors)."
+  exit(0)
+ end
+ # ... but optionally make sure ANSI escape sequences are filtered out
diff --git a/pkgs/tools/misc/taoup/tput.patch b/pkgs/tools/misc/taoup/tput.patch
new file mode 100644
index 0000000000000..5c82024885bf0
--- /dev/null
+++ b/pkgs/tools/misc/taoup/tput.patch
@@ -0,0 +1,17 @@
+--- a/taoup	2021-09-05 12:43:48.334615538 +0800
++++ b/taoup	2021-09-05 12:55:07.631617799 +0800
+@@ -26,11 +26,9 @@
+  zero_colors = true
+  fortunify = true
+ else
+- if `which tput` then
+-  colors = `tput colors`
+-  if colors.chop == "-1" then
+-   zero_colors = true
+-  end
++ colors = `@ncurses@/bin/tput colors`
++ if colors.chop == "-1" then
++  zero_colors = true
+  end
+ end
+ if ARGV[0] == '--whitetrash' then