feat: better git-root and git-home for exec

This commit is contained in:
eneller
2024-03-04 23:07:24 +01:00
parent 8392c8d3b7
commit 0bf29844d1
4 changed files with 26 additions and 8 deletions

View File

@@ -2,10 +2,9 @@
diff-words = diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+' diff-words = diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+'
st = status st = status
cm = commit cm = commit
home = rev-parse --show-toplevel
exec = "!exec "
# TODO use git-delta # TODO use git-delta
# those are just for tab completion # the following aliases are defined as bash scripts, only here for completion
home = "!git-home"
root = "!git-root" root = "!git-root"
ignore = "!git-ignore" ignore = "!git-ignore"
[color] [color]

11
.local/bin/git-home Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# git script that will return the path of the current git project.
# can be used to execute commands in the directory as well.
# uses git >= 2.13 --show-superproject-working-tree
path=$(git rev-parse --show-toplevel);
[[ $? -ne 0 ]] && exit $?
if [ $# -eq 0 ]; then
echo "$path";
else
cd $path && exec "$@";
fi

View File

@@ -1,9 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# git script that will return the root path of a git project, even if currently in a submodule. # git script that will return the root path of a git project, even if currently in a submodule.
# can be used to execute commands in the root directory as well.
# uses git >= 2.13 --show-superproject-working-tree # uses git >= 2.13 --show-superproject-working-tree
superproject=$(git rev-parse --show-superproject-working-tree) path=$(git rev-parse --show-superproject-working-tree)
if [ -z "$superproject" ]; then [[ $? -ne 0 ]] && exit $?
git rev-parse --show-toplevel; if [ -z "$path" ]; then
else path=$(git rev-parse --show-toplevel);
echo "$superproject"; fi
if [ $# -eq 0 ]; then
echo "$path";
else
cd $path && exec "$@";
fi fi

3
.local/bin/i3.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
source ~/.profile
i3