dotfiles:bashrc
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dotfiles:bashrc [2015/01/28 12:41] – link dircolors warnaud | dotfiles:bashrc [2020/12/17 05:23] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | My actual ~/.bashrc with: | ||
| + | * Alias | ||
| + | * Completions | ||
| + | * Functions | ||
| + | * Fun Prompt | ||
| + | You need: | ||
| + | * bash | ||
| + | * ccze | ||
| + | |||
| + | <code bash> | ||
| + | # | ||
| + | # ~/.bashrc | ||
| + | # | ||
| + | |||
| + | # If not running interactively, | ||
| + | [[ $- != *i* ]] && return | ||
| + | |||
| + | # include the global system file | ||
| + | if [ -f /etc/bashrc ]; then | ||
| + | . /etc/bashrc | ||
| + | fi | ||
| + | |||
| + | # Add some color schema | ||
| + | if [[ " | ||
| + | eval $(dircolors ~/ | ||
| + | elif [[ -f ~/ | ||
| + | eval $(dircolors ~/ | ||
| + | fi | ||
| + | |||
| + | # Add some nice folder in the path | ||
| + | PATH=$PATH: | ||
| + | export PATH | ||
| + | |||
| + | # Default editor | ||
| + | export EDITOR=vim | ||
| + | |||
| + | # Bash options | ||
| + | shopt -s checkwinsize # | ||
| + | shopt -s cdspell # autocorrects cd misspellings | ||
| + | shopt -s dotglob # include dotfiles in pathname expansion | ||
| + | shopt -s autocd # auto " | ||
| + | |||
| + | # don't put duplicate lines and same sucessive entries in the history. | ||
| + | export HISTCONTROL=ignoreboth | ||
| + | |||
| + | # Colorized less command | ||
| + | export LESS_TERMCAP_mb=$' | ||
| + | export LESS_TERMCAP_md=$' | ||
| + | export LESS_TERMCAP_me=$' | ||
| + | export LESS_TERMCAP_se=$' | ||
| + | export LESS_TERMCAP_so=$' | ||
| + | export LESS_TERMCAP_ue=$' | ||
| + | export LESS_TERMCAP_us=$' | ||
| + | |||
| + | |||
| + | # Overload actual commands | ||
| + | alias grep=' | ||
| + | alias dmesg=' | ||
| + | alias vi=' | ||
| + | alias ls='ls -G --color' | ||
| + | |||
| + | # New aliases | ||
| + | alias fifo=" | ||
| + | alias lc="ls -al | tr -s \" \" | cut -d\" \" -f3,4,9 | column -t" | ||
| + | alias ll="ls -altrh | tr -s \" \" | cut -d\" \" -f6, | ||
| + | alias learning=" | ||
| + | alias da=' | ||
| + | alias horloge=" | ||
| + | |||
| + | ## FileSystem Aliases ## | ||
| + | alias lsl=' | ||
| + | alias usage=' | ||
| + | alias dut=" | ||
| + | alias size=' | ||
| + | alias sizevar=' | ||
| + | alias sizehome=" | ||
| + | alias lsbig=" | ||
| + | alias listmod=" | ||
| + | alias listf=" | ||
| + | alias findit=" | ||
| + | alias upd60=" | ||
| + | alias rtupd60=" | ||
| + | |||
| + | ## Network Aliases | ||
| + | alias netlisten=' | ||
| + | alias nstat=" | ||
| + | alias nstato=" | ||
| + | alias ports=' | ||
| + | alias speeddown=" | ||
| + | alias speedup=" | ||
| + | alias speedrw=" | ||
| + | |||
| + | ## System Aliases ## | ||
| + | alias h=' | ||
| + | alias sourcebash=" | ||
| + | alias inxif=" | ||
| + | # Drives | ||
| + | alias uuid=" | ||
| + | alias drives=" | ||
| + | # Systemd | ||
| + | alias kernelmsg=" | ||
| + | alias bootmsg=" | ||
| + | alias systemdmsg=" | ||
| + | alias blame=" | ||
| + | alias boot=" | ||
| + | alias units=" | ||
| + | alias errors=" | ||
| + | # Ram | ||
| + | alias meminfo=' | ||
| + | alias psmem=' | ||
| + | # CPU | ||
| + | alias cpuinfo=' | ||
| + | alias pscpu=' | ||
| + | |||
| + | # Terminal Clock | ||
| + | alias tclock=" | ||
| + | |||
| + | ## Xrandr Aliases ## | ||
| + | # Switch Single head | ||
| + | alias singlehead=' | ||
| + | # Switch Dual head (screen left of) | ||
| + | alias dualleft=' | ||
| + | |||
| + | alias FvwmRestart=' | ||
| + | |||
| + | # User specific Aliases and functions | ||
| + | function remove_crap() { rm -r $@; } # Removes everything passed as argument recursively | ||
| + | function add_txt_ext() { mv $@ $@.txt; } # Add .txt extention to file passed as argument | ||
| + | # copy a file and change its filename to filename-timestamp | ||
| + | function fbackup() { cp -iv $1{, | ||
| + | # Remove offending key line $1 | ||
| + | function rmkeyssh() { sed -i " | ||
| + | |||
| + | ## DICTIONARY FUNCTIONS ## | ||
| + | dwordnet () { curl dict:// | ||
| + | dacron () { curl dict:// | ||
| + | djargon () { curl dict:// | ||
| + | dfoldoc () { curl dict:// | ||
| + | dthesaurus () { curl dict:// | ||
| + | |||
| + | ## Website Commands ## | ||
| + | cmdfu() { curl " | ||
| + | down4me() { curl -s " | ||
| + | |||
| + | # Swap 2 files around, if they exist (from Uzi's bashrc). | ||
| + | function swap() { | ||
| + | # Create temp file | ||
| + | local TMPFILE=tmp.$$ | ||
| + | # Check availability of files | ||
| + | [ $# -ne 2 ] && echo "swap: 2 arguments needed" | ||
| + | [ ! -e $1 ] && echo "swap: $1 does not exist" && return 1 | ||
| + | [ ! -e $2 ] && echo "swap: $2 does not exist" && return 1 | ||
| + | # Move it | ||
| + | mv " | ||
| + | mv " | ||
| + | mv $TMPFILE " | ||
| + | } | ||
| + | |||
| + | # Handy Extract Program | ||
| + | function extract() { | ||
| + | if [ -f " | ||
| + | case " | ||
| + | *.tar.bz2) | ||
| + | *.tar.gz) | ||
| + | *.bz2) | ||
| + | *.rar) | ||
| + | *.gz) gunzip " | ||
| + | *.tar) | ||
| + | *.tbz2) | ||
| + | *.tgz) | ||
| + | *.zip) | ||
| + | *.Z) | ||
| + | *.7z) 7z x " | ||
| + | *) echo "' | ||
| + | esac | ||
| + | else | ||
| + | echo "' | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | # Creates an archive (*.tar.gz) from given directory. | ||
| + | function maketar() { tar cvzf " | ||
| + | |||
| + | # Create a ZIP archive of a file or folder. | ||
| + | function makezip() { zip -r " | ||
| + | |||
| + | |||
| + | # Alias root to ssh as root directly | ||
| + | alias root=' | ||
| + | # tab completion for ssh hosts | ||
| + | SSH_COMPLETE=( $(cat ~/ | ||
| + | cut -f 1 -d ' ' | \ | ||
| + | sed -e s/,.*//g | \ | ||
| + | uniq | \ | ||
| + | egrep -v ^[0123456789]) ) | ||
| + | complete -o default -W " | ||
| + | complete -o default -W " | ||
| + | |||
| + | # Auto-complete bticket with the ticket numbers | ||
| + | TICKET_COMPLETE=( $(/ | ||
| + | complete -o default -W " | ||
| + | |||
| + | # auto completion for sudo whereis and man | ||
| + | complete -cf sudo | ||
| + | complete -cf whereis | ||
| + | complete -cf man | ||
| + | |||
| + | battery_status() { | ||
| + | |||
| + | BATTERY=/ | ||
| + | CHARGE=`cat $BATTERY/ | ||
| + | BATSTATE=`cat $BATTERY/ | ||
| + | |||
| + | # Colors for humans | ||
| + | NON=' | ||
| + | BLD=' | ||
| + | RED=' | ||
| + | GRN=' | ||
| + | YEL=' | ||
| + | |||
| + | COLOUR=" | ||
| + | |||
| + | case " | ||
| + | ' | ||
| + | | ||
| + | ;; | ||
| + | ' | ||
| + | | ||
| + | ;; | ||
| + | ' | ||
| + | | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # prevent a charge of more than 100% displaying | ||
| + | if [ " | ||
| + | then | ||
| + | CHARGE=100 | ||
| + | fi | ||
| + | |||
| + | # prevent an error if the battery is not in the laptop (e.g. you have two and take out the primary) | ||
| + | STATE=`cat $BATTERY/ | ||
| + | if [ " | ||
| + | then | ||
| + | echo -e " | ||
| + | exit | ||
| + | fi | ||
| + | |||
| + | if [ " | ||
| + | then | ||
| + | COLOUR=" | ||
| + | fi | ||
| + | |||
| + | if [ " | ||
| + | then | ||
| + | COLOUR=" | ||
| + | fi | ||
| + | echo -e " | ||
| + | } | ||
| + | |||
| + | ################################################## | ||
| + | # 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 | ||
| + | # / | ||
| + | # / | ||
| + | ################################################## | ||
| + | bash_prompt_command() { | ||
| + | # How many characters of the $PWD should be kept | ||
| + | local pwdmaxlen=35 | ||
| + | # Indicate that there has been dir truncation | ||
| + | local trunc_symbol=" | ||
| + | local dir=${PWD## | ||
| + | pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen )) | ||
| + | NEW_PWD=${PWD/# | ||
| + | local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen )) | ||
| + | if [ ${pwdoffset} -gt " | ||
| + | then | ||
| + | NEW_PWD=${NEW_PWD: | ||
| + | NEW_PWD=${trunc_symbol}/ | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | function draw_line(){ | ||
| + | # Function that creates a line terminal wide | ||
| + | |||
| + | # Seprataor | ||
| + | #local DOTS=" | ||
| + | |||
| + | for (( c=1; c< | ||
| + | do | ||
| + | DOTS=$(echo -n $DOTS" | ||
| + | done | ||
| + | } | ||
| + | |||
| + | function load_out() { | ||
| + | echo -n " | ||
| + | } | ||
| + | |||
| + | function load_color() { | ||
| + | # 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. | ||
| + | # Colors are defined in the load function / blinking for load > 2 | ||
| + | |||
| + | tmp=$(echo $(load_out)*100 | bc) | ||
| + | let load100=${tmp%.*} | ||
| + | |||
| + | if [ ${load100} -lt 70 ] | ||
| + | then | ||
| + | printf " | ||
| + | elif [ ${load100} -ge 70 ] && [ ${load100} -lt 120 ] | ||
| + | then | ||
| + | printf " | ||
| + | elif [ ${load100} -ge 120 ] && [ ${load100} -lt 200 ] | ||
| + | then | ||
| + | printf " | ||
| + | elif [ ${load100} -ge 200 ] && [ ${load100} -lt 300 ] | ||
| + | then | ||
| + | printf " | ||
| + | elif [ ${load100} -ge 300 ] && [ ${load100} -lt 500 ] | ||
| + | then | ||
| + | printf " | ||
| + | else | ||
| + | printf " | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | function load { | ||
| + | |||
| + | case $TERM in | ||
| + | | ||
| + | local TITLEBAR=' | ||
| + | ;; | ||
| + | | ||
| + | local TITLEBAR="" | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | local NONE=" | ||
| + | local BLINK=" | ||
| + | |||
| + | # regular colors | ||
| + | local K=" | ||
| + | local R=" | ||
| + | local G=" | ||
| + | local Y=" | ||
| + | local B=" | ||
| + | local M=" | ||
| + | local C=" | ||
| + | local W=" | ||
| + | |||
| + | # empahsized (bolded) colors | ||
| + | local EMK=" | ||
| + | local EMR=" | ||
| + | local EMG=" | ||
| + | local EMY=" | ||
| + | local EMB=" | ||
| + | local EMM=" | ||
| + | local EMC=" | ||
| + | local EMW=" | ||
| + | |||
| + | # background colors | ||
| + | local BGK=" | ||
| + | local BGR=" | ||
| + | local BGG=" | ||
| + | local BGY=" | ||
| + | local BGB=" | ||
| + | local BGM=" | ||
| + | local BGC=" | ||
| + | local BGW=" | ||
| + | |||
| + | local UC=$W # user's color | ||
| + | [ $UID -eq " | ||
| + | |||
| + | # PS1="# | ||
| + | # PS1=" | ||
| + | # ∴ \# ∴ ${EMG}\D{%H: | ||
| + | # | ||
| + | |||
| + | PS1=" | ||
| + | |||
| + | unset DOTS | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | PROMPT_COMMAND=" | ||
| + | </ | ||
| + | |||
| + | The prompt will looks like: | ||
| + | <code bash> | ||
| + | ┌╼ ✓ ∴ 66 ∴ 12:01:09 ∴ 99% ∴ warnaud@Yoru:/ | ||
| + | └──╼ 0.48 →>></ | ||
| + | |||
| + | You need the [[dotfiles: | ||
