Last active
January 18, 2019 09:37
Bash script to add a file by its index to the git staging area.
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
#!/usr/bin/bash | |
git_status=`git status --porcelain` | |
if [[ $# -ne 1 ]] | |
then | |
# Get modified files and their index | |
# nl: numbers the lines | |
echo "$git_status" | nl | |
exit 0 | |
fi | |
if ! [[ "$1" =~ ^[0-9]+$ ]] | |
then | |
echo "Sorry integers only" | |
exit 1 | |
fi | |
line=`echo "$git_status" | sed "${1}q;d"` | |
# remove first 4 chars. E.g. M and some spaces | |
file=`echo "$line" | cut -c3-` | |
git add $file | |
git status -s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment