My bash config file as of [2025-08-09 Sat]–downloadable here.

# ~/.bashrc - config for interactive bash sessions

################
# front matter #
################
# If shell is not running interactively, don't evaluate
case $- in
    *i*) ;;
      *) return;;
esac

################
# shell prompt #
################
# git prompt 
######
# set colors
c_reset='\[\e[0m\]'
c_git_clean='\[\e[0;32m\]'
c_git_dirty='\[\e[0;31m\]'
# function: get active branch of current git repo
get_git_branch ()
{
    echo "$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')"
}
# function: get status relative to remote
get_git_remote_status ()
{
    behind_count=$(git rev-list --count HEAD..@{u} 2>&-)
    ahead_count=$(git rev-list --count @{u}..HEAD 2>&-)

    re='^[0-9]+$'

    if ! [[ $behind_count =~ $re ]] || ! [[ $ahead_count =~ $re ]]; then
        exit 1
    fi

    if [ "$behind_count" -eq 0 ] && [ "$ahead_count" -eq 0 ]; then 
        exit
    elif [ "$behind_count" -gt 0 ] && [ "$ahead_count" -gt 0 ]; then  
        echo " +$ahead_count/-$behind_count"
    elif [ "$behind_count" -gt 0 ]; then 
        echo " -$behind_count"
    elif [ "$ahead_count" -gt 0 ]; then 
        echo " +$ahead_count"
    else
        exit
    fi
}
# function: return git prompt
git_prompt ()
{
  if ! git rev-parse --git-dir > /dev/null 2>&1; then
    return 0
  fi

  git_branch=$(get_git_branch)
  git_divergance=$(get_git_remote_status)

  if git diff --quiet 2>/dev/null >&2; then
    git_color="$c_git_clean"
  else
    git_color="$c_git_dirty"
  fi

  echo " [$git_color$git_branch${c_reset}$git_divergance]"
}
#####
# set bash prompt
#####
# 'PROMPT_COMMAND' seems to be required to pass through colors
PROMPT_COMMAND='PS1="\[\e[0;34m\]\\$ \[\e[0;36m\]\u \[\e[0;37m\]@ \[\e[0;32m\]\H \[\e[0;37m\]in \[\e[0;33m\]\W \[\e[0;37m\][\t]\[\e[m\]$(git_prompt)\n\[\e[0;31m\]>\[\e[m\] "'

############
# controls #
############
# set vi mode
set -o vi
# keybindings
bind -m vi-move '"k":history-search-backward'
bind -m vi-move '"j":history-search-forward'   
#####
# completion
#####
# enable bash completion
if ! shopt -oq posix; then
    if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
    elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
fi
# enable tab autocompletion with options listed
bind 'set show-all-if-ambiguous on'
bind 'TAB:menu-complete'
# allow bash to correct spelling errors on directory completion
shopt -s dirspell
# allow bash to ignore case when matching
shopt -s nocaseglob
shopt -s nocasematch

################
# bash history #
################
# don't put duplicate lines or lines starting with space in the history
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

##################
# misc functions #
##################
# grpt - get summary of git files under home dir
#####
grpt ()
{
    echo "All git repos under ~/ :" > /tmp/gitreport 

    for i in $(find ~/ -type d -name ".git" -not -path "/home/jules/shared/*" | sort); do
        echo "-----" >> /tmp/gitreport
        checkDir=$(echo $i | sed -n "/.git/s/.git//p")
        echo -e "[\e[0;35m$checkDir\e[0m]" >> /tmp/gitreport
        echo "-----" >> /tmp/gitreport
        git -C $checkDir fetch
        git -C $checkDir status  >> /tmp/gitreport
    done

    less -R /tmp/gitreport
}
#####
# mktp - create and inhabit temp dir
#####
function mktp() {

 tpd=$(mktemp -d)

 echo $tpd

 cd "$tpd"

}
#####
# os - sync org directory in one go
#####
os ()
{
    set -e
    orgDir="/home/jules/org"
    emacsclient -e "(save-some-buffers)"
    git -C $orgDir add .
    # use the || to eat git commit's exit signal
    git -C $orgDir commit -m "$(date)" || sleep 1
    git -C $orgDir pull origin master
    git -C $orgDir push origin master
}

###########
# aliases #
###########
# ls
alias ls='ls -1 --color=tty --group-directories-first'
alias ll='ls -1lh --color=tty --group-directories-first'
alias la='ls -lAh --color=tty --group-directories-first'
# grep
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# git
alias gst='git status'
alias ggpull='git pull origin "$(get_git_branch)"'
alias ggpush='git push origin "$(get_git_branch)"'
alias gcam='git commit --all --message'
alias gcad='git commit --all -m "$(date)"'
alias gaa='git add --all'
alias gcad='git commit -m "$(date)"'
# executables
alias vscode='code'
alias astudio='~/bin/android-studio/bin/studio.sh'
alias ytdla='yt-dlp --audio-quality 0 -x'
alias centclk='TZ="US/Central"; export TZ; tty-clock -f "Central Time"'
alias cpbd='xclip -selection clipboard -out | tr \\n \\r | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file -'
# misc 
alias rd=rmdir
alias su='su --login'
alias ipa='ip a'

################
# other config #
###############
# add directories to PATH:
#####
PATH=$PATH:~/.local/bin:/snap/bin
######
#keychain setup
#####
if [ -x /usr/bin/keychain ]; then
    /usr/bin/keychain $HOME/.ssh/id_rsa
    source $HOME/.keychain/$(hostname)-sh
fi
#####
# Set emacsclient as editor
#####
export EDITOR="emacsclient -c -a '' -t"
export VISUAL="emacsclient -c -a ''"

Author: jules

Created: 2025-08-09 Sat 19:45

Validate