reorder lazy loading functions
This commit is contained in:
51
.bashrc
51
.bashrc
@@ -8,6 +8,32 @@
|
|||||||
[[ $- != *i* ]] && return
|
[[ $- != *i* ]] && return
|
||||||
[[ -z "${PS1-}" ]] && 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
|
# set PS1
|
||||||
PS1=
|
PS1=
|
||||||
PS1="$PS1"'\[\033[01;35m\]\u@\h' # user@host
|
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)
|
# check the window size after each command (and if necessary, the values of LINES and COLUMNS)
|
||||||
shopt -s checkwinsize
|
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
|
# aliases
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user