post your .bashrc profiles!

Discussion in 'all things UNIX' started by x942, Nov 7, 2011.

Thread Status:
Not open for further replies.
  1. x942

    x942 Guest

    I have been doing alot of tinkering with bashrc so I thought we should share what we have!

    Code:
    # .bashrc
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
    	. /etc/bashrc
    fi
    
    # User specific aliases and functions
    # ~/.bashrc: executed by bash(1) for non-login shells.
    # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    # for examples
    
    # Pager
    export PAGER=most
    
    # If not running interactively, don't do anything
    [ -z "$PS1" ] && return
    
    # don't put duplicate lines in the history. See bash(1) for more options
    # don't overwrite GNU Midnight Commander's setting of `ignorespace'.
    HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
    # ... or force ignoredups and ignorespace
    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 variable identifying the chroot you work in (used in the prompt below)
    if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)
    fi
    
    # set a fancy prompt (non-color, unless we know we "want" color)
    case "$TERM" in
        xterm-color) 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
    
    if [ "$color_prompt" = yes ]; then
        PS1='\[\033[1;34m\]┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ \[\033[0;34m\]'
    else
        PS1='┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ '
    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;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
        ;;
    *)
        ;;
    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
        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 more ls aliases
    #alias ll='ls -l'
    #alias la='ls -A'
    #alias l='ls -CF'
    # 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 ] && ! shopt -oq posix; then
        . /etc/bash_completion
    fi
    
    
    #------------------------------------------////
    # Colors:
    #------------------------------------------////
    black='\e[0;30m'
    blue='\e[0;34m'
    green='\e[0;32m'
    cyan='\e[0;36m'
    red='\e[0;31m'
    purple='\e[0;35m'
    brown='\e[0;33m'
    lightgray='\e[0;37m'
    darkgray='\e[1;30m'
    lightblue='\e[1;34m'
    lightgreen='\e[1;32m'
    lightcyan='\e[1;36m'
    lightred='\e[1;31m'
    lightpurple='\e[1;35m'
    yellow='\e[1;33m'
    white='\e[1;37m'
    nc='\e[0m'
    
    #------------------------------------------////
    # Colors:
    #------------------------------------------////
    black='\e[0;30m'
    blue='\e[0;34m'
    green='\e[0;32m'
    cyan='\e[0;36m'
    red='\e[0;31m'
    purple='\e[0;35m'
    brown='\e[0;33m'
    lightgray='\e[0;37m'
    darkgray='\e[1;30m'
    lightblue='\e[1;34m'
    lightgreen='\e[1;32m'
    lightcyan='\e[1;36m'
    lightred='\e[1;31m'
    lightpurple='\e[1;35m'
    yellow='\e[1;33m'
    white='\e[1;37m'
    nc='\e[0m'
    
    #------------------------------------------////
    # Aliases:
    #------------------------------------------////
    ## make ls list by size
    ##alias ls='du -s */* | sort -n'
    alias findbig='find . -type f -exec ls -s {} \; | sort -n -r | head -5'
    alias music='vlc'
    alias ports='netstat -nape --inet'
    alias ping='ping -c 4'
    #alias ns='netstat -alnp --protocol=inet'
    #alias update='sudo'
    #alias refresh='sudo pacman -Syy'
    alias ls='ls --color=always'
    alias la='ls -Al'
    alias lx='ls -lXB'
    alias lk='ls -lSr'
    alias lc='ls -lcr'
    alias lu='ls -lur'
    alias lr='ls -lR'
    alias lt='ls -ltr'
    alias lm='ls -al |more'
    alias lr='ls -R' # using ls recursively - Handy with grep
    alias reload='source ~/.bashrc'
    alias bashmod='nano ~/.bashrc'
    alias secscan='sudo rkhunter -c'
    alias update='sudo yum update'
    alias byebye='sudo poweroff'
    alias chrome='/opt/google/chrome/chrome'
    alias download='sudo yum install'
    #------------------------------------------////
    # Functions and Scripts:
    #------------------------------------------////
    localnet ()
    {
    /sbin/ifconfig | awk /'inet addr/ {print $2}'
    echo ""
    /sbin/ifconfig | awk /'Bcast/ {print $3}'
    echo ""
    }
    upinfo ()
    {
    echo -ne "${green}$HOSTNAME ${red}uptime is ${cyan} \t ";uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}'
    }
    cd()
    {
      if [ -n "$1" ]; then
        builtin cd "$@" && ls
      else
        builtin cd ~ && ls
      fi
    }
    encrypt ()
    {
    gpg -ac --no-options "$1"
    }
    
    decrypt ()
    {
    gpg --no-options "$1"
    }
    
    extract()
    {
    if [ -f "$1" ] ; then
    case "$1" in
    *.tar.bz2) tar xjf "$1" ;;
    *.tar.gz) tar xzf "$1" ;;
    *.tar.Z) tar xzf "$1" ;;
    *.bz2) bunzip2 "$1" ;;
    *.rar) unrar x "$1" ;;
    *.gz) gunzip "$1" ;;
    *.jar) unzip "$1" ;;
    *.tar) tar xf "$1" ;;
    *.tbz2) tar xjf "$1" ;;
    *.tgz) tar xzf "$1" ;;
    *.zip) unzip "$1" ;;
    *.Z) uncompress "$1" ;;
    *) echo "'$1' cannot be extracted." ;;
    esac
    else
    echo "'$1' is not a file."
    fi
    }
    
    #------------------------------------------////
    # Prompt:
    #------------------------------------------////
    
    PS1='\[\033[01;32m\]\u\[\033[01;34m\]@\[\033[01;31m\]\h\[\033[00;34m\]{\[\033[01;34m\]\w\[\033[00;34m\]}\[\033[01;32m\]:\[\033[00m\]'
    
    #------------------------------------------////
    # System Information:
    #------------------------------------------////
    clear
    echo -e "${purple}Welcome To X942's System"
    echo -e  "${purple}Authorized Users Only"
    echo -e  "${purple}Unauthorized is strictly prohibited and will be prosecuted to the fullest"
    echo -e  "${purple}Extent of the law."
    echo -e  "${red}Fedora 15";
    echo ""
    echo -ne "${red}Today is:\t\t${cyan}" `date`; echo ""
    echo -e "${red}Kernel Information: \t${cyan}" `uname -smr`
    echo -ne "${cyan}";upinfo;echo ""
    echo -e "${lightgray}"; cal -1
    
    Parts were taken from another poster elsewhere.

    I love aliases so much easier! :thumb:
     
  2. tlu

    tlu Guest

    I haven't modified the standard Ubuntu .bashrc but I'm using the following .bash_aliases file:

    Code:
    alias u="sudo apt-get update ; sudo apt-get upgrade"
    alias U="sudo apt-get update ; sudo apt-get dist-upgrade"
    alias i="sudo apt-get install"
    alias r="sudo apt-get remove"
    alias s="wajig search"
    alias S="wajig show"
    alias up="sudo apt-get dist-upgrade"
    alias ar="sudo apt-get autoremove"
    alias cleanup="wajig autoremove ; wajig auto-clean ; wajig purge-orphans"
     
  3. x942

    x942 Guest

    Aliases make life so much easier. I have one (bashmod) that lets me modify .bashrc quickly :D

    Also what is "wajig"? Never heard of it before.
     
  4. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,710
    Location:
    George, S.Africa
    Like tlu I aslo 'rediscovered' wajig. Check it out here
    and
    the commands list
     
  5. tlu

    tlu Guest

    Another idea is adding

    to .bashrc - see this site. The command offers the following options (you have to loggoff and logon again first):

    apt-history install | remove | upgrade | rollback

    Example output:

     
  6. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,710
    Location:
    George, S.Africa
    Nice ! (mack_guy will be pleased with the rollback feature). Oops, I misunderstood the rollback function - not like that in yum history at all.
    Did you compile from the tar.bz2 or did you install the 32 bit deb on your
    64 bit system ? I suppose you may have had 32 bit libraries installed like I have, and simply installed the deb ?

    > Wieder mal ein Knüller von tlu ! :D <
     
    Last edited: Dec 4, 2011
  7. tlu

    tlu Guest

    Neither :D Adding that function to .bashrc is sufficient.

    Thanks - but I didn't invent it, just found it somewhere ;)
     
  8. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,710
    Location:
    George, S.Africa
    There may be something to be concerned about. The dpkg.log files - the older
    ones - are gzipped. So I don't think rollback/install/upgrade/remove will work when a gzip needs to be accessed.
    In this regard I have found a script which purports to fix this.

    Code:
    #!/bin/bash
    
    ### Author:      Benjamin York
    ### Date:        2011-01-08
    ###
    ### Based On:
    ### http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
    ###
    ### Hosted At:
    ### https://github.com/blyork/apt-history
    ### 
    ### Git Repository:
    ### git://github.com/blyork/apt-history.git
    ###
    ### Description:
    ### Parses dpkg log files to get package installation, removal, and rollback
    ### information.
    ###
    ### Ubuntu Server likes to split up the dpkg.log file and then compress the
    ### various pieces. After seeing LinuxCommando's function, I added functionality
    ### to pull the pieces back together. I also slightly adjusted the output to
    ### avoid false positives.
    
    function echoHistory(){
        if [[ $1 == *.gz ]] ; then
            gzip -cd $1
        else
            if [[ $1 == *.log || $1 == *.log.1 ]] ; then
                cat $1
            else
                echo "\*\*\* Invalid File: ${1} \*\*\*" 1>&2
            fi
        fi
    }
    
    FILES=( `ls -rt /var/log/dpkg.log*` ) || exit 1
    
    for file in "${FILES[@]}"
    do
        case "$1" in
            install)
                echoHistory $file | grep " install "
            ;;
    
            upgrade|remove)
                echoHistory $file | grep " ${1} "
            ;;
                      
            rollback)
                echoHistory $file | grep upgrade | \
                    grep "$2" -A10000000 | \
                    grep "$3" -B10000000 | \
                    awk '{print $4"="$5}'
            ;;
    
            list)
                echoHistory $file
            ;;
    
            *)
                echo "Parameters:"
                echo "     install  - Lists all packages that have been installed."
                echo "     upgrade  - Lists all packages that have been upgraded."
                echo "     remove   - Lists all packages that have been removed."
                echo "     rollback - Lists rollback information."
                echo "     list     - Lists all contents of dpkg logs."
                break
            ;;
        esac
    done
    
    exit 0
    
    BTW, tlu, you did use sudo didn't you ?
     
    Last edited: Dec 4, 2011
  9. vasa1

    vasa1 Registered Member

    Joined:
    May 1, 2010
    Posts:
    4,238
    Do we run that as admin?
     
  10. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,710
    Location:
    George, S.Africa
    su -i is the one to use there vasa1 ... :D really deep root access. :blink:
     
  11. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,710
    Location:
    George, S.Africa
    Here is another to extract archives. (I see x942 has similar function script)

    Code:
    ##################################################
    # 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
    }
    
    
    
    
    Example on a 7zip..

    severin@severin-desktop:~/Desktop$ extract new.7z

    7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
    p7zip Version 9.20 (locale=en_ZA.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

    Processing archive: new.7z

    Extracting BitDefender Command Line Options
    Extracting BitDefender Install Instructions
    Extracting Bitdefender email script.mht

    Everything is Ok

    Files: 3
    Size: 145747
    Compressed: 70131


    And renaming the previously extracted files.

    severin@severin-desktop:~/Desktop$ extract new.7z

    7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
    p7zip Version 9.20 (locale=en_ZA.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

    Processing archive: new.7z

    file BitDefender Command Line Options
    already exists. Overwrite with
    BitDefender Command Line Options?
    (Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? u
    Extracting BitDefender Command Line Options
    Extracting BitDefender Install Instructions
    Extracting Bitdefender email script.mht

    Everything is Ok

    Files: 3
    Size: 145747
    Compressed: 70131
    severin@severin-desktop:~/Desktop$
     
    Last edited: Dec 4, 2011
  12. tlu

    tlu Guest

    Not necessary.
     
  13. tlu

    tlu Guest

    Thanks, Ocky - yes, that's actually a better one.:thumb:
     
  14. iceni60

    iceni60 ( ^o^)

    Joined:
    Jun 29, 2004
    Posts:
    5,116
    there are some nice things in this bashrc if you care to go through it
    http://gnome-look.org/content/show.php/Ultimate%20Bashrc%20File?content=129746

    right now there seems to be a database error, but i'm sure it will get worked out soon. here's the cached paged
    http://webcache.googleusercontent.com/search?q=cache:wrhaTd-JUuEJ:gnome-look.org/content/show.php%3Fcontent%3D129746+&cd=1&hl=en&ct=clnk&gl=uk&client=ubuntu

    i looked through it and found it has some stuff i made in the Network/Internet -oriented stuff section :cool: (not sure if that's a good thing, or not lol)


    i had the file already downloaded and uploaded it to one of those multiupload sites until it can be downloaded from gnome-look again :)

    $ md5sum bashrc.tar.gz
    e50af765bb3e41470de6c15559c4fab5 bashrc.tar.gz

    http://www.zshare.net/download/97063735619438f5/
    https://rapidshare.com/#!download|52l34|1462077921|bashrc.tar.gz|148|R~B46FEB2669BC115D074416697B3D7A6D|0|0
    http://hotfile.com/dl/136911702/b010e30/bashrc.tar.gz.html
    http://www.mediafire.com/?8ff66pi82dp7mub#1
    http://turbobit.net/download/free/kx73o85jh0xm
     
  15. raspb3rry

    raspb3rry Registered Member

    Joined:
    Jun 8, 2010
    Posts:
    37
    Code:
    # Check for an interactive session
    [ -z "$PS1" ] && return
    
    # Start tmux if it is not running already
    [[ $TERM != "screen-256color" ]] && tmux attach #&& exit
    
    # FRIGGIN' COLOURS!
    if [[ ${EUID} == 0 ]] ; # We are root 
     then
        PS1='\[\e[1;31m\]\u\[\e[m\]:\[\e[0;34m\]\w\[\e[m\] \[\e[0;31m\]\$ \[\e[m\]\[\e[0;32m\]'
     else
        PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[0;34m\]\w\[\e[m\] \[\e[0;32m\]\$\[\e[m\] \[\e[0;37m\]'
    fi
    
    # Autocomplete sudo
    complete -sf sudo
    
    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize
    
    # Include the following files:
    
    # Exports
    if [ -f /home/raspb3rry/.bash_exports ]; then
        source /home/raspb3rry/.bash_exports
    fi
    
    # Aliases
    if [ -f /home/raspb3rry/.bash_aliases ]; then
        source /home/raspb3rry/.bash_aliases
    fi
    
    # Functions
    if [ -f /home/raspb3rry/.bash_functions ]; then
        source /home/raspb3rry/.bash_functions
    fi
    
    # Advanced bash-completion (requires the package "bash-completion")
    if [ -f /etc/bash_completion ]; then
        source /etc/bash_completion
    fi
    
    if [ -f /home/raspb3rry/.bash_colours ]; then
        source /home/raspb3rry/.bash_colours
    fi
    
    Got tired of having an insanely huge .bashrc, so I decided to split it up.

    I'm running tmux inside all my terminals.

    Another great thing to try is to set PS1 to
    Code:
    PS1="C:\$( pwd | sed -e 's:/:\\\\\:g' -e 's:\\\\\*\$:\\\\\:g' )> "
     
Loading...
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.