Skip to content

Instantly share code, notes, and snippets.

@hammeiam
Created September 3, 2015 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hammeiam/5a06c53d22f8a1267e89 to your computer and use it in GitHub Desktop.
Save hammeiam/5a06c53d22f8a1267e89 to your computer and use it in GitHub Desktop.
### Quick Diff
### A bash function that lets you see a diff without tabbing through all of your project folders
###
### Imagine you changed some number of files in your project and wanted to view the git diff of one of them
### but your project is deepy nested, so you have to type in the first letters and tab through each folder
### eg: folder_a/folder_b/folder_c/folder_d/my_file.js
###
### Instead of doing all that, just use `$ qdif my_file` to search your modified folders and show a diff of the first result
function qdif() {
local ISGIT="$(git rev-parse --is-inside-work-tree 2>&1)"
if [ "$ISGIT" = "true" ]; then
local SEARCH="$(git status --porcelain | grep -e "\(${1}\)" -m 1)"
local FILEPATH=${SEARCH:2}
if [ -n "$FILEPATH" ]; then
git diff $FILEPATH
else
echo "Error: No files match ‘${1}’"
fi
else
echo "Error: Not a git repo"
fi
}
@hammeiam
Copy link
Author

hammeiam commented Sep 5, 2015

Seems to get tripped up on files that have been renamed

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