This is a very simple python script that removes the PWD and username from a command output.
I wrote it to copy and paste Python errors to ChatGPT without giving it all of my personal data.
Put this into ~/bin/censor and have ~/bin on PATH:
#!/usr/bin/env python3
import sys
import os
import re
LOGIN = os.getlogin()
RE_LOGIN = re.compile(re.escape(LOGIN.lower()), re.IGNORECASE)
PWD = os.getcwd()
CENSORED = "[censored]"
for line in sys.stdin:
line = line.replace(PWD, CENSORED)
line = RE_LOGIN.sub(CENSORED, line)
print(line, end="")Then you can do something like this:
$ cat test.py 130 ↵
#!/usr/bin/env python3
def main() -> None:
raise Exception("Foo")
if __name__ == '__main__':
main()
$ ./test.py 2>&1 | censor
Traceback (most recent call last):
File "[censored]/./test.py", line 9, in <module>
main()
~~~~^^
File "[censored]/./test.py", line 5, in main
raise Exception("Foo")
Exception: FooNote: Always remember to redirect stderr to stdout first (2>&1)!