Skip to content

Instantly share code, notes, and snippets.

@drconopoima
Forked from arindam89/.bashrc
Last active August 30, 2019 06:01
Show Gist options
  • Save drconopoima/e5284e8be6d2f9b0a6036f63df24a960 to your computer and use it in GitHub Desktop.
Save drconopoima/e5284e8be6d2f9b0a6036f63df24a960 to your computer and use it in GitHub Desktop.
.bashrc example for a Ubuntu/OpenSUSE host with customized Prompt to visualize git branch and depth level, aliases for Backend tools for network (tcpdump, ngrep, ss), Python (Pyenv) and Node.js (NVM)
#
# ~/.bashrc
#
[[ $- != *i* ]] && return
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"
# foreground colors
for fgc in {30..37}; do
# background colors
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
}
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
# Change the window title of X terminals
case ${TERM} in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
;;
screen*)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
;;
esac
use_color=true
# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs} ]] \
&& type -P dircolors >/dev/null \
&& match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
if ${use_color} ; then
# Enable colors for ls, etc. Prefer ~/.dir_colors #64489
if type -P dircolors >/dev/null ; then
if [[ -f ~/.dir_colors ]] ; then
eval $(dircolors -b ~/.dir_colors)
elif [[ -f /etc/DIR_COLORS ]] ; then
eval $(dircolors -b /etc/DIR_COLORS)
fi
fi
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
else
PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] '
fi
alias ls='ls --color=auto'
alias ll='ls -AlF --color=auto'
alias la='ls -A --color=auto'
alias l='ls -CF --color=auto'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='\u@\h \W \$ '
else
PS1='\u@\h \w \$ '
fi
fi
alias cp="cp -i" # confirm before overwriting something
alias df='df -h' # human-readable sizes
alias free='free -m' # show sizes in MB
alias np='nano -w PKGBUILD'
alias more=less
xhost +local:root > /dev/null 2>&1
complete -cf sudo
# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control. #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize
shopt -s expand_aliases
# export QT_SELECT=4
# Enable history appending instead of overwriting. #139609
shopt -s histappend
#
# # ex - archive extractor
# # usage: ex <file>
ex ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $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
}
# better yaourt colors
export YAOURT_COLORS="nb=1:pkg=1:ver=1;32:lver=1;45:installed=1;42:grp=1;34:od=1;41;5:votes=1;44:dsc=0:other=1;35"
# NVM Root Directory
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pyenv Root Directory
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Customizations to history
export HISTCONTROL=ignoredups
export HISTIGNORE='&:bg:fg:ll:ls:h'
export HISTTIMEFORMAT='%H:%M > '
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
# Use a system alert to trigger after long commands finish running. 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$//'\'')"'
# Update all system packages, Flatpak, Snap, Pyenv, NVM and NERDTree Basics Vim In Parallel
alias update_all='sudo echo "Updating all system packages, Flatpak packages, Snap packages, and pyenv" && (sudo snap refresh & sudo flatpak update -y & pyenv update & curl -o- https://raw.githubusercontent.com/drconopoima/nerdtree-basics-vim/master/install.sh | bash & wait) && yay -Syyu && alert'
##################################################
# Color chart #
##################################################
txtBlack='\[\033[0;30m\]' # Black - Regular
txtRed='\[\033[0;31m\]' # Red
txtGreen='\[\033[0;32m\]' # Green
txtYellow='\[\033[0;33m\]' # Orange
txtBlue='\[\033[0;34m\]' # Blue
txtPurple='\[\033[0;35m\]' # Purple
txtCyan='\[\033[0;36m\]' # Cyan
txtWhite='\[\033[1;37m\]' # White
lightGray='\[\033[0;37m\]' # light Gray
lightBlack='\[\033[1;30m\]' # light Black
lightRed='\[\033[1;31m\]' # Red
lightGreen='\[\033[1;32m\]' # Green
lightYellow='\[\033[1;33m\]' # Yellow
lightBlue='\[\033[1;34m\]' # Blue
lightPurple='\[\033[1;35m\]' # Purple
lightCyan='\[\033[1;36m\]' # Cyan
underlineBlack='\[\033[4;30m\]' # Black - Underline
underlineRed='\[\033[4;31m\]' # Red
underlineGreen='\[\033[4;32m\]' # Green
underlineYellow='\[\033[4;33m\]' # Yellow
underlineBlue='\[\033[4;34m\]' # Blue
underlinePurple='\[\033[4;35m\]' # Purple
underlineCyan='\[\033[4;36m\]' # Cyan
underlineWhite='\[\033[4;37m\]' # White
backgroundBlack='\[\033[40m\]' # Black - Background
backgroundRed='\[\033[41m\]' # Red
backgroundGreen='\[\033[43m\]' # Green
backgroundYellow='\[\033[43m\]' # Yellow
backgroundBlue='\[\033[44m\]' # Blue
backgroundPurple='\[\033[45m\]' # Purple
backgroundCyan='\[\033[46m\]' # Cyan
backgroundWhite='\[\033[47m\]' # White
resetFormat='\[\033[0m\]' # Text Reset
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
if ${use_color}; then
## If within Git repository, display Branch as " [$BRANCH]" otherwise don't show brackets nor blank spaces.
## When color is green then git status is clean, when it's red then it's not
PS1='$(echo "'${resetFormat}'") $(if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet 2>/dev/null >&2; then echo "'${txtGreen}'"; else echo "'${txtRed}'"; fi fi)'
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(${lightCyan}Host:${resetFormat} ${txtBlue}\u${resetFormat}@${lightPurple}\h${resetFormat}) ${lightYellow}\W${PS1}"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}${txtYellow}$(((SHLVL>1))&&echo ' $SHLVL')${resetFormat}"
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
else
PS1=" "
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(Host: \u@\h) \W"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}$(((SHLVL>1))&&echo ' $SHLVL')\$ "
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
fi
unset use_color safe_term match_lhs sh
# Dir
alias home='cd'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
# alias linuxdoc='cd ~/linuxdoc'
alias music='cd ~/Music'
alias pix='cd ~/Pictures'
alias root='sudo -i'
alias linecount='wc -l $1' # count number of lines in text file
# Sudo
alias install='yay -Syy'
alias remove='yay -R'
alias update='yay -Syu'
# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# Misc
# alias a='alias'
# alias c='clear'
# alias h='htop'
# alias x='exit'
# alias bg='geany ~/.bashrc'
# alias pci='lspci'
# alias ksf='killall swiftfox-bin'
# alias del='rm --target-directory=$HOME/.local/share/Trash/'
alias font='fc-cache -v -f'
#Automatically do an ls after each cd
#cd() {
# if [ -n "$1" ]; then
# builtin cd "$@" && ll
# else
# builtin cd ~ && ll
# fi
#}
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gs="git svn"
# Network
alias tcp="ss -t"
# alias mtr="mtr -t"
# alias nmap="nmap -v -v -T5"
# alias nmapp="nmap -P0 -A --osscan_limit"
# alias pktstat="sudo pktstat -tBFT"
alias ngany="ngrep -d any"
alias tcpany="tcpdump -vvv -A -i any"
echo -ne "Hello, $USER. Today is "; date
### Thanks to @arindam89 awesome .bashrc, mine is only a fork with minor changes and updates and adding Git branch in prompt
# Check out his at: https://gist.github.com/arindam89/2873141
# Thanks to Jordi Martínez Lobo for some of the customizations
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't overwrite GNU Midnight Commander's setting of 'ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export 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)
# 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
# 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 color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
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
# 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 [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# 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; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#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
##################################################
# Color chart #
##################################################
txtBlack='\[\033[0;30m\]' # Black - Regular
txtRed='\[\033[0;31m\]' # Red
txtGreen='\[\033[0;32m\]' # Green
txtYellow='\[\033[0;33m\]' # Orange
txtBlue='\[\033[0;34m\]' # Blue
txtPurple='\[\033[0;35m\]' # Purple
txtCyan='\[\033[0;36m\]' # Cyan
txtWhite='\[\033[1;37m\]' # White
lightGray='\[\033[0;37m\]' # light Gray
lightBlack='\[\033[1;30m\]' # light Black
lightRed='\[\033[1;31m\]' # Red
lightGreen='\[\033[1;32m\]' # Green
lightYellow='\[\033[1;33m\]' # Yellow
lightBlue='\[\033[1;34m\]' # Blue
lightPurple='\[\033[1;35m\]' # Purple
lightCyan='\[\033[1;36m\]' # Cyan
underlineBlack='\[\033[4;30m\]' # Black - Underline
underlineRed='\[\033[4;31m\]' # Red
underlineGreen='\[\033[4;32m\]' # Green
underlineYellow='\[\033[4;33m\]' # Yellow
underlineBlue='\[\033[4;34m\]' # Blue
underlinePurple='\[\033[4;35m\]' # Purple
underlineCyan='\[\033[4;36m\]' # Cyan
underlineWhite='\[\033[4;37m\]' # White
backgroundBlack='\[\033[40m\]' # Black - Background
backgroundRed='\[\033[41m\]' # Red
backgroundGreen='\[\033[43m\]' # Green
backgroundYellow='\[\033[43m\]' # Yellow
backgroundBlue='\[\033[44m\]' # Blue
backgroundPurple='\[\033[45m\]' # Purple
backgroundCyan='\[\033[46m\]' # Cyan
backgroundWhite='\[\033[47m\]' # White
resetFormat='\[\033[0m\]' # Text Reset
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
if [ "$color_prompt" = yes ]; then
## If within Git repository, display Branch as " [$BRANCH]" otherwise don't show brackets nor blank spaces.
## When color is green then git status is clean, when it's red then it's not
PS1='$(echo "'${resetFormat}'") $(if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet 2>/dev/null >&2; then echo "'${txtGreen}'"; else echo "'${txtRed}'"; fi fi)'
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(${lightCyan}Host:${resetFormat} ${txtYellow}\u${resetFormat}@${lightPurple}\h${resetFormat}) ${lightYellow}\w${PS1}"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}${txtYellow}$(((SHLVL>1))&&echo ' $SHLVL')${resetFormat}"
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
else
PS1=" "
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(Host: \u@\h) \w"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}$(((SHLVL>1))&&echo ' $SHLVL')\$ "
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
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;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
###########
# Aliases #
###########
# ls
alias ll='ls -AlF'
alias la='ls -A'
alias l='ls -CF'
# Dir
alias home='cd'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
# alias linuxdoc='cd ~/linuxdoc'
alias music='cd ~/Music'
alias pix='cd ~/Pictures'
alias root='sudo -i'
alias linecount='wc -l $1' # count number of lines in text file
# Sudo
alias install='sudo apt install'
alias remove='sudo apt remove'
alias purge='sudo apt remove --purge'
alias update='sudo pkcon update'
# alias sources='(gksudo geany /etc/apt/sources.list &)'
# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# Misc
# alias a='alias'
# alias c='clear'
# alias h='htop'
# alias x='exit'
# alias bg='geany ~/.bashrc'
# alias pci='lspci'
# alias ksf='killall swiftfox-bin'
# alias del='rm --target-directory=$HOME/.local/share/Trash/'
alias font='fc-cache -v -f'
# Custom Oracle related
# alias root='/usr/local/packages/aime/ias/run_as_root "su root"'
#Automatically do an ls after each cd
#cd() {
# if [ -n "$1" ]; then
# builtin cd "$@" && ll
# else
# builtin cd ~ && ll
# fi
#}
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gsvn="git svn"
# Network
alias tcp="ss -t"
# alias mtr="mtr -t"
# alias nmap="nmap -v -v -T5"
# alias nmapp="nmap -P0 -A --osscan_limit"
# alias pktstat="sudo pktstat -tBFT"
alias ngany="ngrep -d any"
alias tcpany="tcpdump -vvv -A -i any"
# Use a system alert to trigger after long commands finish running. Use like so:
# sleep 10; alert
# You may need to install with "sudo pkcon install libnotify-bin"
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$//'\'')"'
test -s ~/.alias && . ~/.alias || true
export PATH=$PATH:/home/ljdm/.local/bin
################################################
# Update Packages, snaps, flatpaks, Pyenv, NVM #
################################################
alias update_all='sudo echo "Updating all system packages, Flatpak packages, Snap packages, and pyenv" && (sudo snap refresh & sudo flatpak update -y & pyenv update & curl -o- https://raw.githubusercontent.com/drconopoima/nerdtree-basics-vim/master/install.sh | sh & wait) && sudo pkcon update && alert'
### From inameiname's Ultimate bashrc file
# at Gnome-Look.org
# https://www.gnome-look.org/p/1115107/
export EDITOR='vim'
export HISTIGNORE='&:bg:fg:ll:h:ls'
export HISTTIMEFORMAT='%H:%M > '
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
unset HISTFILESIZE # infinite History
unset HISTSIZE # infinite History
### Thanks to @arindam89 awesome .bashrc, mine is only a fork with minor changes and updates and adding Git branch in prompt
# Check out his at: https://gist.github.com/arindam89/2873141
# Thanks to Jordi Martínez Lobo for some of the customizations
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't overwrite GNU Midnight Commander's setting of 'ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export 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)
# 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
# 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 color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
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
# 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 [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# 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; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#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
##################################################
# Color chart #
##################################################
txtBlack='\[\033[0;30m\]' # Black - Regular
txtRed='\[\033[0;31m\]' # Red
txtGreen='\[\033[0;32m\]' # Green
txtYellow='\[\033[0;33m\]' # Orange
txtBlue='\[\033[0;34m\]' # Blue
txtPurple='\[\033[0;35m\]' # Purple
txtCyan='\[\033[0;36m\]' # Cyan
txtWhite='\[\033[1;37m\]' # White
lightGray='\[\033[0;37m\]' # light Gray
lightBlack='\[\033[1;30m\]' # light Black
lightRed='\[\033[1;31m\]' # Red
lightGreen='\[\033[1;32m\]' # Green
lightYellow='\[\033[1;33m\]' # Yellow
lightBlue='\[\033[1;34m\]' # Blue
lightPurple='\[\033[1;35m\]' # Purple
lightCyan='\[\033[1;36m\]' # Cyan
underlineBlack='\[\033[4;30m\]' # Black - Underline
underlineRed='\[\033[4;31m\]' # Red
underlineGreen='\[\033[4;32m\]' # Green
underlineYellow='\[\033[4;33m\]' # Yellow
underlineBlue='\[\033[4;34m\]' # Blue
underlinePurple='\[\033[4;35m\]' # Purple
underlineCyan='\[\033[4;36m\]' # Cyan
underlineWhite='\[\033[4;37m\]' # White
backgroundBlack='\[\033[40m\]' # Black - Background
backgroundRed='\[\033[41m\]' # Red
backgroundGreen='\[\033[43m\]' # Green
backgroundYellow='\[\033[43m\]' # Yellow
backgroundBlue='\[\033[44m\]' # Blue
backgroundPurple='\[\033[45m\]' # Purple
backgroundCyan='\[\033[46m\]' # Cyan
backgroundWhite='\[\033[47m\]' # White
resetFormat='\[\033[0m\]' # Text Reset
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
if [ "$color_prompt" = yes ]; then
## If within Git repository, display Branch as " [$BRANCH]" otherwise don't show brackets nor blank spaces.
## When color is green then git status is clean, when it's red then it's not
PS1='$(echo "'${resetFormat}'") $(if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet 2>/dev/null >&2; then echo "'${txtGreen}'"; else echo "'${txtRed}'"; fi fi)'
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(${lightCyan}Host:${resetFormat} ${txtYellow}\u${resetFormat}@${lightPurple}\h${resetFormat}) ${lightYellow}\w${PS1}"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}${txtYellow}$(((SHLVL>1))&&echo ' $SHLVL')${resetFormat}"
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
else
PS1=" "
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(Host: \u@\h) \w"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}$(((SHLVL>1))&&echo ' $SHLVL')\$ "
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
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;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
###########
# Aliases #
###########
# ls
alias ll='ls -AlF'
alias la='ls -A'
alias l='ls -CF'
# Dir
alias home='cd'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
# alias linuxdoc='cd ~/linuxdoc'
alias music='cd ~/Music'
alias pix='cd ~/Pictures'
alias root='sudo -i'
alias linecount='wc -l $1' # count number of lines in text file
# Sudo
alias install='sudo apt install'
alias remove='sudo apt remove'
alias purge='sudo apt remove --purge'
alias update='pkcon refresh && sudo pkcon update'
# alias sources='(gksudo geany /etc/apt/sources.list &)'
# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# Misc
# alias a='alias'
# alias c='clear'
# alias h='htop'
# alias x='exit'
# alias bg='geany ~/.bashrc'
# alias pci='lspci'
# alias ksf='killall swiftfox-bin'
# alias del='rm --target-directory=$HOME/.local/share/Trash/'
alias font='fc-cache -v -f'
# Custom Oracle related
# alias root='/usr/local/packages/aime/ias/run_as_root "su root"'
#Automatically do an ls after each cd
#cd() {
# if [ -n "$1" ]; then
# builtin cd "$@" && ll
# else
# builtin cd ~ && ll
# fi
#}
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gsvn="git svn"
# Network
alias tcp="ss -t"
# alias mtr="mtr -t"
# alias nmap="nmap -v -v -T5"
# alias nmapp="nmap -P0 -A --osscan_limit"
# alias pktstat="sudo pktstat -tBFT"
alias ngany="ngrep -d any"
alias tcpany="tcpdump -vvv -A -i any"
# Use a system alert to trigger after long commands finish running. Use like so:
# sleep 10; alert
# You may need to install with "sudo pkcon install libnotify-bin"
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$//'\'')"'
test -s ~/.alias && . ~/.alias || true
export PATH=$PATH:/home/ljdm/.local/bin
################################################
# Update Packages, snaps, flatpaks, Pyenv, NVM #
################################################
alias update_all='sudo echo "Updating all system packages, Flatpak packages, Snap packages, and pyenv" && (sudo snap refresh & sudo flatpak update -y & pyenv update & curl -o- https://raw.githubusercontent.com/drconopoima/nerdtree-basics-vim/master/install.sh | bash & wait) && pkcon refresh && sudo pkcon update && alert'
### From inameiname's Ultimate bashrc file
# at Gnome-Look.org
# https://www.gnome-look.org/p/1115107/
export EDITOR='vim'
export HISTIGNORE='&:bg:fg:ll:h:ls'
export HISTTIMEFORMAT='%H:%M > '
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
unset HISTFILESIZE # infinite History
unset HISTSIZE # infinite History
# function Extract for common file formats
# extract.sh Credit due to XVOLAND at repo https://github.com/xvoland/Extract
SAVEIFS=$IFS
IFS="$(printf '\n\t')"
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*.zpaq) zpaq x ./"$n" ;;
*.arc) arc e ./"$n" ;;
*.cso) ciso 0 ./"$n" ./"$n.iso" && \
extract $n.iso && \rm -f $n ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
IFS=$SAVEIFS
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
##################
# WELCOME SCREEN #
##################
echo -ne "Hello, $USER. Today is "; date
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
##################
# WELCOME SCREEN #
##################
echo -ne "Hello, $USER. Today is "; date
### Thanks to @arindam89 awesome .bashrc, mine is only a fork with minor changes and compatibility with OpenSUSE
# Check out his for Ubuntu at: https://gist.github.com/arindam89/2873141
# Thanks to Jordi Martínez Lobo for some of the customizations
# Thanks to inameiname's "Ultimate Bashrc file" at Gnome-Look.org
# https://www.gnome-look.org/p/1115107/
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't overwrite GNU Midnight Commander's setting of 'ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export 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)
# 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
# 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 color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
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
# 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 [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# 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; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#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
##################################################
# Color chart #
##################################################
txtBlack='\[\033[0;30m\]' # Black - Regular
txtRed='\[\033[0;31m\]' # Red
txtGreen='\[\033[0;32m\]' # Green
txtYellow='\[\033[0;33m\]' # Orange
txtBlue='\[\033[0;34m\]' # Blue
txtPurple='\[\033[0;35m\]' # Purple
txtCyan='\[\033[0;36m\]' # Cyan
txtWhite='\[\033[1;37m\]' # White
lightGray='\[\033[0;37m\]' # light Gray
lightBlack='\[\033[1;30m\]' # light Black
lightRed='\[\033[1;31m\]' # Red
lightGreen='\[\033[1;32m\]' # Green
lightYellow='\[\033[1;33m\]' # Yellow
lightBlue='\[\033[1;34m\]' # Blue
lightPurple='\[\033[1;35m\]' # Purple
lightCyan='\[\033[1;36m\]' # Cyan
underlineBlack='\[\033[4;30m\]' # Black - Underline
underlineRed='\[\033[4;31m\]' # Red
underlineGreen='\[\033[4;32m\]' # Green
underlineYellow='\[\033[4;33m\]' # Yellow
underlineBlue='\[\033[4;34m\]' # Blue
underlinePurple='\[\033[4;35m\]' # Purple
underlineCyan='\[\033[4;36m\]' # Cyan
underlineWhite='\[\033[4;37m\]' # White
backgroundBlack='\[\033[40m\]' # Black - Background
backgroundRed='\[\033[41m\]' # Red
backgroundGreen='\[\033[43m\]' # Green
backgroundYellow='\[\033[43m\]' # Yellow
backgroundBlue='\[\033[44m\]' # Blue
backgroundPurple='\[\033[45m\]' # Purple
backgroundCyan='\[\033[46m\]' # Cyan
backgroundWhite='\[\033[47m\]' # White
resetFormat='\[\033[0m\]' # Text Reset
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
if [ "$color_prompt" = yes ]; then
## If within Git repository, display Branch as " [$BRANCH]" otherwise don't show brackets nor blank spaces.
## When color is green then git status is clean, when it's red then it's not
PS1='$(echo "'${resetFormat}'") $(if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet 2>/dev/null >&2; then echo "'${txtGreen}'"; else echo "'${txtRed}'"; fi fi)'
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(${lightCyan}Host:${resetFormat} ${txtBlue}\u${resetFormat}@${lightPurple}\h${resetFormat}) ${lightYellow}\w${PS1}"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}${txtYellow}$(((SHLVL>1))&&echo ' $SHLVL')${resetFormat}"
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
else
PS1=" "
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(Host: \u@\h) \w"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}$(((SHLVL>1))&&echo ' $SHLVL')\$ "
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
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;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
###########
# Aliases #
###########
# ls
alias ll='ls -AlF'
alias la='ls -A'
alias l='ls -CF'
# Dir
alias home='cd'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
# alias linuxdoc='cd ~/linuxdoc'
alias music='cd ~/Music'
alias pix='cd ~/Pictures'
alias root='sudo -i'
alias linecount='wc -l $1' # count number of lines in text file
# Sudo
alias install='sudo zypper in'
alias remove='sudo zypper rm'
alias purge='sudo zypper rm --clean-deps'
alias update='sudo zypper ref'
# alias sources='(gksudo geany /etc/apt/sources.list &)'
# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# Misc
# alias a='alias'
# alias c='clear'
# alias h='htop'
# alias x='exit'
# alias bg='geany ~/.bashrc'
# alias pci='lspci'
# alias ksf='killall swiftfox-bin'
# alias del='rm --target-directory=$HOME/.local/share/Trash/'
alias font='fc-cache -v -f'
# Custom Oracle related
# alias root='/usr/local/packages/aime/ias/run_as_root "su root"'
#Automatically do an ls after each cd
#cd() {
# if [ -n "$1" ]; then
# builtin cd "$@" && ll
# else
# builtin cd ~ && ll
# fi
#}
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gs="git svn"
# Network
alias tcp="ss -t"
# alias mtr="mtr -t"
# alias nmap="nmap -v -v -T5"
# alias nmapp="nmap -P0 -A --osscan_limit"
# alias pktstat="sudo pktstat -tBFT"
alias ngany="ngrep -d any"
alias tcpany="tcpdump -vvv -A -i any"
# Use a system alert to trigger after long commands finish running. Use like so:
# sleep 10; alert
# You may need to install with "sudo zypper in libnotify-tools"
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$//'\'')"'
test -s ~/.alias && . ~/.alias || true
export PATH=$PATH:/home/ljdm/.local/bin
################################################
# Update Packages, snaps, flatpaks, Pyenv, NVM #
################################################
alias update_all='sudo echo "Updating all system packages, Flatpak packages, Snap packages, and pyenv" && (sudo snap refresh & sudo flatpak update -y & pyenv update & curl -o- https://raw.githubusercontent.com/drconopoima/nerdtree-basics-vim/master/install.sh | bash & wait) && sudo zypper ref && sudo zypper update && alert'
### From inameiname's Ultimate bashrc file
# at Gnome-Look.org
# https://www.gnome-look.org/p/1115107/
export EDITOR='vim'
export HISTIGNORE='&:bg:fg:ll:h'
export HISTTIMEFORMAT='%H:%M > '
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
unset HISTFILESIZE # infinite History
unset HISTSIZE # infinite History
##################################################
# Extract - extract most common compression #
# types #
##################################################
function extract() {
local e=0 i c
for i; do
if [[ -f $i && -r $i ]]; then
c=''
case $i in
*.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz)))))
c='bsdtar xvf' ;;
*.7z) c='7z x' ;;
*.Z) c='uncompress' ;;
*.bz2) c='bunzip2' ;;
*.exe) c='cabextract' ;;
*.gz) c='gunzip' ;;
*.rar) c='unrar x' ;;
*.xz) c='unxz' ;;
*.zip) c='unzip' ;;
*) echo "$0: cannot extract \`$i': Unrecognized file extension" >&2; e=1 ;;
esac
[[ $c ]] && command $c "$i"
else
echo "$0: cannot extract \`$i': File is unreadable" >&2; e=2
fi
done
return $e
}
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
##################
# WELCOME SCREEN #
##################
screenfetch
echo -ne "Hello, $USER. Today is "; date
### Thanks to @arindam89 awesome .bashrc, mine is only a fork with minor changes and updates and adding Git branch in prompt
# Check out his at: https://gist.github.com/arindam89/2873141
# Thanks to Jordi Martínez Lobo for some of the customizations
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't overwrite GNU Midnight Commander's setting of 'ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export 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)
# 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
# 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 color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
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
# 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 [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# 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; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#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
##################################################
# Color chart #
##################################################
txtBlack='\[\033[0;30m\]' # Black - Regular
txtRed='\[\033[0;31m\]' # Red
txtGreen='\[\033[0;32m\]' # Green
txtYellow='\[\033[0;33m\]' # Orange
txtBlue='\[\033[0;34m\]' # Blue
txtPurple='\[\033[0;35m\]' # Purple
txtCyan='\[\033[0;36m\]' # Cyan
txtWhite='\[\033[1;37m\]' # White
lightGray='\[\033[0;37m\]' # light Gray
lightBlack='\[\033[1;30m\]' # light Black
lightRed='\[\033[1;31m\]' # Red
lightGreen='\[\033[1;32m\]' # Green
lightYellow='\[\033[1;33m\]' # Yellow
lightBlue='\[\033[1;34m\]' # Blue
lightPurple='\[\033[1;35m\]' # Purple
lightCyan='\[\033[1;36m\]' # Cyan
underlineBlack='\[\033[4;30m\]' # Black - Underline
underlineRed='\[\033[4;31m\]' # Red
underlineGreen='\[\033[4;32m\]' # Green
underlineYellow='\[\033[4;33m\]' # Yellow
underlineBlue='\[\033[4;34m\]' # Blue
underlinePurple='\[\033[4;35m\]' # Purple
underlineCyan='\[\033[4;36m\]' # Cyan
underlineWhite='\[\033[4;37m\]' # White
backgroundBlack='\[\033[40m\]' # Black - Background
backgroundRed='\[\033[41m\]' # Red
backgroundGreen='\[\033[43m\]' # Green
backgroundYellow='\[\033[43m\]' # Yellow
backgroundBlue='\[\033[44m\]' # Blue
backgroundPurple='\[\033[45m\]' # Purple
backgroundCyan='\[\033[46m\]' # Cyan
backgroundWhite='\[\033[47m\]' # White
resetFormat='\[\033[0m\]' # Text Reset
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
if [ "$color_prompt" = yes ]; then
## If within Git repository, display Branch as " [$BRANCH]" otherwise don't show brackets nor blank spaces.
## When color is green then git status is clean, when it's red then it's not
PS1='$(echo "'${resetFormat}'") $(if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet 2>/dev/null >&2; then echo "'${txtGreen}'"; else echo "'${txtRed}'"; fi fi)'
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(${lightCyan}Host:${resetFormat} ${txtYellow}\u${resetFormat}@${lightPurple}\h${resetFormat}) ${lightYellow}\w${PS1}"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}${txtYellow}$(((SHLVL>1))&&echo ' $SHLVL')${resetFormat}"
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
else
PS1=" "
PS1+='$(git_prompt)'
## Display "(Host: $USER@$HOSTNAME) $PWD". When working with containers/VMs, remove "Host:" to keep track of your Host shell.
PS1="(Host: \u@\h) \w"
## If the shell depth is higher than 1, display shell depth
PS1="${PS1}$(((SHLVL>1))&&echo ' $SHLVL')\$ "
# If you prefer cursor in new line
PS1="${PS1}\n└─\$ "
# Otherwise
# PS1="${PS1}\$ "
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;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
###########
# Aliases #
###########
# ls
alias ll='ls -AlF'
alias la='ls -A'
alias l='ls -CF'
# Dir
alias home='cd'
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
# alias linuxdoc='cd ~/linuxdoc'
alias music='cd ~/Music'
alias pix='cd ~/Pictures'
alias root='sudo -i'
alias linecount='wc -l $1' # count number of lines in text file
# Sudo
alias install='sudo apt install'
alias remove='sudo apt remove'
alias purge='sudo apt remove --purge'
alias update='sudo apt update && sudo apt upgrade'
# alias sources='(gksudo geany /etc/apt/sources.list &)'
# chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# Misc
# alias a='alias'
# alias c='clear'
# alias h='htop'
# alias x='exit'
# alias bg='geany ~/.bashrc'
# alias pci='lspci'
# alias ksf='killall swiftfox-bin'
# alias del='rm --target-directory=$HOME/.local/share/Trash/'
alias font='fc-cache -v -f'
# Custom Oracle related
# alias root='/usr/local/packages/aime/ias/run_as_root "su root"'
#Automatically do an ls after each cd
#cd() {
# if [ -n "$1" ]; then
# builtin cd "$@" && ll
# else
# builtin cd ~ && ll
# fi
#}
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gsvn="git svn"
# Network
alias tcp="ss -t"
# alias mtr="mtr -t"
# alias nmap="nmap -v -v -T5"
# alias nmapp="nmap -P0 -A --osscan_limit"
# alias pktstat="sudo pktstat -tBFT"
alias ngany="ngrep -d any"
alias tcpany="tcpdump -vvv -A -i any"
# Use a system alert to trigger after long commands finish running. Use like so:
# sleep 10; alert
# You may need to install with "sudo apt install libnotify-bin"
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$//'\'')"'
test -s ~/.alias && . ~/.alias || true
export PATH=$PATH:/home/ljdm/.local/bin
################################################
# Update Packages, snaps, flatpaks, Pyenv, NVM #
################################################
alias update_all='sudo echo "Updating all system packages, Flatpak packages, Snap packages, and pyenv" && (sudo snap refresh & sudo flatpak update -y & pyenv update & curl -o- https://raw.githubusercontent.com/drconopoima/nerdtree-basics-vim/master/install.sh | bash & wait) && sudo apt update && sudo apt upgrade && alert'
### From inameiname's Ultimate bashrc file
# at Gnome-Look.org
# https://www.gnome-look.org/p/1115107/
export EDITOR='vim'
export HISTIGNORE='&:bg:fg:ll:h:ls'
export HISTTIMEFORMAT='%H:%M > '
export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format
unset HISTFILESIZE # infinite History
unset HISTSIZE # infinite History
# function Extract for common file formats
# extract.sh Credit due to XVOLAND at repo https://github.com/xvoland/Extract
SAVEIFS=$IFS
IFS="$(printf '\n\t')"
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*.zpaq) zpaq x ./"$n" ;;
*.arc) arc e ./"$n" ;;
*.cso) ciso 0 ./"$n" ./"$n.iso" && \
extract $n.iso && \rm -f $n ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
IFS=$SAVEIFS# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
##################
# WELCOME SCREEN #
##################
echo -ne "Hello, $USER. Today is "; date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment