Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaushikgopal/9674859 to your computer and use it in GitHub Desktop.
Save kaushikgopal/9674859 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Get line number for file that needs to be added
argument = ARGV.pop
# do a git status and get the second argument
# filename = %x[git status -s | sed -n '#{argument}p'].split(" ", 2)[1]
filename = %x[git status -s | awk 'NR==#{argument}'].split(" ", 2)[1] # using awk baby!
system("git diff-index --quiet HEAD -- || clear; git diff --patch-with-stat #{filename}")
# here's a nice git status command to show you the file changed along with the line number
# git status -s | awk '{print NR,$0}' | awk -F: '{ print "\033[1;30m" $1 "\033[0m" }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment