Skip to content

Instantly share code, notes, and snippets.

@GermaniumSystem
Last active December 13, 2019 02:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GermaniumSystem/559f6048c2268e1bae02d9b177b4a489 to your computer and use it in GitHub Desktop.
Save GermaniumSystem/559f6048c2268e1bae02d9b177b4a489 to your computer and use it in GitHub Desktop.
Personal .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
### see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
### for examples
### If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
### Unset the PROMPT_COMMAND variable. It likes to cause problems.
unset PROMPT_COMMAND
### Create a function for converting seconds to human-readable. Used in command runtime.
function seconds2human {
T=$1
D=$((T/60/60/24))
H=$((T/60/60%24))
M=$((T/60%60))
S=$((T%60))
if [[ ${D} != 0 ]] ; then
printf '%d days %02d:%02d:%02d' $D $H $M $S
elif [[ ${H} != 0 ]] ; then
printf '%02d:%02d:%02d' $H $M $S
else
printf '%02d:%02d' $M $S
fi
}
### Calculate command runtime for the PS1 prompt. Thanks Jake McCrary!
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(seconds2human $(($SECONDS - $timer)))
unset timer
}
trap 'timer_start' DEBUG
if [ "$PROMPT_COMMAND" == "" ]; then
PROMPT_COMMAND="timer_stop"
else
PROMPT_COMMAND="$PROMPT_COMMAND; timer_stop"
fi
### Add a silly "Magic 8-Ball" command.
function 8ball {
local ANSWERS=("It is certain"\
"It is decidedly so"\
"Without a doubt"\
"Yes, definitely"\
"You may rely on it"\
"As I see it, yes"\
"Most likely"\
"Outlook good"\
"Yes"\
"Signs point to yes"\
"Reply hazy try again"\
"Ask again later"\
"Better not tell you now"\
"Cannot predict now"\
"Concentrate and ask again"\
"Don't count on it"\
"My reply is no"\
"My sources say no"\
"Outlook not so good"\
"Very doubtful")
echo "${ANSWERS[$(($RANDOM % ${#ANSWERS[@]}))]}"
}
### Handy sed statement to remove newlines.
function sedNewline {
echo "Try this: sed ':a;N;\$!ba;s/\\n/ /g' file"
}
### 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
### Make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
### Set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
### Make sure we get fancy colors. Comment to disable.
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1="\[\033[38;5;255m\][\[$(tput sgr0)\]\[\033[38;5;39m\]\u\[$(tput sgr0)\]\[\033[38;5;255m\]@\[$(tput sgr0)\]\[\033[38;5;172m\]\h\[$(tput sgr0)\]\[\033[38;5;255m\]:\[$(tput sgr0)\]\[\033[38;5;39m\]\w\[$(tput sgr0)\]\[\033[38;5;255m\]][\[$(tput sgr0)\]\[\033[38;5;172m\]\$timer_show\[$(tput sgr0)\]\[\033[38;5;255m\]][\[$(tput sgr0)\]\[\033[38;5;39m\]\$?\[$(tput sgr0)\]\[\033[38;5;255m\]]\[$(tput sgr0)\]\[\033[38;5;15m\]\n\[$(tput sgr0)\]\[\033[38;5;39m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"
else
PS1="[\u@\h:\w][\$timer_show][\$?]\n\\$ \[$(tput sgr0)\]"
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="\[\033[38;5;255m\][\[$(tput sgr0)\]\[\033[38;5;39m\]\u\[$(tput sgr0)\]\[\033[38;5;255m\]@\[$(tput sgr0)\]\[\033[38;5;172m\]\h\[$(tput sgr0)\]\[\033[38;5;255m\]:\[$(tput sgr0)\]\[\033[38;5;39m\]\w\[$(tput sgr0)\]\[\033[38;5;255m\]][\[$(tput sgr0)\]\[\033[38;5;172m\]\$timer_show\[$(tput sgr0)\]\[\033[38;5;255m\]][\[$(tput sgr0)\]\[\033[38;5;39m\]\$?\[$(tput sgr0)\]\[\033[38;5;255m\]]\[$(tput sgr0)\]\[\033[38;5;15m\]\n\[$(tput sgr0)\]\[\033[38;5;39m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"
;;
*)
;;
esac
### Enable color support for common commands.
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
### Some ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias lh='ls -lah'
alias l.='ls -d .*'
### Some aliases to save my ass.
alias rm='rm --preserve-root'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
### Some 'fun' aliases to make admin work just a bit less soul crushing.
alias fucking='sudo'
alias ffs='sudo $(fc -ln -1)'
### 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$//'\'')"'
### Alias definitions.
### 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
### 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).
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment