Created
September 3, 2015 07:55
-
-
Save hammeiam/5a06c53d22f8a1267e89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to get tripped up on files that have been renamed