Skip to content

Instantly share code, notes, and snippets.

@alkuzad
Created April 28, 2015 09:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alkuzad/dd729aca36a810892772 to your computer and use it in GitHub Desktop.
Save alkuzad/dd729aca36a810892772 to your computer and use it in GitHub Desktop.
Rubocop check only files that are changed
# Needs showlinennum in ~/bin folder of user, change it to some more general
# solution if you have showlinenum in path
if [ "$1" == "" ];then
rev="HEAD"
else
rev="$1"
fi
if [ -e ~/bin/showlinenum.awk ]; then
git diff $rev --diff-filter=ACM --name-only | while read file;do rubocop $file | awk "/$(echo "$(echo $file | tr "/" '.'):("$((git diff -U0 HEAD $file | ~/bin/showlinenum.awk | awk -F':' '/^[0-9]+:/ {print $1}' | tr '\n' '|') | rev | cut -c 2- | rev)")")/ {print}";done | grep -v " C:"
else
echo "~/bin/showlinenum.awk does not exist. Install it from https://github.com/jay/showlinenum"
fi
@hiendinhngoc
Copy link

@alkuzad hi, where should the script be placed? I put it in bash file, but got error bad config at line 4

@alkuzad
Copy link
Author

alkuzad commented Jan 1, 2023

@alkuzad hi, where should the script be placed? I put it in bash file, but got error bad config at line 4

Do you think the script location will impact this error?

@hiendinhngoc
Copy link

Do you think the script location will impact this error?

Honestly, I am not sure where should I place the script 😢 . I supposed it should in the bashrc file(I am using Ubuntu), then I put it in and got the error.

@alkuzad
Copy link
Author

alkuzad commented Jan 1, 2023

It is already bash script, bashrc is for configuration, not whole scripts...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment