From ef82d7c421fa1f0ce013a6d367d845a74cca655e Mon Sep 17 00:00:00 2001 From: Quinn Date: Sun, 25 May 2025 00:53:04 +0200 Subject: [PATCH] reorder lazy loading functions --- .bashrc | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/.bashrc b/.bashrc index 7d0fb9f..22dceb3 100644 --- a/.bashrc +++ b/.bashrc @@ -8,6 +8,32 @@ [[ $- != *i* ]] && return [[ -z "${PS1-}" ]] && return +# wrapper for lazily loading __git_ps1 whenever it is actually needed +_lazy_git_ps1() { + if [[ -z $__GIT_PROMPT_SOURCED ]]; then + if [[ -d .git || $(git rev-parse --is-inside-work-tree 2>/dev/null) == true ]]; then + source /usr/share/bash-completion/completions/git &>/dev/null + source /usr/share/git/completion/git-prompt.sh &>/dev/null + export __GIT_PROMPT_SOURCED=1 + __git_ps1 "$@" + fi + else + __git_ps1 "$@" + fi +} + +# lazy loading of ssh agents +_lazy_ssh() { + if [[ -z $SSH_AUTH_SOCK ]]; then + eval "$(ssh-agent -s)" &>/dev/null + ssh-add "$HOME/.ssh/github" &>/dev/null + ssh-add "$HOME/.ssh/admin@homeserver" &>/dev/null + fi +} +# aliases so the function is called beforehand +alias ssh='_lazy_ssh; ssh' +alias sudo='_lazy_ssh; sudo' + # set PS1 PS1= PS1="$PS1"'\[\033[01;35m\]\u@\h' # user@host @@ -38,31 +64,6 @@ source /home/user/.local/share/vcpkg/scripts/vcpkg_completion.bash &>/dev/null # check the window size after each command (and if necessary, the values of LINES and COLUMNS) shopt -s checkwinsize -# wrapper for lazily loading __git_ps1 whenever it is actually needed -_lazy_git_ps1() { - if [[ -z $__GIT_PROMPT_SOURCED ]]; then - if [[ -d .git || $(git rev-parse --is-inside-work-tree 2>/dev/null) == true ]]; then - source /usr/share/bash-completion/completions/git &>/dev/null - source /usr/share/git/completion/git-prompt.sh &>/dev/null - export __GIT_PROMPT_SOURCED=1 - __git_ps1 "$@" - fi - else - __git_ps1 "$@" - fi -} - -# lazy loading of ssh agents -_lazy_ssh() { - if [[ -z $SSH_AUTH_SOCK ]]; then - eval "$(ssh-agent -s)" &>/dev/null - ssh-add "$HOME/.ssh/github" &>/dev/null - ssh-add "$HOME/.ssh/admin@homeserver" &>/dev/null - fi -} -alias ssh='_lazy_ssh; ssh' -alias sudo='_lazy_ssh; sudo' - # # aliases #