From 0dcd93477a796bcd5fd0f2a9879ca0b6c3d2aa39 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Wed, 28 Dec 2022 10:38:43 -0500 Subject: [PATCH] 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. --- bash/bash_aliases | 3 +++ bash/prompt.sh | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/bash/bash_aliases b/bash/bash_aliases index bf8552a0c..874ee2207 100644 --- a/bash/bash_aliases +++ b/bash/bash_aliases @@ -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 diff --git a/bash/prompt.sh b/bash/prompt.sh index c765fdee1..bc4c1752e 100755 --- a/bash/prompt.sh +++ b/bash/prompt.sh @@ -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