This is a small bash script that searches in the current directory for TODO, FIXME, and NOTE
in your source code and displays your matched code with syntax highlighting.
$ work
- first line is broken
| #!/bin/bash | |
| cache1=$(mktemp) | |
| cache2=$(mktemp) | |
| language=$(mktemp) | |
| LINE_WIDTH=$(tput cols) | |
| LINE_WIDTH=$((LINE_WIDTH - 5)) | |
| function highlight() { | |
| lang=$(head -n 1 "$language") | |
| paste -d "" "$cache1" <( | |
| bat --color always \ | |
| --plain \ | |
| --pager never \ | |
| --language "$lang" \ | |
| "$cache2" | |
| ) | |
| echo -n > "$cache1" | |
| echo -n > "$cache2" | |
| } | |
| function hline() { | |
| printf "────%s" "$1" | |
| printf "%${LINE_WIDTH}s" | rg --color never " " --replace "─" | |
| } | |
| rg --context 3 --heading --line-number '(TODO|FIXME|NOTE).*' . | | |
| while IFS="-" read -r line_number code | |
| do | |
| if [ -z "$line_number" ] | |
| then | |
| highlight | |
| hline "┼" | |
| elif [ "$line_number" -eq "$line_number" ] 2> /dev/null | |
| then | |
| printf "%4d│\n" "$line_number" >> "$cache1" | |
| echo "$code" >> "$cache2" | |
| else | |
| IFS=":" read -r line_number code <<< "$line_number" | |
| if [ -z "$code" ] | |
| then | |
| printf "\e[1A" | |
| hline "┴" | |
| hline "┬" | |
| printf "\e[1m │%s:\e[K\e[0m\n" "$line_number" | |
| hline "┼" | |
| echo "${line_number##*.}" > "$language" | |
| else | |
| line_number=$(sed 's/\x1b\[[0-9;]*m//g' <<< "$line_number") | |
| printf "\e[1;43m%4d\e[1;49m│%s\e[0m\n" "$line_number" "$code" >> "$cache1" | |
| echo >> "$cache2" | |
| fi | |
| fi | |
| done | |
| highlight | |
| hline "┴" | |
| rm "$cache1" | |
| rm "$cache2" | |
| rm "$language" |