scripts: git-ignore, git-root
needs to be improved
This commit is contained in:
29
.local/bin/git-root
Executable file
29
.local/bin/git-root
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
git_root() {
|
||||
git rev-parse --show-toplevel
|
||||
}
|
||||
|
||||
# get the relative path of current path according to root of repo
|
||||
git_root_relative() {
|
||||
rel=$(git rev-parse --show-prefix)
|
||||
if [ -z "$rel" ]; then
|
||||
# git rev-parse --show-prefix will output empty string when we are in the root dir
|
||||
echo "."
|
||||
else
|
||||
echo "$rel"
|
||||
fi
|
||||
}
|
||||
|
||||
if test $# -eq 0; then
|
||||
git_root
|
||||
else
|
||||
case "$1" in
|
||||
-r|--relative)
|
||||
git_root_relative
|
||||
;;
|
||||
*)
|
||||
git_root
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
Reference in New Issue
Block a user