From dabfa780df359fa2b24f27e014b48acc1c5c0847 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 21 Feb 2026 07:58:17 -0500 Subject: [PATCH] Add bash.d. --- .bash.d/.bash_aliases | 28 +++++++++++++ .bash_aliases => .bash.d/.bash_exports | 55 +------------------------- .bash.d/.bash_functions | 8 ++++ .bash.d/.bash_sources | 15 +++++++ .bashrc | 11 +++++- setup.sh | 6 +-- 6 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 .bash.d/.bash_aliases rename .bash_aliases => .bash.d/.bash_exports (51%) create mode 100644 .bash.d/.bash_functions create mode 100644 .bash.d/.bash_sources diff --git a/.bash.d/.bash_aliases b/.bash.d/.bash_aliases new file mode 100644 index 0000000..e861aba --- /dev/null +++ b/.bash.d/.bash_aliases @@ -0,0 +1,28 @@ +alias ,git='git config --global user.name "Shaun Reed" && git config --global user.email "shaunrd0@gmail.com"' +# Some aliases don't make sense in the docker image, like shortcuts to fix plasmashell. +if [ -f /.dockerenv ]; then + alias ,update='apt update -y && apt upgrade -y && apt upgrade --fix-broken --fix-missing --auto-remove' + alias ,init='apt update -y && apt install -y $DOT_PACKAGES' + alias ,swap='swapoff -a && swapon -a' +else + alias ,update='sudo apt update -y && sudo apt upgrade -y && sudo apt upgrade --fix-broken --fix-missing --auto-remove' + alias ,init='sudo apt update -y && sudo apt install -y $DOT_PACKAGES' + # Clear kscreen cached settings + alias ,kscreen='rm -rf ~/.local/share/kscreen/*' + # Restart plasmashell + alias ,plasmashell='plasmashell --replace &> /dev/null &' + alias ,swap='sudo swapoff -a && sudo swapon -a' + alias ,vbox="ps aux www |grep 'VBoxClient --draganddrop' | awk '{print $2}' | xargs kill" +fi + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# Don't use tmux in vscode to avoid 'failure to resolve shell' errors. +if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then + if ! pstree -s $$ | grep -wq code; then + exec tmux >/dev/null 2>&1 + fi +fi + diff --git a/.bash_aliases b/.bash.d/.bash_exports similarity index 51% rename from .bash_aliases rename to .bash.d/.bash_exports index 8d9e89e..3fbd30f 100644 --- a/.bash_aliases +++ b/.bash.d/.bash_exports @@ -1,46 +1,13 @@ -# Source ble.sh if installed. -if [ -f ~/.local/share/blesh/ble.sh ]; then - source -- ~/.local/share/blesh/ble.sh -fi - -# Source rust things if they exist -if [ -f ~/.cargo/env ]; then - . ~/.cargo/env -fi - -alias ,git='git config --global user.name "Shaun Reed" && git config --global user.email "shaunrd0@gmail.com"' -# Some aliases don't make sense in the docker image, like shortcuts to fix plasmashell. +# Used in setup script and dockerfile. if [ -f /.dockerenv ]; then export DOT_PACKAGES='git stow vim tmux ranger clang wget curl golang-go' - alias ,update='apt update -y && apt upgrade -y && apt upgrade --fix-broken --fix-missing --auto-remove' - alias ,init='apt update -y && apt install -y $DOT_PACKAGES' - alias ,swap='swapoff -a && swapon -a' else export DOT_PACKAGES='git stow vim vim-gtk3 xsel xclip tmux ranger clang yakuake wget curl golang-go gawk' - alias ,update='sudo apt update -y && sudo apt upgrade -y && sudo apt upgrade --fix-broken --fix-missing --auto-remove' - alias ,init='sudo apt update -y && sudo apt install -y $DOT_PACKAGES' - # Clear kscreen cached settings - alias ,kscreen='rm -rf ~/.local/share/kscreen/*' - # Restart plasmashell - alias ,plasmashell='plasmashell --replace &> /dev/null &' - alias ,swap='sudo swapoff -a && sudo swapon -a' - alias ,vbox="ps aux www |grep 'VBoxClient --draganddrop' | awk '{print $2}' | xargs kill" fi -# $1: Version -# $2: Path to Qt; defaults to $HOME/Qt -function assistant { - local version=${1:-6\.7\.3} - local path=${2:-$HOME/Qt} - nohup ${path%/}/$version/gcc_64/bin/assistant > /dev/null 2>&1 & -} - # colored GCC warnings and errors #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' export EDITOR="vim" export VISUAL="vim" export LS_COLORS="di=1;34:ln=31;47:so=32:pi=33:ex=1;32:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" @@ -50,17 +17,6 @@ export DOTNET_ROOT=$HOME/.dotnet # Example path for autocompletion using libclang-9-dev package, obtained by the following command export LIBCLANG="$(command -v clang &>/dev/null && ldconfig -p | sort | grep libclang-[0-9]. | awk -F "> " '{print$2}' | tail -n 1)" -# Source a top-secret alias file -if [ -e ~/.bash_secrets ]; then - . ~/.bash_secrets -fi - -if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then - if ! pstree -s $$ | grep -wq code; then - exec tmux >/dev/null 2>&1 - fi -fi - # Set the default terminal to use konsole, with kapper profile # + Execute tmux on start if [ -e ~/.local/share/konsole/kapper.profile ]; then @@ -105,15 +61,6 @@ export LESS='--mouse --wheel-lines 2' # + -#2 to shift 2 columns horizontally when right / left arrow is pressed export LESS="$LESS -R -w -#2" - -if ! [ command -v conda &>/dev/null ] && [ -e ~/Code/Clones/mambaforge/bin/conda ] && ! grep -e conda ~/.bashrc &>/dev/null; then - if ! (~/Code/Clones/mambaforge/bin/conda init | awk -F "==>" '{print $1}'); then - echo "[dot] ERROR: Failed to initialize Conda." - fi - echo "[dot] WARN: Ran \`conda init\`; Conda was installed but not initialized" - source ~/.bashrc -fi - # For shared systems where history is not desired. # ln -sf /dev/null ~/.bash_history # HISTFILE=/dev/null diff --git a/.bash.d/.bash_functions b/.bash.d/.bash_functions new file mode 100644 index 0000000..e4efd33 --- /dev/null +++ b/.bash.d/.bash_functions @@ -0,0 +1,8 @@ +# $1: Version +# $2: Path to Qt; defaults to $HOME/Qt +function assistant { + local version=${1:-6\.7\.3} + local path=${2:-$HOME/Qt} + nohup ${path%/}/$version/gcc_64/bin/assistant > /dev/null 2>&1 & +} + diff --git a/.bash.d/.bash_sources b/.bash.d/.bash_sources new file mode 100644 index 0000000..0915545 --- /dev/null +++ b/.bash.d/.bash_sources @@ -0,0 +1,15 @@ +# Source ble.sh if installed. +if [ -f ~/.local/share/blesh/ble.sh ]; then + source -- ~/.local/share/blesh/ble.sh +fi + +# Source rust things if they exist +if [ -f ~/.cargo/env ]; then + . ~/.cargo/env +fi + +# Source a top-secret alias file +if [ -e ~/.bash_secrets ]; then + . ~/.bash_secrets +fi + diff --git a/.bashrc b/.bashrc index b488fcc..fce2fa8 100644 --- a/.bashrc +++ b/.bashrc @@ -100,11 +100,20 @@ alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. - if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi +# Source all files in ~/.bash.d, if it exists. +# This can contain .bash_aliases, or other configs to append to your shell. +if [ -d ~/.bash.d ]; then + for f in ~/.bash.d/.*; do + if [ -f $f ]; then + . $f + fi + done +fi + # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). diff --git a/setup.sh b/setup.sh index 1d8e11e..8d6b509 100755 --- a/setup.sh +++ b/setup.sh @@ -16,10 +16,10 @@ fi git submodule update --init --recursive # Use alias for installing packages so we don't maintain several dependency lists. -if ! [[ -f .bash_aliases ]]; then - fatal "Failed to locate .bash_aliases in path: $(pwd)" 3 +if ! [[ -f .bash.d/.bash_exports ]]; then + fatal "Failed to locate .bash.d/.bash_exports in path: $(pwd)" 3 fi -. .bash_aliases +. .bash.d/.bash_exports if [[ -z ${DOT_PACKAGES:-} ]]; then fatal "DOT_PACKAGES variable not found after sourcing $(pwd)/.bash_aliases" 4