From 7abf2d6f13498fa7376bd61ba08198e3c34cc2eb Mon Sep 17 00:00:00 2001
From: Gary Guo <gary.guo@lowrisc.org>
Date: Wed, 3 Jan 2024 11:50:10 +0000
Subject: [PATCH] Reduce help message verbosity if invoked by direnv

---
 flake.nix | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/flake.nix b/flake.nix
index 41ddac53..746bf7e0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -86,16 +86,19 @@
           # FIXME This works on Ubuntu, may not on other distros. FIXME
           export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive
 
-          export PS1='labenv(HiPEAC) (ibex-demo-system) \$ '
+          if [ -z "$DIRENV_IN_ENVRC" ]; then
+            export PS1='labenv(HiPEAC) (ibex-demo-system) \$ '
+
+            echo
+            echo
+            cat ./data/lowrisc.art
+          fi
 
-          echo
-          echo
-          cat ./data/lowrisc.art
           echo "---------------------------------------------------"
           echo "Welcome to the 'ibex-demo-system' nix environment!"
           echo "---------------------------------------------------"
 
-          helpstr=$(cat <<'EOF'
+          helpme(){ cat <<'EOF'
 
           Build ibex software :
               mkdir sw/c/build && pushd sw/c/build && cmake ../ && make && popd
@@ -115,17 +118,24 @@
           Connect gdb to a running program on the FPGA (In a different terminal to the OpenOCD instance):
               riscv32-unknown-elf-gdb -ex "target extended-remote localhost:3333" ./sw/c/build/demo/hello_world/demo
 
+          EOF
+
+            if [ -z "$DIRENV_IN_ENVRC" ]; then
+              cat <<'EOF'
           To leave the environment:
               exit
 
           EOF
-          )
-          helpme(){ echo "$helpstr"; }
+            fi
+          }
+
           helpme
 
-          echo
-          echo "Run 'helpme' in your shell to see this message again."
-          echo
+          if [ -z "$DIRENV_IN_ENVRC" ]; then
+            echo
+            echo "Run 'helpme' in your shell to see this message again."
+            echo
+          fi
         '';
       };
       formatter = pkgs.alejandra;