Skip to content

Commit

Permalink
Add -m flag to git-modified, to only show locally-modified files
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jan 5, 2022
1 parent d533513 commit 7227492
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion git-modified
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ usage () {
echo ' $ vim `git modified`' >&2
echo >&2
echo "Options:" >&2
echo "-m Modified files only (excludes untracked files)" >&2
echo "-i Consider the index, too" >&2
echo "-u Print only files that are unmerged (files with conflicts)" >&2
echo "-q Be quiet, only return with 0 exit code when files are modified" >&2
echo "-h Show this help" >&2
}

modified=0
index=0
unmerged=0
quiet=0
while getopts iuqh flag; do
while getopts miuqh flag; do
case "$flag" in
m) modified=1;;
i) index=1;;
u) unmerged=1;;
q) quiet=1;;
Expand Down Expand Up @@ -88,6 +91,10 @@ modified_unmerged () {
status | grep -Ee '^(U.|.U)' | cut -c 4- | fix_rename_notation | make_relative
}

modified_only_locally () {
status | cut -c 2- | grep -Ee '^M' | cut -c 3- | fix_rename_notation | make_relative
}

modified_locally () {
status | cut -c 2- | grep -vEe '^[ ]' | cut -c 3- | fix_rename_notation | make_relative
}
Expand All @@ -108,6 +115,8 @@ if [ -z "$commit" ]; then
modified_unmerged | fail_if_empty
elif [ $index -eq 1 ]; then
modified_in_index | fail_if_empty
elif [ $modified -eq 1 ]; then
modified_only_locally | fail_if_empty
else
modified_locally | fail_if_empty
fi
Expand Down

0 comments on commit 7227492

Please sign in to comment.