Last active
June 26, 2022 22:42
-
-
Save ivan/13edbae669481308c08ae5a4db2cb686 to your computer and use it in GitHub Desktop.
Print an outline of Rust code in the current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Print an outline of Rust code in the current directory | |
| GRAY=$(tput setaf 7) | |
| PURPLE=$(tput setaf 5) | |
| BOLD=$(tput bold) | |
| CLEAR=$(tput sgr0) | |
| rg --sort path --heading --no-line-number --glob '*.rs' '\b(fn|struct|enum|trait|impl|mod|macro_rules)\b' |\ | |
| # Indent each line | |
| sed -r -s 's,^,\t,g' |\ | |
| # Dedent each filename and make it bold purple | |
| sed -r -s "s,^\t(.*\.rs)$,$BOLD$PURPLE\1$CLEAR,g" |\ | |
| # Bold the identifier and make everything else gray | |
| sed -r -s "s,\b((fn|struct|enum|trait|impl|mod|macro_rules!) +)([^ <\(]+)(.*),$GRAY\1$CLEAR$BOLD\3$CLEAR$GRAY\4$CLEAR,g" |\ | |
| # Convert each tab to 4 spaces | |
| sed -r -s 's,\t, ,g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment