Last active
April 6, 2023 04:59
-
-
Save abcdlsj/ca4a26aae1710f3018cdb5a2f2fd2750 to your computer and use it in GitHub Desktop.
This file contains 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
function search_todo() { | |
# This function will search for TODO items in the file(s) modified by the specified user. | |
# Usage: search_todo <username> [--exclude <pattern>]... [search-dir] | |
if [[ $# -lt 1 ]]; then | |
echo "Usage: search_todo <username> [--exclude <pattern>]... [search-dir]" | |
return 1 | |
fi | |
local USERNAME=$1 | |
shift | |
# Parse the exclude patterns | |
local SEARCH_DIR="." | |
local exclude_pattern=false | |
local EXCLUDE_PATTERN | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
--exclude) | |
exclude_pattern=true | |
;; | |
*) | |
if $exclude_pattern; then | |
EXCLUDE_PATTERN="$1" | |
exclude_pattern=false | |
else | |
SEARCH_DIR="$1" | |
fi | |
;; | |
esac | |
shift | |
done | |
# Use git ls-files to get a list of all non-directory files in the specified search directory, excluding files that match the specified exclude pattern(s) | |
local FILES=$(git ls-files --exclude-standard --cached --modified --others -- "$SEARCH_DIR/" | grep -vE "/$" | grep -vE "$EXCLUDE_PATTERN" | tr '\n' ' ') | |
# Use git blame to get a list of TODO lines modified by the user, excluding lines that match the specified file patterns | |
local TODO_LINES=$(git blame --show-email --show-name --show-number -s -f -L '/TODO/' --author="$USERNAME" $FILES | grep -E "^\w+\W+[A-Z]+\w+.*TODO" | sed "s/^[^0-9]*//" | sort -u) | |
# Use awk to extract the filename and line number of each TODO line | |
echo "$TODO_LINES" | awk '{print $1 ":" $2}' | |
# Use ag to search for TODO items in the file(s) containing the affected line numbers | |
local FILENAMES=$(echo "$TODO_LINES" | awk -F: '{print $1}' | sort -u) | |
grep "TODO" $FILENAMES | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment