-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitadd
More file actions
executable file
·32 lines (27 loc) · 962 Bytes
/
gitadd
File metadata and controls
executable file
·32 lines (27 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# git-add a modified file by its position on the git status list
# usage: alias this script to gitadd or whatever, then on a git repo folder
# run gitadd 1 3 to git-add the first and the third modified file of the git status list
indexesToGitAdd=$*
gitStatus=($(git ls-files -m))
# verbose
# echo $indexesToGitAdd
# printf -- '%s\n' "${gitStatus[@]}"
# exit if git does not have modified files
if [ ${#gitStatus[@]} -eq 0 ]; then
echo "There are no modified files in git"
exit 1
fi
for fileIndex in $indexesToGitAdd; do
# start from 1 instead of 0
((fileIndex=fileIndex-1))
# if this fileindex exists on the list of modified files
if test $fileIndex -ge 0 -a "${gitStatus[fileIndex]+isset}"
then
# add this file
echo "Adding " ${gitStatus[$fileIndex]}
git add ${gitStatus[$fileIndex]}
else
echo 'No modified file in position' $(($fileIndex+1))
fi;
done