Skip to content

Instantly share code, notes, and snippets.

@fin-ger
Last active May 30, 2019 11:56
Show Gist options
  • Save fin-ger/e8289e1dc7fc4b070aaa269e3b5d58ac to your computer and use it in GitHub Desktop.
Save fin-ger/e8289e1dc7fc4b070aaa269e3b5d58ac to your computer and use it in GitHub Desktop.
Display TODOs, FIXMEs, and NOTEs from your projects source code

Display work in your project

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.

Dependencies

Usage

$ work

Bugs

  • 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment