Skip to content

Instantly share code, notes, and snippets.

@drconopoima
Last active April 10, 2023 21:24
Show Gist options
  • Save drconopoima/81c35bc446945aeab7c74404b7deceb6 to your computer and use it in GitHub Desktop.
Save drconopoima/81c35bc446945aeab7c74404b7deceb6 to your computer and use it in GitHub Desktop.
basrc color prompt chroot extract
#!/usr/bin/env bash
# ~/.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
# 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
export HISTIGNORE='&:bg:fg:ll:h:ls:update_all'
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
# for unsetting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=9999999999 # infinite History
HISTFILESIZE=9999999999 # infinite History
# 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
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying a chroot you work in (used in the prompt below)
if [ "$(awk '$5=="/" {print $file_name}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $file_name}' </proc/$$/mountinfo)" ]; then
chroot="(chroot)"
fi
##############################################################
# Colored git branch in bash prompt. Credits: Tobias Sjösten #
# http://vvv.tobiassjosten.net/git/add-current-git-branch-to-your-bash-prompt/
function git_current_branch() {
local ref
local return_code
ref="$(GIT_OPTIONAL_LOCKS=0 git symbolic-ref --quiet HEAD 2> /dev/null)"
local return_code="$?"
[[ $return_code == 128 ]] && return # no git repo.
if [[ $return_code != 0 ]]; then
ref="$(GIT_OPTIONAL_LOCKS=0 git rev-parse --short HEAD 2> /dev/null)" || return
fi
echo -n "${ref#refs/heads/}"
}
git_commit ()
{
if ! GIT_OPTIONAL_LOCKS=0 git symbolic-ref --quiet HEAD > /dev/null 2>&1; then
return 0 # no git repo.
fi
commit=$(GIT_OPTIONAL_LOCKS=0 git log -1 --pretty=format:%h 2>/dev/null | cat)
echo -n "${commit}"
}
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# enable color support of ls and also 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
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
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
# dependency 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$//'\'')"'
# 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
PATH="$HOME/.nvm/versions/node/v18.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$HOME/.local/bin:$HOME/bin:/usr/games:/usr/local/games:/snap/bin:$PATH"
PROMPT_DIRTRIM=3
# Define a few Colours
BLACK='\[\033[0;30m\]'
BLUE='\[\033[0;34m\]'
GREEN='\[\033[0;32m\]'
CYAN='\[\033[0;36m\]'
RED='\[\033[0;31m\]'
YELLOW='\[\033[0;33m\]'
PURPLE='\[\033[0;35m\]'
BROWN='\[\033[0;33m\]'
LIGHTGRAY='\[\033[0;37m\]'
DARKGRAY='\[\033[0;90m\]'
LIGHTBLUE='\[\033[0;94m\]'
LIGHTGREEN='\[\033[0;92m\]'
LIGHTCYAN='\[\33[0;96m\]'
LIGHTRED='\[\033[0;91m\]'
LIGHTPURPLE='\[\033[1;35m\]'
LIGHTYELLOW='\[\033[1;33m\]'
WHITE='\[\033[1;37m\]'
# No Color
NC='\[\033[0m\]'
# 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
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="(${YELLOW}\u${NC}@${LIGHTPURPLE}\h${NC})${chroot} \w "
PS1+='$(if GIT_OPTIONAL_LOCKS=0 git rev-parse --git-dir > /dev/null 2>&1; then if GIT_OPTIONAL_LOCKS=0 git diff --quiet > /dev/null 2>&1; then echo -n "['${LIGHTGREEN}'"; else echo -n "['${RED}'"; fi; fi)'
PS1+='$(git_current_branch)$(if GIT_OPTIONAL_LOCKS=0 git rev-parse --git-dir > /dev/null 2>&1; then echo -n "'${YELLOW}'@"; fi)$(if GIT_OPTIONAL_LOCKS=0 git rev-parse --git-dir > /dev/null 2>&1; then echo -n "$(git_commit)'${NC}']"; fi)'
## If the shell depth is higher than 1, display shell depth
PS1+="${YELLOW}$( ((SHLVL>1))&&echo -n ' $SHLVL')${NC}"
# If you prefer cursor in new line
PS1+="\n└─\$ "
# Otherwise
# PS1+="${PS1}\$ "
else
PS1="(\u@\h)${chroot} \w "
PS1+='$(git_current_branch)$(if GIT_OPTIONAL_LOCKS=0 git rev-parse --git-dir > /dev/null 2>&1; then echo -n "@"; fi)$(if GIT_OPTIONAL_LOCKS=0 git rev-parse --git-dir > /dev/null 2>&1; then echo -n "$(git_commit)]"; fi)'
## If the shell depth is higher than 1, display shell depth
PS1+="$( ((SHLVL>1))&&echo -n ' $SHLVL')"
# If you prefer cursor in new line
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;${chroot}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
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
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# function Extract for common file formats
# extract.sh Credit due to XVOLAND at repo https://github.com/xvoland/Extract
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 file_name in "$@"; do
if [ -f "$file_name" ] ; then
case "${file_name%,}" in
*.tar.bz2) tar xvjf $file_name ;;
*.tar.gz) tar xvzf $file_name ;;
*.bz2) bunzip2 $file_name ;;
*.rar) unrar x $file_name ;;
*.gz) gunzip $file_name ;;
*.tar) tar xvf $file_name ;;
*.tbz2) tar xvjf $file_name ;;
*.tgz) tar xvzf $file_name ;;
*.cbz|*.epub|*.jar|*.zip) unzip $file_name ;;
*.Z) uncompress $file_name ;;
*.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar) 7z x $file_name ;;
*.lzma) unlzma ./$file_name ;;
*.xz) unxz $file_name ;;
*.cpio) cpio -id < $file_name ;;
*.cba|*.ace) unace x $file_name ;;
*.zpaq) zpaq x $file_name ;;
*.arc) arc e $file_name ;;
*.cso) ciso 0 $file_name $file_name.iso && \
extract $file_name.iso && \
rm -f $file_name ;;
*) echo "don't know how to extract '$file_name'..." ;;
esac
fi
done
fi
}
##################
# WELCOME SCREEN #
##################
neofetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment