Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Last active September 11, 2026 20:58
Show Gist options
  • Select an option

  • Save ramirez7/626b9466f49dcb7d1b3df53e871536d5 to your computer and use it in GitHub Desktop.

Select an option

Save ramirez7/626b9466f49dcb7d1b3df53e871536d5 to your computer and use it in GitHub Desktop.
stfu.sh - Google-Search-AI-mode-coded script to remove all new comments from a git diff. Run it after your AI codes to shut it up.
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p gnused perl git
# Discover all unstaged Haskell and TypeScript files with modifications
mapfile -t FILES < <(git diff --name-only | grep -E '\.(hs|ts)$')
if [ ${#FILES[@]} -eq 0 ]; then
echo "No modified Haskell (.hs) or TypeScript (.ts) files found in git status."
exit 0
fi
echo "Found ${#FILES[@]} modified source file(s). Processing..."
for FILE in "${FILES[@]}"; do
[ ! -f "$FILE" ] && continue
# Determine file extension and set regex patterns accordingly
EXT="${FILE##*.}"
if [ "$EXT" = "hs" ]; then
echo " -> Stripping new Haskell comments from: $FILE"
# Match single-line (--) and multi-line ({- ... -})
COMMENT_REGEX='(--.*|{-[\s\S]*?-})'
elif [ "$EXT" = "ts" ]; then
echo " -> Stripping new TypeScript comments from: $FILE"
# Match single-line (//) and multi-line (/* ... */)
COMMENT_REGEX='(\/\/.*|\/\*[\s\S]*?\*\/)'
else
continue
fi
export COMMENT_REGEX
# 1. Extract and erase the language-specific comment blocks precisely
git diff -U0 "$FILE" | grep '^[+][^+]' | gsed 's/^[+]//' | perl -0777 -pe '
my $regex = $ENV{COMMENT_REGEX};
@comments = m/$regex/g;
$_ = join("\n", @comments);
' | while IFS= read -r comment_chunk || [ -n "$comment_chunk" ]; do
[ -z "$comment_chunk" ] && continue
export COMMENT_CHUNK="$comment_chunk"
perl -i -0777 -pe '
my $chunk = $ENV{COMMENT_CHUNK};
s/\Q$chunk\E\n?//g;
' "$FILE"
done
# 2. Collapse consecutive redundant blank lines to clean up voids left by the diff
perl -i -0777 -pe 's/\n{3,}/\n\n/g' "$FILE"
# 3. Clean up any trailing blank spaces at the very end of the file
perl -i -0777 -pe 's/\n+\z/\n/' "$FILE"
done
echo "Done! All newly added comments have been completely stripped."
@ramirez7

Copy link
Copy Markdown
Author

seems to work

armandoramirez@beeg-ram main % gd
diff --git a/exe/Main.hs b/exe/Main.hs
index 60d904e..806374c 100644
--- a/exe/Main.hs
+++ b/exe/Main.hs
@@ -2,7 +2,14 @@ module Main where

 import qualified MyLib (someFunc)

+-- NEW COMMENT
 main :: IO ()
 main = do
   putStrLn "Hello, Haskell!"
   MyLib.someFunc
+
+{-
+
+MORE COMMENT
+
+-}
diff --git a/test.ts b/test.ts
index a922b77..c3e98ce 100644
--- a/test.ts
+++ b/test.ts
@@ -1 +1,7 @@
+//HI
 2 + 2
+
+/*
+WORLD
+LOLlol
+*/
armandoramirez@beeg-ram main % type stfu
stfu is an alias for ~/work/gists/stfu.sh/stfu.sh
armandoramirez@beeg-ram main % stfu
warning: unknown experimental feature 'repl-flake'
fetching github input 'github:NixOS/nixpkgs/nixpkgs-unstable'
Found 2 modified source file(s). Processing...
 -> Stripping new Haskell comments from: exe/Main.hs
 -> Stripping new TypeScript comments from: test.ts
Done! All newly added comments have been completely stripped.
armandoramirez@beeg-ram main % gd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment