Skip to content

Instantly share code, notes, and snippets.

@serrasqueiro
Last active December 27, 2021 00:43
Show Gist options
  • Select an option

  • Save serrasqueiro/b9591fac25f741b87c8560de5153457b to your computer and use it in GitHub Desktop.

Select an option

Save serrasqueiro/b9591fac25f741b87c8560de5153457b to your computer and use it in GitHub Desktop.
List files in "svn status" style-alike
#!/bin/sh
#
# (c)2020 Henrique Moreira
# git_svnst.sh
# The following line proves you will only show lines starting with '??'
# echo -e "ab AB-123\n?? DE-567" | sed 's/^?? \([A-Za-z0-9].*\)/:: \1/'
show_svnst ()
{
local WHERE=$(git rev-parse --show-prefix)
[ "$WHERE" = "" ] && WHERE=.
sed 's/^?? \([A-Za-z0-9].*\)/? \1/' | \
grep "^.. $WHERE"
return $?
}
show_svnst_2 ()
{
local WHERE=$(git rev-parse --show-prefix)
local EXP
if [ "$WHERE" = "" ]; then
show_svnst $*
return $?
fi
EXP="$(echo $WHERE | sed 's/\//\\\//g')"
sed 's/^?? \([A-Za-z0-9].*\)/? \1/' | \
grep "^.. $WHERE" | \
sed "s/ $EXP/ /" | \
grep .
git ls-files $* | awk '{print ". ", $0}'
return $?
}
case $1 in
"")
git status --porcelain | show_svnst
RES=$?
;;
st)
# Shows only the relative path
shift
git status --porcelain | show_svnst_2 $*
RES=$?
;;
esac
# Exit status
exit $RES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment