Git directory 'onefetch'

Alias 'cd' to create a flag.
Detect flag during prompt script.
If directory changed to the root of a git repository, print 'onefetch'
Remove flag if set.
This commit is contained in:
John Mertz 2022-12-28 10:38:43 -05:00
parent 2020584c71
commit 0dcd93477a
2 changed files with 11 additions and 0 deletions

View File

@ -51,6 +51,9 @@ alias mpv="flatpak run io.mpv.Mpv"
# Detect if I'm in a toolbox
alias isdistrobox='[ -f "/run/.toolboxenv" ] && grep -oP "(?<=name=\")[^\";]+" /run/.containerenv'
# Flag that the directory was just changed (used with prompt)
alias cd='export DIRCHANGED="1"; cd'
if [ $(isdistrobox) ]; then
source $HOME/.dotfiles/bash/bash_aliases.distrobox
else

View File

@ -9,6 +9,14 @@ elif [[ $ARG != '' ]]; then
exit 0
fi
# If directory was just changed to the root of a git repository, print onefetch
if [ ! -z $DIRCHANGED ]; then
if [ -d $PWD/.git ]; then
$HOME/bin/onefetch
fi
unset DIRCHANGED
fi
# Default colours
# 0 default, 1 red 2 green 3 yellow 4 blue 5 magenta 6 cyan 7 white (grey)
PC="0" # prompt default