Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created January 14, 2026 23:30
Show Gist options
  • Select an option

  • Save xeioex/d9b9692e552cdae55ac3a4e6a533cd25 to your computer and use it in GitHub Desktop.

Select an option

Save xeioex/d9b9692e552cdae55ac3a4e6a533cd25 to your computer and use it in GitHub Desktop.
#! /bin/bash
# FIXME: with checkbashisms
# Bash snippets
# for i in {1..500}; do curl 'url' > /dev/null & done
# Generic routines
__source-if-exist() {
if [ -f $1 ]; then
. $1
fi
}
__create-if-not-exist() {
if [ ! -d $1 ]; then
mkdir -p $1 2>/dev/null
fi
}
__is-exist() {
which $1 2>/dev/null
}
__path_prepend() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$1:$PATH"
fi
}
__path_append() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$PATH:$1"
fi
}
# Customization
USERPROFILERC=~/.bashrc_user_profile
__source-if-exist $USERPROFILERC
__source-if-exist ~/.bashrc_private
export PROJECT=$PROJECT
export HOSTIP=$(ip addr|egrep 'inet.*eth0'|egrep -m 1 -o 'inet [0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed 's/inet //')
export ESSENTIALCONFIGS="$USERPROFILERC $ESSENTIALCONFIGS"
#Colors aliases
# Reset
Color_Off="\[\e[0m\]"
Color_OffE="\e[0m"
# Bold Regular Colors
Red="\[\033[1;31m\]"
RedE="\033[1;31m"
Green="\[\033[1;32m\]"
GreenE="\033[1;32m"
Yellow="\[\033[1;33m\]"
YellowE="\033[1;33m"
Blue="\[\033[1;34m\]"
BlueE="\033[1;34m"
Purple="\[\033[1;35m\]"
PurpleE="\033[1;35m"
Cyan="\[\033[1;36m\]"
CyanE="\033[1;36m"
White="\[\033[1;37m\]"
WhiteE="\033[1;37m"
info-message () {
echo -e "${GreenE}$1${Color_OffE}"
}
important-message () {
echo -e "${YellowE}$1${Color_OffE}"
}
warning-message () {
echo -e "${RedE}$1${Color_OffE}"
}
export PS1HOST="$Red $HOSTIP $Color_Off"
if [[ $HOSTIP == $BASEHOSTIP ]]; then
export HOSTIP='HOME'
export PS1HOST="$Green $HOSTIP $Color_Off"
fi
export SHELLRC="~/.bashrc_$USER"
export SHELLCMD="bash --rcfile $SHELLRC -i"
export PS1="$Yellow[\@] $Red\#$Red$PS1HOST$Blue\u@\h$Yellow \w\n$Color_Off\$ "
if [ -n "$(type __git_ps1 2>/dev/null)" ]; then
export PS1="\$(__git_ps1) $PS1"
fi
__create-if-not-exist $WORKSPACE
__create-if-not-exist ~/.gdb
# Sources
__source-if-exist /etc/bashrc
__source-if-exist ~/.cargo/env
__source-if-exist /usr/share/doc/cdargs/examples/cdargs-bash.sh
__source-if-exist /etc/bash_completion
__path_append "$HOME/bin"
__path_append "$HOME/bin/depot_tools"
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
__path_prepend "$GOPATH/bin"
__path_prepend "$GOROOT/bin"
__path_prepend "$HOME/bin/node-v25.2.1-linux-arm64/bin"
# Aliases
if [[ $TMUX || $EXPALIAS ]]; then
shopt -s expand_aliases #expand aliases in non-interactive shell
fi
alias ss="source $SHELLRC"
# Generic
alias ainstall='sudo apt-get install'
alias asearch='sudo apt-cache search'
alias vim="env --unset=DISPLAY nvim -u ~/.vimrc"
alias ldd='bash ldd'
alias cursor-invisible='tput cinvis'
alias cursor-visible='tput cnorm'
alias reload-ssh-agent='eval `ssh-agent -s`; ssh-add ~/.ssh/nginx_id_rsa'
alias ssh-copy-id='ssh-copy-id -i ~/.ssh/id_rsa.pub'
# Interactive
# It's best if there's no output to stdout from login rc files such as ~/.bash_profile
# or ~/.profile since it can interfere with the proper operation of rsync for example.
if [[ $- == *i* ]]; then
if [ -n "$(__is-exist keychain)" ]; then
keychain -q --eval --agents ssh -Q --quiet id_rsa
fi
# disabling XOFF
if [[ -t 0 ]]; then
stty ixany
stty ixoff -ixon
fi
fi
# TMUX
# reload environment
if [ -n "$(__is-exist tmux)" ]; then
function tmux() {
local tmux=$(type -fp tmux)
case "$1" in
update-environment|update-env|env-update)
local v
while read v; do
echo "processing $v"
if [[ $v == -* ]]; then
v=$(echo "$v" | sed -e 's/=.*//')
unset ${v/#-/}
else
# Add quotes around the argument
v=${v/=/=\"}
v=${v/%/\"}
eval export $v
fi
done < <(tmux show-environment)
;;
*)
$tmux "$@"
;;
esac
}
fi
if [[ -n $PROJECT ]]; then
PROJECTPREFIX="${PROJECT}-"
else
PROJECTPREFIX=""
fi
alias tmux-enter-dev="~/.tmux/${PROJECTPREFIX}dev"
alias tmux-enter-aux="~/.tmux/${PROJECTPREFIX}aux"
alias tmux-kill-dev='tmux kill-session -t dev'
alias tmux-kill-aux='tmux kill-session -t aux'
vim-enter-session() {
info-message "Running vim..."
vim -S ~/.vimrc
}
vim-enter-clean-session() {
rm -fr ~/.vim/backups/*; rm -fr ~/.vim/sessions/$USER-$1.vim; vim-enter-session $1
}
# HOST only
if [[ $(hostname) == $BASEHOST ]]; then
alias elecard-open="DISPLAY=:0.0 xtightvncviewer $ELECARD_SERVER"
if [[ $(whoami) == $USER ]]; then
# Interactive
# It's best if there's no output to stdout from login rc files such as ~/.bash_profile
# or ~/.profile since it can interfere with the proper operation of rsync for example.
if [[ $- == *i* ]]; then
if [[ -z $TMUX ]]; then
echo "tmux-enter-dev - to enter development session"
echo "tmux-enter-aux - to enter aux session"
echo "WORKSPACE $WORKSPACE"
fi
fi
fi
fi
. "$HOME/.cargo/env"
. "$HOME/.local/bin/env"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment