chore(bash): update shellrc files as usual

Signed-off-by: Andrei Jiroh Halili <ajhalili2006@andreijiroh.xyz>
This commit is contained in:
Andrei Jiroh Halili 2024-07-07 17:46:25 +08:00
parent 56ae595504
commit ab3e569190
No known key found for this signature in database
GPG key ID: 67BFC91B3DA12BE8
7 changed files with 83 additions and 9 deletions

View file

@ -1,16 +1,17 @@
#!/usr/bin/env bash
# # shellcheck disable=SC2046,SC1091,SC2155
# Stage 0: Source dotenv stuff from homedir
source "$HOME/.env"
if [[ -f "$HOME/.env.local" ]]; then
source "$HOME/.env.local"
LOCAL_DOTENV_LOADED=true
export LOCAL_DOTENV_LOADED=true
fi
if [[ $TERMUX ]]; then
export SSH_AGENT_=todo
elif command -v keychain >> /dev/null; then
export KEYCHAIN_PATh=$(command -v keychain)
export KEYCHAIN_PATH=$(command -v keychain)
eval $(keychain --agents gpg,ssh --eval)
fi
@ -19,4 +20,5 @@ if [ -f "$HOME/.config/localconfig.env" ]; then
. "$HOME/.config/localconfig.env"
fi
_byobu_sourced=1 . /usr/bin/byobu-launch 2>/dev/null || true
# # shellcheck source=./.bashrc
source ./.bashrc

View file

@ -63,8 +63,9 @@ if [[ -d "$HOME/.bashbox" ]]; then
source "$HOME/.bashbox/env"
fi
# handle hostname generation for importing host-specific configs
# TODO: Handle detection when we don't have WSL_* variables on tmux shell sessions
# Formerly: handle hostname generation for importing host-specific configs
# TODO: Handle detection across distributions without chaos, especially where
# Nix is installed (not NixOS)
if [[ $WSL_DISTRO_NAME ]] && [[ $WSL_INTEROP ]]; then
HOSTNAME_BASH="$(cat /etc/hostname)-wsl-${WSL_DISTRO_NAME}"
export WSL=1 # similar to CODESPACES and GITPOD_WORKSPACE_ID vars

View file

@ -1,7 +1,7 @@
# General
alias clear="printf '\033c'" # faster than ncurses clear by a lot
alias c='clear'
alias bashrc="nano ~/.bashrc && source ~/.bashrc"
alias bashrc="${EDITOR:-"nano"} ~/.bashrc && source ~/.bashrc"
# LS
alias ls='ls --color=auto -FAh'
alias ll='ls -l'

View file

@ -68,8 +68,9 @@ export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quo
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
source "${HOME}/.config/aliases"
source "${HOME}/.config/bash/aliases"
source "${HOME}/.config/bash/tools/automated-deploy.bashrc"
source "${HOME}/.config/bash/functions"
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile

67
.config/bash/functions Normal file
View file

@ -0,0 +1,67 @@
#!/usr/bin/env bash
# shellcheck disable=SC2046
# handle .env.keys detection
_load_env_keys() {
if [[ "$LAST_DOTENV_DIR" == "$PWD" ]]; then
return
elif [[ "$LAST_DOTENV_DIR" != "$PWD" ]] && [ -f "$LAST_DOTENV_DIR/.env.keys" ]; then
return
fi
if [ -f "$PWD/.env.keys" ] && [[ "$LOADED_DOTENV_KEYS" != "1" ]]; then
echo "dotenv-keys: loading up dotenv keys from this directory"
# TODO: Add source link since it is obviously copied from Stack Overflow.
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export $(grep -v '^#' .env.keys | xargs -d '\n')
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export $(grep -v '^#' .env.keys | xargs -0)
fi
export DOTENV_KEYS_LOADED=1 LAST_DOTENV_DIR=$PWD DOTENV_KEYS_LOADER=auto
elif [ ! -f "$PWD/.env.keys" ] && [[ "$LOADED_DOTENV_KEYS" == "1" ]]; then
echo "dotenv-keys: unloading dotenv keys"
unset "${!DOTENV_PRIVATE_KEYS*}" DOTENV_KEYS_LOADED DOTENV_KEYS_LOADER
export LAST_DOTENV_DIR=$PWD
fi
}
if [[ ";${PROMPT_COMMAND[*]:-};" != *";_load_env_keys;"* ]]; then
if [[ "$(declare -p PROMPT_COMMAND 2>&1)" == "declare -a"* ]]; then
PROMPT_COMMAND=(_load_env_keys "${PROMPT_COMMAND[@]}")
else
PROMPT_COMMAND="_load_env_keys${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi
fi
# Allow manual access to .env.keys, even without the keys autoloader.
dotenv-keys() {
if [[ $1 == "load" ]]; then
if [ ! -f "$PWD/.env.keys" ]; then
echo "error: missing dotenv encryption keys"
return 1
fi
echo "dotenv-keys: loading up dotenv keys from this directory"
# TODO: Add source link since it is obviously copied from Stack Overflow.
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export $(grep -v '^#' .env.keys | xargs -d '\n')
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export $(grep -v '^#' .env.keys | xargs -0)
fi
export LOADED_DOTENV_KEYS=$PWD DOTENV_KEYS_LOADER=manual DOTENV_KEYS_LOADED=1
elif [[ $1 == "unload" ]]; then
echo "dotenv-keys: manually unloading dotenv keys"
unset "${!DOTENV_PRIVATE_KEY*}" DOTENV_KEYS_LOADED DOTENV_KEYS_LOADER DOTENV_KEYS_LOADED
else
echo "dotenv-keys - .env.keys manager for dotenvx"
echo ""
echo "Commands:"
echo " load - load keys from .env.keys in current directory into shell session"
echo " unload - unload keys from shell session"
fi
}

View file

@ -1,3 +1,7 @@
#!/usr/bin/env bash
[ -s "$HOME/.asdf/asdf.sh" ] && source "$HOME/.asdf/asdf.sh"
[ -s "$HOME/.asdf/asdf.sh" ] && source "$HOME/.asdf/asdf.sh"
if [[ $ASDF_DIR ]]; then
eval "$(direnv hook bash)" # Load up direnv hook after asdf
fi

View file

@ -41,5 +41,4 @@ if [ -f "$HOME/.config/localconfig.env" ]; then
fi
if [[ $FF_BYOBU_ON_LOGIN != "" ]]; then
_byobu_sourced=1 . /usr/bin/byobu-launch 2>/dev/null || true
fi