My Shell Configuration Files

A collection of fine-tuned shell configuration files including bashrc, zshrc, custom functions, and more to boost terminal productivity.

My Shell Configuration Files

Welcome to my collection of shell configuration files! These configurations have been fine-tuned over years of daily use to boost productivity and make terminal work more enjoyable. Each file serves a specific purpose in creating a seamless command-line experience.

📋 Table of Contents


.bashrc

The heart of Bash configuration - contains environment variables, PATH modifications, and basic shell settings.

#============================================================#
#                     Part 1: System Settings                #
#------------------------------------------------------------#

# ~/.bashrc: executed by bash(1) for non-login shells.

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# 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

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

stty erase ^?

#============================================================#
#                  Part 2: Prompt Customization              #
#------------------------------------------------------------#

# Set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# Uncomment for a colored prompt, if the terminal has the capability
# force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='\[\033[01;33m\][\u@\h\[\033[01;32m\] \W\[\033[01;33m\]]\$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm, set the title to user@host:dir
case "$TERM" in
    xterm*|rxvt*)
        PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
esac


#============================================================#
#               Part 3: Color and Alias Definitions          #
#------------------------------------------------------------#

# Enable color support for 'ls' and add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    alias dir='dir --color=auto'
    alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# Additional 'ls' aliases for convenience
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# 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$//'\'')"'

# Check if ~/.bash_aliases exists and source it for additional aliases
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# Enable programmable completion features if not already enabled
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

# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'


#============================================================#
#                     Part 4: Custom Functions               #
#------------------------------------------------------------#

# Function to display terminal color codes
colors() {
    local fgc bgc vals seq0
    printf "Color escapes are %s\n" '\e[${value};...;${value}m'
    printf "Values 30..37 are \e[33mforeground colors\e[m\n"
    printf "Values 40..47 are \e[43mbackground colors\e[m\n"
    printf "Value  1 gives a  \e[1mbold-faced look\e[m\n\n"

    for fgc in {30..37}; do
        for bgc in {40..47}; do
            fgc=${fgc#37} # white
            bgc=${bgc#40} # black
            vals="${fgc:+$fgc;}${bgc}"
            vals=${vals%%;}
            seq0="${vals:+\e[${vals}m}"
            printf "  %-9s" "${seq0:-(default)}"
            printf " ${seq0}TEXT\e[m"
            printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
        done
        echo; echo
    done
}

# Function to extract various archive types
ex() {
    if [ -f "$1" ]; then
        case "$1" in
            *.tar.bz2) tar xjvf "$1" ;;
            *.tar.gz)  tar xzvf "$1" ;;
            *.bz2)     bunzip2 "$1" ;;
            *.rar)     unrar xv "$1" ;;
            *.gz)      gunzip "$1" ;;
            *.tar)     tar xvf "$1" ;;
            *.tbz2)    tar xjvf "$1" ;;
            *.tgz)     tar xzvf "$1" ;;
            *.zip)     unzip "$1" ;;
            *.Z)       uncompress "$1" ;;
            *.7z)      7z x "$1" ;;
            *)         echo "'$1' cannot be extracted via ex()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Function to log local history in a specific format
myLocalHistory() {
    if [ -w . ]; then
        history 1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> .history-$LOGNAME
    else
        history 1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "_PWD="  ENVIRON["PWD"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> ~/.history-all-$LOGNAME
    fi
}
export PROMPT_COMMAND="myLocalHistory 2> /dev/null"

# Function to search local history
grepLocalHistory() {
    grep "$1" .history-$LOGNAME
}
alias h=grepLocalHistory

# Function to remove directories gracefully, including empty ones with history files
gracefulRmDir() {
    for d in "$@"; do
        if [ -d "$d" ]; then
            if [ "$(ls "$d" | wc -l)" -ge 1 ]; then
                echo "Directory not empty: $d" >&2
            else
                rm -f "$d"/.history-$LOGNAME
                /bin/rmdir "$d" || exit 1
            fi
        else
            echo "Not a directory: $d" >&2
        fi
    done
}
alias rmdir=gracefulRmDir


gzcount() {
    for file in "$@"; do
        if [[ -f "$file" ]]; then
            echo "$file: $(gzip -cd "$file" | wc -l)"
        else
            echo "$file is not a valid file"
        fi
    done
}


#============================================================#
#               Part 5: Environment Variables and Paths      #
#------------------------------------------------------------#

# Set default language and locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

# Set the terminal type to support 256 colors
export TERM=xterm-256color

# Custom Library Paths
# export LD_LIBRARY_PATH=/mnt/users/sagarst/bin/miniconda/lib:$LD_LIBRARY_PATH

# Packages installed from source
# export PATH="/mnt/users/sagarst/bin/miniconda/bin:$PATH"  # commented out by conda initialize
export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Custom Python Path
export PYTHONPATH=/mnt/local/sangeet/workncode/k2-fsa/icefall:/mnt/local/sangeet/workncode/k2/k2-fsa/icefall:$PYTHONPATH

# Path to sherpa executable
export PATH=$PATH:/mnt/local/sangeet/workncode/k2-fsa/sherpa-onnx/build/bin/

# Path to sherpa C API executable (static compilation)
export PKG_CONFIG_PATH="/mnt/local/sangeet/workncode/k2-fsa/sherpa-onnx/build-static:$PKG_CONFIG_PATH"

# CUDA and CUDNN environment variables
#export CUDA_HOME=/usr/local/cuda-11.2
export CUDA_HOME=/home/sagarst/bin/cuda/12.4.0
export PATH=$CUDA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$CUDA_HOME/extras/CUPTI/lib64:$LD_LIBRARY_PATH
export CUDAToolkit_ROOT_DIR=$CUDA_HOME
export CUDAToolkit_ROOT=$CUDA_HOME


# CUDA toolkit paths
export CUDA_TOOLKIT_ROOT_DIR=$CUDA_HOME
export CUDA_TOOLKIT_ROOT=$CUDA_HOME
export CUDA_BIN_PATH=$CUDA_HOME
export CUDA_PATH=$CUDA_HOME
export CUDA_INC_PATH=$CUDA_HOME/targets/x86_64-linux
export CUDAToolkit_TARGET_DIR=$CUDA_HOME/targets/x86_64-linux



# Additional CFLAGS for CUDA
export CFLAGS=-I$CUDA_HOME/targets/x86_64-linux/include:$CFLAGS

# Set Theano flags for GPU usage
export THEANO_FLAGS='floatX=float32,device=cuda0,gpuarray.preallocate=1'

# Load SSH directory if ~/.sshcd file exists
if [ -f ~/.sshcd ]; then
    cd "$(cat ~/.sshcd)"
    rm ~/.sshcd
fi

# Zero size of core dump (avoid disk quota overfill)
ulimit -c 1

# Kaldi root from Volker- Mon Aug 12 03:47:43 PM CEST 2024
export KALDI_ROOT="/mnt/local/volker/Kaldi/"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/mnt/users/sagarst/bin/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/mnt/users/sagarst/bin/miniconda/etc/profile.d/conda.sh" ]; then
        . "/mnt/users/sagarst/bin/miniconda/etc/profile.d/conda.sh"
    else
        export PATH="/mnt/users/sagarst/bin/miniconda/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

# Huggingface cache dir
export HF_HOME=/mnt/users/sagarst/.hf_cache

#============================================================#
#          Part 6: Specialized Aliases and Functions         #
#------------------------------------------------------------#

# General Aliases
alias rm='rm -i'  # Prompt before deleting files
alias more='less' # Use 'less' instead of 'more'
alias lsn='ls'    # Alias for listing files
alias lsd='ls -d */' # List only directories

# Directory Navigation Aliases
alias cds='cd /home/sagarst'
alias cdn='cd /mnt/users/sagarst'
alias cdw='cd /mnt/local/sangeet/workncode/'
alias cdl='cd /mnt/local/sangeet/'
alias cdr='cd /mnt/amtmpvf2/sangeet'

# Activation of Virtual Environments
alias sb='source /mnt/users/sagarst/envs/sb_env/bin/activate'
alias k2c='source /mnt/users/sagarst/envs/k2-cpu/bin/activate'
alias k2g='source /mnt/users/sagarst/envs/k2-gpu/bin/activate'
alias nemo='source /mnt/users/sagarst/envs/nemo/bin/activate'
alias esp='source /mnt/users/sagarst/envs/esp/bin/activate'
alias wenet='source /mnt/users/sagarst/envs/wenet/bin/activate'

# Shortcut for editing bashrc
alias bashrc='vim ~/.bashrc'

# Alias for removing specific file types
alias rmr='rm -rf *.out *.err *.logs'

# Custom Command for Starting GPU
alias start_int_gpu='/home/sagar/bin/start_int_gpu.sh $1 $2 $3'

# VPN Connection Alias
alias eml-vpn='sudo openvpn --verb 3 --config /home/eml-speech/work/vpn/sangeet_sagar@vpn.eml.org.ovpn'

# GPU Management
alias gpu='export CUDA_VISIBLE_DEVICES=$(nvisel --max-count 1 --min-free-memory 5GiB --max-gpu-utilization 50)'

# Listing Aliases
alias lsr='eza --icons=always -R'    # Recursive listing
alias ltr='eza --icons=always  -ltr'  # List sorted by modification time
alias lls='eza --icons=always -lh' 
alias ll='eza --icons=always --sort modified -l'


# Conda environment listing
alias condalist="conda info -e"

# GPU job submission command
alias qgpu="srun --pty --mem=16gb -n 1 --gres=gpu:1 /bin/bash"

# Monitoring GPU
alias nsmi="nvitop" # Advanced GPU monitoring
alias nvsmi="watch --color -n 1 nvidia-smi" # Regular monitoring with auto-refresh
alias nsmil='nvidia-smi' # Simple call to nvidia-smi

# SGE job queue status
alias stat='squeue -u sagar -o "%.6i %9P %15j %.6u %.10T %.10M %.10l %.6D %10R %s %.10g"'

# TTS Command
alias rekni='espeak -v europe/cs -s 150'


#============================================================#
#                 Part 9: End of the file functions          #
#------------------------------------------------------------#

# Initialize LS_COLORS with directory color
LS_COLORS=$LS_COLORS:'di=1;35:' 

# Set non-executable file types (no chmod)
export LS_COLORS=$LS_COLORS:"*.py=0;32:"    # Python files: Green
export LS_COLORS=$LS_COLORS:"*.sh=0;34:"    # Shell scripts: Blue
export LS_COLORS=$LS_COLORS:"*.md=0;37:"    # Markdown files: White
export LS_COLORS=$LS_COLORS:"*.txt=0;37:"   # Text files: White
export LS_COLORS=$LS_COLORS:"*.wav=0;33:"   # WAV audio files: Yellow
export LS_COLORS=$LS_COLORS:"*.jpg=0;35:"   # JPEG images: Magenta
export LS_COLORS=$LS_COLORS:"*.png=0;34:"   # PNG images: Blue
export LS_COLORS=$LS_COLORS:"*.pdf=0;31:"   # PDF documents: Red
export LS_COLORS=$LS_COLORS:"*.html=0;33:"  # HTML files: Yellow
export LS_COLORS=$LS_COLORS:"*.css=0;34:"   # CSS files: Blue
export LS_COLORS=$LS_COLORS:"*.js=0;33:"    # JavaScript files: Yellow
export LS_COLORS=$LS_COLORS:"*.json=0;36:"  # JSON files: Cyan
export LS_COLORS=$LS_COLORS:"*.xml=0;32:"   # XML files: Green
export LS_COLORS=$LS_COLORS:"*.zip=0;31:"   # ZIP archives: Red
export LS_COLORS=$LS_COLORS:"*.tar=0;31:"   # TAR archives: Red
export LS_COLORS=$LS_COLORS:"*.gz=0;31:"    # GZ compressed files: Red

# Set executable file types (chmod a+x)
export LS_COLORS=$LS_COLORS:"*.py=1;32:"    # Executable Python files: Bold Green
export LS_COLORS=$LS_COLORS:"*.sh=1;34:"    # Executable Shell scripts: Bold Blue
export LS_COLORS=$LS_COLORS:"*.exe=1;31:"   # Executable files: Bold Red
export LS_COLORS=$LS_COLORS:"*.bat=1;33:"   # Batch files: Bold Yellow
export LS_COLORS=$LS_COLORS:"*.bin=1;31:"   # Binary files: Bold Red
export LS_COLORS=$LS_COLORS:"*.pl=1;35:"    # Perl scripts: Bold Magenta
export LS_COLORS=$LS_COLORS:"*.out=1;34:"   # Executable output files: Bold Blue
export LS_COLORS=$LS_COLORS:"*.run=1;33:"   # Linux run files: Bold Yellow

# Apply the LS_COLORS configuration
export LS_COLORS

# Fancy Linux Prompt
source ~/.fancy-prompt.sh
. "$HOME/.cargo/env"

# Startship cross-shell prompt theme
# eval "$(starship init bash)"


.zshrc

Main Zsh configuration file with Oh My Zsh setup, plugins, and Zsh-specific settings.

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# packages installed from source
export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Path to your Oh My Zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
source /home/sagarst/bin/main/powerlevel10k/powerlevel10k.zsh-theme

# history setup
HISTFILE=$HOME/.zhistory.$(tty | sed 's/[^a-zA-Z0-9]/_/g')
SAVEHIST=1000
HISTSIZE=999
setopt share_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_verify

# completion using arrow keys (based on history)
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

  # Enable word navigation with Ctrl + Left/Right arrow keys in Zsh
bindkey '^[[1;5C' forward-word   # Ctrl + Right arrow
bindkey '^[[1;5D' backward-word  # Ctrl + Left arrow

bindkey  "^[[H"   beginning-of-line
bindkey  "^[[F"   end-of-line
bindkey  "^[[3~"  delete-char
bindkey  "^[[1~"  beginning-of-line  # Additional binding for screen
bindkey  "^[[4~"  end-of-line  # Additional binding for screen

WORDCHARS='*?[]~#%^(){}<>|&'

source /home/sagarst/bin/zsh-autosuggestions/zsh-autosuggestions.zsh
source /home/sagarst/bin/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

export PATH=$PATH:"/home/sagarst/bin" # Add custom bin directory to PATH

# ---- Eza (better ls) -----

alias ls="/home/sagarst/bin/eza --icons=always"

# ---- Zoxide (better cd) ----
eval "$(/home/sagarst/bin/zoxide init zsh)"

alias cd="z"

# Directory Navigation Aliases
alias cds='cd /home/sagarst'
alias cdn='cd /mnt/users/sagarst'
alias cdw='cd /mnt/local/sangeet/workncode/'
alias cdl='cd /mnt/local/sangeet/'
alias cdr='cd /mnt/amtmpvf2/sangeet'

# All aliases
source ~/.zsh_aliases


#============================================================#
#                     Custom Functions                       #
#------------------------------------------------------------#

# Function to log local history in a specific format
myLocalHistory() {
    if [ -w . ]; then
        fc -l -1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> .history-$LOGNAME
    else
        fc -l -1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "_PWD="  ENVIRON["PWD"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> ~/.history-all-$LOGNAME
    fi
}

# export PROMPT_COMMAND="myLocalHistory 2> /dev/null"

precmd() {
    myLocalHistory 2>/dev/null
}

# Function to search local history
grepLocalHistory() {
    grep "$1" .history-$LOGNAME
}
alias h=grepLocalHistory



.custom_functions

Collection of custom shell functions that automate repetitive tasks and enhance workflow efficiency.

# Function to display terminal color codes
colors() {
    local fgc bgc vals seq0
    printf "Color escapes are %s\n" '\e[${value};...;${value}m'
    printf "Values 30..37 are \e[33mforeground colors\e[m\n"
    printf "Values 40..47 are \e[43mbackground colors\e[m\n"
    printf "Value  1 gives a  \e[1mbold-faced look\e[m\n\n"

    for fgc in {30..37}; do
        for bgc in {40..47}; do
            fgc=${fgc#37} # white
            bgc=${bgc#40} # black
            vals="${fgc:+$fgc;}${bgc}"
            vals=${vals%%;}
            seq0="${vals:+\e[${vals}m}"
            printf "  %-9s" "${seq0:-(default)}"
            printf " ${seq0}TEXT\e[m"
            printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
        done
        echo; echo
    done
}

# Function to extract various archive types
ex() {
    if [ -f "$1" ]; then
        case "$1" in
            *.tar.bz2) tar xjvf "$1" ;;
            *.tar.gz)  tar xzvf "$1" ;;
            *.bz2)     bunzip2 "$1" ;;
            *.rar)     unrar xv "$1" ;;
            *.gz)      gunzip "$1" ;;
            *.tar)     tar xvf "$1" ;;
            *.tbz2)    tar xjvf "$1" ;;
            *.tgz)     tar xzvf "$1" ;;
            *.zip)     unzip "$1" ;;
            *.Z)       uncompress "$1" ;;
            *.7z)      7z x "$1" ;;
            *)         echo "'$1' cannot be extracted via ex()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Function to log local history in a specific format
myLocalHistory() {
    if [ -w . ]; then
        history 1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> .history-$LOGNAME
    else
        history 1 | gawk '($2 !~ "^[mr]?cd[0-9a-z]?$") {$1="_T="strftime("%Y%m%d_%H:%M:%S_") PROCINFO["ppid"] "_PWD="  ENVIRON["PWD"] "\t"; $2=gensub("^_T=[-_0-9:]*[ \t]* *", "", 1, $2); $2=gensub("^_P=[^ \t]* *", "", 1, $2); print;}' >> ~/.history-all-$LOGNAME
    fi
}
export PROMPT_COMMAND="myLocalHistory 2> /dev/null"

# Function to search local history
grepLocalHistory() {
    grep "$1" .history-$LOGNAME
}
alias h=grepLocalHistory

# Function to remove directories gracefully, including empty ones with history files
gracefulRmDir() {
    for d in "$@"; do
        if [ -d "$d" ]; then
            if [ "$(ls "$d" | wc -l)" -ge 1 ]; then
                echo "Directory not empty: $d" >&2
            else
                rm -f "$d"/.history-$LOGNAME
                /bin/rmdir "$d" || exit 1
            fi
        else
            echo "Not a directory: $d" >&2
        fi
    done
}
alias rmdir=gracefulRmDir


.fancy-prompt.sh

Custom prompt configuration script that creates an informative and visually appealing command prompt.

#!/usr/bin/env bash

__powerline() {
    # Unicode symbols
    readonly GIT_BRANCH_CHANGED_SYMBOL='+'
    readonly GIT_NEED_PULL_SYMBOL='⇣'
    readonly GIT_NEED_PUSH_SYMBOL='⇡'
    readonly PS_SYMBOL='🍻'

    # Solarized colorscheme
readonly BG_BASE00="\\[$(tput setab 11)\\]"   # Background color: Bright yellow
readonly BG_BASE01="\\[$(tput setab 10)\\]"   # Background color: Bright green
readonly BG_BASE02="\\[$(tput setab 0)\\]"    # Background color: Black
readonly BG_BASE03="\\[$(tput setab 8)\\]"    # Background color: Dark gray
readonly BG_BASE0="\\[$(tput setab 12)\\]"    # Background color: Bright blue
readonly BG_BASE1="\\[$(tput setab 14)\\]"    # Background color: Bright cyan
readonly BG_BASE2="\\[$(tput setab 7)\\]"     # Background color: White
readonly BG_BASE3="\\[$(tput setab 15)\\]"    # Background color: Bright white
readonly BG_BLUE="\\[$(tput setab 4)\\]"      # Background color: Blue
readonly BG_BASE4="\\[$(tput setab 208)\\]"   # Background color: Bright orange
readonly BG_BASE5="\\[$(tput setab 214)\\]"   # Background color: Light orange
readonly BG_BASE6="\\[$(tput setab 226)\\]"   # Background color: Bright yellow
readonly BG_BASE7="\\[$(tput setab 229)\\]"   # Background color: Light yellow
readonly BG_BASE8="\\[$(tput setab 93)\\]"    # Background color: Bright purple
readonly BG_BASE9="\\[$(tput setab 99)\\]"    # Background color: Light purple
readonly BG_BASE10="\\[$(tput setab 135)\\]"  # Background color: Violet
readonly BG_BASE11="\\[$(tput setab 129)\\]"  # Background color: Light violet
readonly BG_BASE12="\\[$(tput setab 164)\\]"  # Background color: Bright magenta
readonly BG_BASE13="\\[$(tput setab 201)\\]"  # Background color: Light magenta

readonly BG_COLOR1="\\[\\e[48;5;240m\\]"      # Background color: Gray (xterm-256 color, index 240)
readonly BG_COLOR2="\\[\\e[48;5;238m\\]"      # Background color: Dark gray (xterm-256 color, index 238)
readonly BG_COLOR3="\\[\\e[48;5;238m\\]"      # Background color: Dark gray (xterm-256 color, index 238)
readonly BG_COLOR4="\\[\\e[48;5;31m\\]"       # Background color: Dark blue (xterm-256 color, index 31)
readonly BG_COLOR5="\\[\\e[48;5;31m\\]"       # Background color: Dark blue (xterm-256 color, index 31)
readonly BG_COLOR6="\\[\\e[48;5;237m\\]"      # Background color: Very dark gray (xterm-256 color, index 237)
readonly BG_COLOR7="\\[\\e[48;5;237m\\]"      # Background color: Very dark gray (xterm-256 color, index 237)
readonly BG_COLOR8="\\[\\e[48;5;161m\\]"      # Background color: Deep pink (xterm-256 color, index 161)
readonly BG_COLOR9="\\[\\e[48;5;161m\\]"      # Background color: Deep pink (xterm-256 color, index 161)

readonly BG_COLOR10="\\[\\e[48;5;208m\\]"  # Background color: Bright orange (xterm-256 color, index 208)
readonly BG_COLOR11="\\[\\e[48;5;214m\\]"  # Background color: Light orange (xterm-256 color, index 214)
readonly BG_COLOR12="\\[\\e[48;5;226m\\]"  # Background color: Bright yellow (xterm-256 color, index 226)
readonly BG_COLOR13="\\[\\e[48;5;229m\\]"  # Background color: Light yellow (xterm-256 color, index 229)
readonly BG_COLOR14="\\[\\e[48;5;93m\\]"   # Background color: Bright purple (xterm-256 color, index 93)
readonly BG_COLOR15="\\[\\e[48;5;99m\\]"   # Background color: Light purple (xterm-256 color, index 99)
readonly BG_COLOR16="\\[\\e[48;5;135m\\]"  # Background color: Violet (xterm-256 color, index 135)
readonly BG_COLOR17="\\[\\e[48;5;129m\\]"  # Background color: Light violet (xterm-256 color, index 129)
readonly BG_COLOR18="\\[\\e[48;5;164m\\]"  # Background color: Bright magenta (xterm-256 color, index 164)
readonly BG_COLOR19="\\[\\e[48;5;201m\\]"  # Background color: Light magenta (xterm-256 color, index 201)

readonly BG_CYAN="\\[$(tput setab 6)\\]"      # Background color: Cyan
readonly BG_GREEN="\\[$(tput setab 2)\\]"     # Background color: Green
readonly BG_MAGENTA="\\[$(tput setab 5)\\]"   # Background color: Magenta
readonly BG_ORANGE="\\[$(tput setab 9)\\]"    # Background color: Bright red/orange
readonly BG_RED="\\[$(tput setab 1)\\]"       # Background color: Red
readonly BG_VIOLET="\\[$(tput setab 13)\\]"   # Background color: Bright magenta/violet
readonly BG_YELLOW="\\[$(tput setab 3)\\]"    # Background color: Yellow
readonly BOLD="\\[$(tput bold)\\]"            # Bold text
readonly BOLD_WHITE="\\[$(tput bold)\$(tput setaf 17)\\]"  # Bold and white text

readonly DIM="\\[$(tput dim)\\]"              # Dim text

readonly FG_BASE00="\\[$(tput setaf 11)\\]"   # Foreground color: Bright yellow
readonly FG_BASE01="\\[$(tput setaf 10)\\]"   # Foreground color: Bright green
readonly FG_BASE02="\\[$(tput setaf 0)\\]"    # Foreground color: Black
readonly FG_BASE03="\\[$(tput setaf 8)\\]"    # Foreground color: Dark gray
readonly FG_BASE0="\\[$(tput setaf 12)\\]"    # Foreground color: Bright blue
readonly FG_BASE1="\\[$(tput setaf 14)\\]"    # Foreground color: Bright cyan
readonly FG_BASE2="\\[$(tput setaf 7)\\]"     # Foreground color: White
readonly FG_BASE3="\\[$(tput setaf 15)\\]"    # Foreground color: Bright white
readonly FG_BLUE="\\[$(tput setaf 4)\\]"      # Foreground color: Blue
readonly FG_COLOR1="\\[\\e[38;5;250m\\]"      # Foreground color: Light gray (xterm-256 color, index 250)
readonly FG_COLOR2="\\[\\e[38;5;240m\\]"      # Foreground color: Gray (xterm-256 color, index 240)
readonly FG_COLOR3="\\[\\e[38;5;250m\\]"      # Foreground color: Light gray (xterm-256 color, index 250)
readonly FG_COLOR4="\\[\\e[38;5;238m\\]"      # Foreground color: Dark gray (xterm-256 color, index 238)
readonly FG_COLOR6="\\[\\e[38;5;31m\\]"       # Foreground color: Dark blue (xterm-256 color, index 31)
readonly FG_COLOR7="\\[\\e[38;5;250m\\]"      # Foreground color: Light gray (xterm-256 color, index 250)
readonly FG_COLOR8="\\[\\e[38;5;237m\\]"      # Foreground color: Very dark gray (xterm-256 color, index 237)
readonly FG_COLOR9="\\[\\e[38;5;161m\\]"      # Foreground color: Deep pink (xterm-256 color, index 161)
readonly FG_COLOR10="\\[\\e[38;5;208m\\]"   # Foreground color: Bright orange (xterm-256 color, index 208)
readonly FG_COLOR11="\\[\\e[38;5;214m\\]"   # Foreground color: Light orange (xterm-256 color, index 214)
readonly FG_COLOR12="\\[\\e[38;5;226m\\]"   # Foreground color: Bright yellow (xterm-256 color, index 226)
readonly FG_COLOR13="\\[\\e[38;5;229m\\]"   # Foreground color: Light yellow (xterm-256 color, index 229)
readonly FG_COLOR14="\\[\\e[38;5;93m\\]"    # Foreground color: Bright purple (xterm-256 color, index 93)
readonly FG_COLOR15="\\[\\e[38;5;99m\\]"    # Foreground color: Light purple (xterm-256 color, index 99)
readonly FG_COLOR16="\\[\\e[38;5;135m\\]"   # Foreground color: Violet (xterm-256 color, index 135)
readonly FG_COLOR17="\\[\\e[38;5;129m\\]"   # Foreground color: Light violet (xterm-256 color, index 129)
readonly FG_COLOR18="\\[\\e[38;5;164m\\]"   # Foreground color: Bright magenta (xterm-256 color, index 164)
readonly FG_COLOR19="\\[\\e[38;5;201m\\]"   # Foreground color: Light magenta (xterm-256 color, index 201)

readonly FG_CYAN="\\[$(tput setaf 6)\\]"      # Foreground color: Cyan
readonly FG_GREEN="\\[$(tput setaf 2)\\]"     # Foreground color: Green
readonly FG_MAGENTA="\\[$(tput setaf 5)\\]"   # Foreground color: Magenta
readonly FG_ORANGE="\\[$(tput setaf 9)\\]"    # Foreground color: Bright red/orange
readonly FG_RED="\\[$(tput setaf 1)\\]"       # Foreground color: Red
readonly FG_VIOLET="\\[$(tput setaf 13)\\]"   # Foreground color: Bright magenta/violet
readonly FG_YELLOW="\\[$(tput setaf 3)\\]"    # Foreground color: Yellow
readonly RESET="\\[$(tput sgr0)\\]"           # Reset text attributes
readonly REVERSE="\\[$(tput rev)\\]"          # Reverse video (swap foreground and background)


    __git_info() {
        # no .git directory
    	[ -d .git ] || return

        local aheadN
        local behindN
        local branch
        local marks
        local stats

        # get current branch name or short SHA1 hash for detached head
        branch="$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --always 2>/dev/null)"
        [ -n "$branch" ] || return  # git branch not found

        # how many commits local branch is ahead/behind of remote?
        stats="$(git status --porcelain --branch | grep '^##' | grep -o '\[.\+\]$')"
        aheadN="$(echo "$stats" | grep -o 'ahead \d\+' | grep -o '\d\+')"
        behindN="$(echo "$stats" | grep -o 'behind \d\+' | grep -o '\d\+')"
        [ -n "$aheadN" ] && marks+=" $GIT_NEED_PUSH_SYMBOL$aheadN"
        [ -n "$behindN" ] && marks+=" $GIT_NEED_PULL_SYMBOL$behindN"

        # print the git branch segment without a trailing newline
        # branch is modified?
        if [ -n "$(git status --porcelain)" ]; then
            printf "%s" "${BG_COLOR8}$RESET$BG_COLOR8 $branch$marks $FG_COLOR9"
        else
            printf "%s" "${BG_BLUE}$RESET$BG_BLUE $branch$marks $RESET$FG_BLUE"
        fi
    }
    git_toplevel_dir() {
        if git rev-parse --is-inside-work-tree &>/dev/null; then
            basename "$(git rev-parse --show-toplevel)"
        fi
        }

    virtual_env_name() {
        # Check if VIRTUAL_ENV is set and the shell is interactive
        if [[ -n "$VIRTUAL_ENV" && $- == *i* ]]; then
            echo "($(basename $VIRTUAL_ENV)) "
        fi
    }


    ps1() {
        # Check the exit code of the previous command and display different
        # colors in the prompt accordingly.
        if [ "$?" -eq 0 ]; then
            local BG_EXIT="$BG_GREEN"
            local FG_EXIT="$FG_GREEN"
        else
            local BG_EXIT="$BG_RED"
            local FG_EXIT="$FG_RED"
        fi


        PS1="$FG_COLOR5"
        # PS1+="$BOLD_WHITE$BG_COLOR11 \$(virtual_env_name)`date +%r` "
        PS1+="$BOLD_WHITE$BG_COLOR11 \$(virtual_env_name) \\u@\\h "
        PS1+="$RESET${FG_COLOR11}"
        PS1+="${BG_COLOR1}$RESET"

        # Add the top-level directory of the Git repository
        PS1+="$BG_COLOR1 \$(git_toplevel_dir) "
        PS1+="$RESET${FG_COLOR2}"
        PS1+="${BG_COLOR5}$RESET"

        PS1+="$BG_COLOR5 \\W "
        PS1+="$RESET${FG_COLOR6}"

        PS1+="$(__git_info)"
        PS1+="$BG_EXIT$RESET"
        PS1+="$BG_EXIT$FG_BASE3 ${PS_SYMBOL} ${RESET}${FG_EXIT}${RESET} "
    }

    export PROMPT_COMMAND="myLocalHistory 2> /dev/null; ps1"
}
# Skip if not interactive shell
[[ $- == *i* ]] || return
__powerline
unset __powerline


.screenrc

GNU Screen configuration for managing multiple terminal sessions efficiently.

# Turn the status line on
hardstatus on

# Set the status line format (customize as needed)
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %Y-%m-%d %C%a "

termcapinfo xterm* ti@:te@



.zsh_aliases

Comprehensive collection of Zsh aliases to speed up common commands and operations.

#============================================================#
#               Part 3: Color and Alias Definitions          #
#------------------------------------------------------------#

# Enable color support for 'ls' and add handy aliases
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# 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$//'\'')"'

#============================================================#
#               Part 6: Specialized Aliases and Functions         #
#------------------------------------------------------------#

# General Aliases
alias rm='rm -i'  # Prompt before deleting files
alias more='less' # Use 'less' instead of 'more'
alias lsd='ls -d */' # List only directories

# Activation of Virtual Environments
alias sb='source /mnt/users/sagarst/envs/sb_env/bin/activate'
alias k2c='source /mnt/users/sagarst/envs/k2-cpu/bin/activate'
alias k2g='source /mnt/users/sagarst/envs/k2-gpu/bin/activate'
alias nemo='source /mnt/users/sagarst/envs/nemo/bin/activate'
alias esp='source /mnt/users/sagarst/envs/esp/bin/activate'

# Shortcut for editing bashrc
alias bashrc='vim ~/.bashrc'

# Alias for removing specific file types
alias rmr='rm -rf *.out *.err *.logs'

# Custom Command for Starting GPU
alias start_int_gpu='/home/sagar/bin/start_int_gpu.sh $1 $2 $3'

# VPN Connection Alias
alias eml-vpn='sudo openvpn --verb 3 --config /home/eml-speech/work/vpn/sangeet_sagar@vpn.eml.org.ovpn'

# GPU Management
alias gpu='export CUDA_VISIBLE_DEVICES=$(nvisel --max-count 1 --min-free-memory 5GiB --max-gpu-utilization 50)'

# Listing Aliases
alias lsr='eza --icons=always -R'    # Recursive listing
alias ll='eza --icons=always --sort modified -l'  # Detailed listing with human-readable sizes, sorted by modification time
alias lls='eza --icons=always -l'  # Detailed listing with human-readable sizes, sorted by modification time
alias ltr='eza --icons=always  -ltr'  # List sorted by modification time

# Conda environment listing
alias condalist="conda info -e"

# GPU job submission command
alias qgpu="srun --pty --mem=16gb -n 1 --gres=gpu:1 /bin/bash"

# Monitoring GPU
alias nsmi="nvitop" # Advanced GPU monitoring
alias nvsmi="watch --color -n 1 nvidia-smi" # Regular monitoring with auto-refresh
alias nsmil='nvidia-smi' # Simple call to nvidia-smi

# SGE job queue status
alias stat='squeue -u sagar -o "%.6i %9P %15j %.6u %.10T %.10M %.10l %.6D %10R %s %.10g"'

# TTS Command
alias rekni='espeak -v europe/cs -s 150'



.vimrc

Vim editor configuration with custom key mappings, plugins, and settings for efficient text editing.

set pastetoggle=<F3>
set number
set cursorline
set backspace=indent,eol,start


</details>


🚀 Quick Setup

To use these configurations:

  1. Backup your existing files (important!)
    cp ~/.bashrc ~/.bashrc.backup
    cp ~/.zshrc ~/.zshrc.backup
    # ... repeat for other files
    
  2. Copy the desired configurations to your home directory

  3. Source the files or restart your terminal
    source ~/.bashrc
    source ~/.zshrc
    
  4. Requirement
    git-lfs
    zoxide
    eza
    zsh
    zsh-autosuggestions
    zsh-syntax-highlighting
    

📝 Notes

🤝 Contributing

Found a bug or have a suggestion? Feel free to reach out or submit improvements!


Last updated: July 2025