Skip to content

Instantly share code, notes, and snippets.

@hose1021
Last active October 10, 2022 08:58
Show Gist options
  • Save hose1021/87ecf964237771ae4a854991586ffe3b to your computer and use it in GitHub Desktop.
Save hose1021/87ecf964237771ae4a854991586ffe3b to your computer and use it in GitHub Desktop.
.bashrc
###################################################################################################
# wget https://go.momar.de/bashrc -O ~/.bashrc
###################################################################################################
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# UTF-8 fix
export LANG=C.UTF-8
###########
## Color ##
###########
# Normal Bash
export PS1='\[\e[1;38;5;244m\]\t \[\e[1;36m\]\u@\H \[\e[1;33m\]\w \[\e[1;36m\]> \[\e[0m\]'
# export PS1="\u@\h \W\[\033[32m\]\$(__git_ps1)\[\033[00m\] $ "
# Alpine Linux / ash
# export PS1='\[\e[1;38;5;244m\]$(date +%H:%M:%S) \[\e[1;36m\]\u@\H \[\e[1;33m\]\w \[\e[1;36m\]\$ \[\e[0m\]'
# Termux (without user@host)
# export PS1='\[\e[1;38;5;244m\]\t \[\e[1;33m\]\w \[\e[1;36m\]\$ \[\e[0m\]'
# Minimal without path to working directory (~ $)
# export PS1='\[\e[1;33m\]\W \[\e[1;36m\]\$ \[\e[0m\]'
##################################
## ls, exa & more colored stuff ##
##################################
alias ls="ls --color=always"
alias ll="ls -l"
alias la="ls -lA"
for alias in lsl sls lsls sl l s; do alias $alias=ls; done
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
########################################
## Cool bash features nobody knows of ##
########################################
# search through history with up/down arrows
bind '"\e[A": history-search-backward' 2>/dev/null
bind '"\e[B": history-search-forward' 2>/dev/null
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
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
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
shopt -s globstar
#############################
## Warn about root shells! ##
#############################
if [ `id -u` -eq 0 ]; then
start="\033[1;37;41m"
end="\033[0m"
printf "\n"
printf " $start $end\n"
printf " $start WARNING: You are in a root shell. This is probably a very bad idea. $end\n"
printf " $start $end\n"
printf "\n"
fi
#########################
## Path & Applications ##
#########################
# Add ~/.local/bin to $PATH
export PATH="$HOME/.local/bin:$PATH"
#############################
## Awesome online services ##
#############################
# Send command output to qbin.io for quick & easy sharing (stored for 14 days)
# Usage: echo "Hello World" | qbin
alias qbin="curl https://qbin.io -s -T -"
# Upload bigger & binary files to transfer.sh (stored for 14 days)
# transfer anything.tar.gz
transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi; tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }
###########################
## Other helpful aliases ##
###########################
# A really simple password generator
alias pw='bash -c '"'"'echo `tr -dc $([ $# -gt 1 ] && echo $2 || echo "A-Za-z0-9") < /dev/urandom | head -c $([ $# -gt 0 ] && echo $1 || echo 30)`'"'"' --'
# Edit this .bashrc file
alias ebrc='nano -c ~/.bashrc'
# Change to the home directory
alias home='cd ~'
# Allow changing directory when missing a space
alias cd..='cd ..'
# Allow changing directory back when missing a space
alias cd-='cd -'
# Go back directories dot style
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# Go back directories dot dot number style
alias ..2='..; ..'
alias ..3='..2; ..'
alias ..4='..3; ..'
alias ..5='..4; ..'
# Show top ten processes
alias cpu='ps aux | sort -r -nk +4 | head | $PAGER'
# Show CPU information
alias cpuinfo='lscpu | $PAGER'
# Clear the screen with both clear and cls shorthand
alias {cls,c}='clear'
##################
## Custom stuff ##
##################
# I have a few environment variables (paths for Go & node.js) set in environment.d - I'd like to also use them in the terminal.
if [ "$(ls ~/.config/environment.d/ 2>/dev/null)" != "" ]; then
for f in ~/.config/environment.d/*; do
source "$f"
done
fi
# I'm using Tilix, which requires sourcing this script
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
if [ -e /etc/profile.d/vte.sh ]; then
source /etc/profile.d/vte.sh
fi
fi
# Function to run upon exit of shell
function _exit() {
# Show who logged out
local COLOR="\033[1;31m" # Light Red
local HIGHLIGHT="\033[1;34m" # Light Blue
local NOCOLOR="\033[0m"
echo -e "${COLOR}User ${HIGHLIGHT}$(echo $USER)${COLOR} has logged out of ${HIGHLIGHT}$(echo $HOSTNAME)${COLOR}.${NOCOLOR}"
}
trap _exit EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment