Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # /etc/bash.bashrc
- #
- # https://wiki.archlinux.org/index.php/Color_Bash_Prompt
- #
- # This file is sourced by all *interactive* bash shells on startup,
- # including some apparently interactive shells such as scp and rcp
- # that can't tolerate any output. So make sure this doesn't display
- # anything or bad things will happen !
- # Test for an interactive shell. There is no need to set anything
- # past this point for scp and rcp, and it's important to refrain from
- # outputting anything in those cases.
- # If not running interactively, don't do anything!
- [[ $- != *i* ]] && return
- # 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 and update the values of LINES and COLUMNS.
- # http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
- shopt -s checkwinsize
- # Enable history appending instead of overwriting.
- shopt -s histappend
- # don't put duplicate lines in the history. See bash(1) for more options
- # ... or force ignoredups and ignorespace
- HISTCONTROL=ignoredups:ignorespace
- # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
- HISTSIZE=1000
- HISTFILESIZE=2000
- # 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.
- # sanitize TERM:
- safe_term=${TERM//[^[:alnum:]]/?}
- 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)
- if [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] ; then
- # we have colors :-)
- # Enable colors for ls, etc. Prefer ~/.dir_colors
- 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
- # enable color support of ls and also add handy aliases
- alias ls='ls --color=auto'
- alias grep='grep --color=auto'
- alias fgrep='fgrep --color=auto'
- alias egrep='egrep --color=auto'
- fi
- PS2="> "
- PS3="> "
- PS4="+ "
- # Try to keep environment pollution down, EPA loves us.
- unset safe_term match_lhs
- # custom Bash alias
- alias ll='ls -alF'
- alias la='ls -A'
- alias l='ls -CF'
- alias murder='kill -9'
- # Add an "alert" alias for long running commands. Use: 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 ..="cd .."
- alias ...="cd ../.."
- alias ....="cd ../../.."
- alias .....="cd ../../../.."
- alias list="ls -a"
- alias man="man -a"
- alias delete="rm -iv"
- alias rm="rm -iv"
- alias trash="rm -rf ~/.local/share/Trash/"
- alias :q="exit"
- alias home="cd ~"
- alias unmount="umount"
- alias clear="reset"
- alias cdopen="eject"
- alias cdclose="eject -t"
- alias msg="notify-send"
- alias shutdown="sudo shutdown -h now"
- alias snano="sudo nano"
- alias back="cd $OLDPWD"
- alias root="sudo su"
- alias ip="ifconfig"
- alias lynx="(lynx -accept_all_cookies)"
- alias hist='more ~/.bash_history | grep '
- # custom apt-get alias
- alias install="sudo apt-fast install"
- alias uninstall='sudo apt-fast remove'
- alias reinstall='sudo apt-fast --reinstall install'
- alias purge="sudo apt-fast remove --purge"
- alias clean="sudo apt-fast autoclean"
- alias update="sudo apt-fast update"
- alias upgrade="sudo apt-fast upgrade"
- alias autoremove="sudo apt-fast autoremove"
- alias addrepo='sudo add-apt-repository'
- alias search="sudo apt-cache search"
- alias searchIn="apt-file search"
- extract () {
- if [ -f $1 ] ; then
- case $1 in
- *.tar.bz2) tar xjf $1;;
- *.tar.gz) tar xzf $1;;
- *.bz2) bunzip2 $1;;
- *.rar) rar 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 extract()";;
- esac
- else
- echo "'$1' is not a valid file"
- fi
- }
- #netinfo - shows network information for your system
- function netinfo() {
- echo "--------------- Network Information ---------------"
- /sbin/ifconfig | awk /'inet addr/ {print $2}'
- /sbin/ifconfig | awk /'Bcast/ {print $3}'
- /sbin/ifconfig | awk /'inet addr/ {print $4}'
- /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
- myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
- echo "${myip}"
- echo "---------------------------------------------------"
- }
- # Check to see if a site is down for everyone or just me
- function downforme() {
- RED='\e[1;31m'
- GREEN='\e[1;32m'
- YELLOW='\e[1;33m'
- NC='\e[0m'
- if [ $# = 0 ]
- then
- echo -e "${YELLOW}usage:${NC} downforme website_url"
- else
- JUSTYOUARRAY=(`lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"`)
- if [ ${#JUSTYOUARRAY} != 0 ]
- then
- echo -e "${RED}It's just you. \n${NC}$1 is up."
- else
- echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here."
- fi
- fi
- }
- # cp with progress bar
- function cp_pro() {
- if [ `echo "$2" | grep ".*\/$"` ]
- then
- pv "$1" > "$2""$1"
- else
- pv "$1" > "$2"/"$1"
- fi
- }
- # mkdir and cd into it
- function mkdir_go() {
- mkdir $1 && cd $1
- }
- #bu - Back Up a file. Usage "bu filename.txt"
- function bu() {
- cp $1 ${1}-`date +%Y%m%d%H%M`.backup;
- }
- ##################################################
- # Fancy PWD display function
- ##################################################
- # The home directory (HOME) is replaced with a ~
- # The last pwdmaxlen characters of the PWD are displayed
- # Leading partial directory names are striped off
- # /home/me/stuff -> ~/stuff if USER=me
- # /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
- ##################################################
- parse_pwd() {
- # How many characters of the $PWD should be kept
- local pwdmaxlen=25
- # Indicate that there has been dir truncation
- local trunc_symbol=".."
- local dir=${PWD##*/}
- pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
- NEW_PWD=${PWD/#$HOME/\~}
- local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
- if [ ${pwdoffset} -gt "0" ]
- then
- NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
- NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
- fi
- }
- function load_out() {
- echo -n "$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g")"
- }
- function load_color() {
- gray=0
- red=1
- green=2
- yellow=3
- blue=4
- magenta=5
- cyan=6
- white=7
- # Colour progression is important ...
- # bold gray -> bold green -> bold yellow -> bold red ->
- # black on red -> bold white on red
- #
- # Then we have to choose the values at which the colours switch, with
- # anything past yellow being pretty important.
- tmp=$(echo $(load_out)*100 | bc)
- let load100=${tmp%.*}
- if [ ${load100} -lt 70 ]
- then
- tput bold ; tput setaf ${gray}
- elif [ ${load100} -ge 70 ] && [ ${load100} -lt 120 ]
- then
- tput bold ; tput setaf ${green}
- elif [ ${load100} -ge 120 ] && [ ${load100} -lt 200 ]
- then
- tput bold ; tput setaf ${yellow}
- elif [ ${load100} -ge 200 ] && [ ${load100} -lt 300 ]
- then
- tput bold ; tput setaf ${red}
- elif [ ${load100} -ge 300 ] && [ ${load100} -lt 500 ]
- then
- tput setaf ${gray} ; tput setab ${red}
- else
- tput bold ; tput setaf ${white} ; tput setab ${red}
- fi
- }
- bash_prompt() {
- case $TERM in
- xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
- local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
- #local TITLEBAR=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
- #local TITLEBAR=\[\ek\e\\\]\[\ek\W\e\\\]
- ;;
- screen)
- #local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
- #local TITLEBAR=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
- local TITLEBAR=\[\ek\e\\\]\[\ek\W\e\\\]
- ;;
- *)
- local TITLEBAR=""
- ;;
- esac
- local NONE="\[\033[0m\]" # unsets color to term's fg color
- # regular colors
- local K="\[\033[0;30m\]" # grey
- local R="\[\033[0;31m\]" # red
- local G="\[\033[0;32m\]" # green
- local Y="\[\033[0;33m\]" # yellow
- local B="\[\033[0;34m\]" # blue
- local M="\[\033[0;35m\]" # magenta
- local C="\[\033[0;36m\]" # cyan
- local W="\[\033[0;37m\]" # white
- # emphasized (bolded) colors
- local EMK="\[\033[1;30m\]"
- local EMR="\[\033[1;31m\]"
- local EMG="\[\033[1;32m\]"
- local EMY="\[\033[1;33m\]"
- local EMB="\[\033[1;34m\]"
- local EMM="\[\033[1;35m\]"
- local EMC="\[\033[1;36m\]"
- local EMW="\[\033[1;37m\]"
- # background colors
- local BGK="\[\033[40m\]"
- local BGR="\[\033[41m\]"
- local BGG="\[\033[42m\]"
- local BGY="\[\033[43m\]"
- local BGB="\[\033[44m\]"
- local BGM="\[\033[45m\]"
- local BGC="\[\033[46m\]"
- local BGW="\[\033[47m\]"
- local UC=$B # user's color
- [ $UID -eq "0" ] && UC=$R # root's color
- USER_INFO="${UC}\u${EMK}@${UC}\h"
- DATE="\$(date +'%-I:%M %p')"
- DATE_TOP_RIGHT='\[\033[s\]\[\033[1;\$((COLUMNS-4))f\]\$(date +%H:%M)\[\033[u\]'
- YAY_NAY="\$(if [[ \$? == 0 ]]; then echo \"${G}✓ \$?\"; else echo \"${R}✗ \$?\"; fi)"
- FREE_MEM="${R}"$((`sed -nu "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"${EMK}/${G}"$((`sed -nu "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024))MB""
- SYS_LOAD="\$(cut -c 1-14 /proc/loadavg)"
- FOLDER_INFO="\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -lah | grep -m 1 total | sed 's/total //')b"
- # ┌─┬─┐
- # ├─┼─┤
- # └─┴─┘
- # ▒ ° ±
- # My standard custom shell:
- # ┌─(uminded@uminded-Inspiron-1545)─(10:05 AM)
- # ├─(~\Downloads)─(12 files, 248Kb)
- # ├─(✓ 0)─(0.42 0.18 0.15)─(445/2467MB)
- # └─>
- export PS1="\n${EMK}┌─(${USER_INFO}${EMK})─(${B}\${NEW_PWD}${EMK})─(${B}${FOLDER_INFO}${EMK})\n"
- export PS1="$PS1${EMK}└─(${YAY_NAY}${EMK})─> ${NONE}"
- }
- PROMPT_COMMAND=parse_pwd
- bash_prompt
- unset bash_prompt
- # Handy Apps To Install:
- #most - color man pages
- export MANPAGER="/usr/bin/most -s"
- export ANTARES_INSTALL_DIR=~/.antares
- export PATH="$PATH:/home/uminded/stlink"
- export PATH="$PATH:/home/uminded/gcc-arm-none-eabi/bin"
- # added by Anaconda 2.0.1 installer
- export PATH="/home/uminded/anaconda/bin:$PATH"
- # load byobu-launcher with session choice and tmux on prompt load
- _byobu_sourced=1 . /usr/bin/byobu-launch
- export TERM=screen-256color
- alias tmux="tmux -2"
- # load solarized 256 dark color pallet for ls
- eval `dircolors ~/.dircolors.256dark`
- # Files needed to be installed for this .bashrc to work
- # sudo add-apt-repository ppa:apt-fast/stable
- # sudo apt-get update
- # sudo apt-get install apt-fast apt-file nano lynx more less tmux byobu
- # tmux install notes
- # solarizer: https://github.com/seebi/tmux-colors-solarized just copy 256 pallet to .tmux.conf
- # vi install notes
- # vim plugins and highlighters: https://github.com/amix/vimrc
- # shell notes
- # dircolors: https://github.com/seebi/dircolors-solarized
- # gnome-terminal notes
- # solerized pallet: https://github.com/Anthony25/gnome-terminal-colors-solarized
- # After select the background to be slightly darker than the tmux status bar.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement