From 0bf29844d1bfd723e71f920b3cbc1a0dada2077d Mon Sep 17 00:00:00 2001 From: eneller Date: Mon, 4 Mar 2024 23:07:24 +0100 Subject: [PATCH] feat: better git-root and git-home for exec --- .gitconfig | 5 ++--- .local/bin/git-home | 11 +++++++++++ .local/bin/git-root | 15 ++++++++++----- .local/bin/i3.sh | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100755 .local/bin/git-home create mode 100644 .local/bin/i3.sh diff --git a/.gitconfig b/.gitconfig index f4a47a8..50a9488 100644 --- a/.gitconfig +++ b/.gitconfig @@ -2,10 +2,9 @@ diff-words = diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+' st = status cm = commit - home = rev-parse --show-toplevel - exec = "!exec " # 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" ignore = "!git-ignore" [color] diff --git a/.local/bin/git-home b/.local/bin/git-home new file mode 100755 index 0000000..aa7c58e --- /dev/null +++ b/.local/bin/git-home @@ -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 diff --git a/.local/bin/git-root b/.local/bin/git-root index 6eb27fe..d91c1ef 100755 --- a/.local/bin/git-root +++ b/.local/bin/git-root @@ -1,9 +1,14 @@ #!/usr/bin/env bash # 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 -superproject=$(git rev-parse --show-superproject-working-tree) -if [ -z "$superproject" ]; then - git rev-parse --show-toplevel; -else - echo "$superproject"; +path=$(git rev-parse --show-superproject-working-tree) +[[ $? -ne 0 ]] && exit $? +if [ -z "$path" ]; then + path=$(git rev-parse --show-toplevel); +fi +if [ $# -eq 0 ]; then + echo "$path"; +else + cd $path && exec "$@"; fi diff --git a/.local/bin/i3.sh b/.local/bin/i3.sh new file mode 100644 index 0000000..29ef7e2 --- /dev/null +++ b/.local/bin/i3.sh @@ -0,0 +1,3 @@ +#!/bin/sh +source ~/.profile +i3