Page 1 of 18 12311 ... LastLast
Results 1 to 10 of 173

Thread: Show us your .bashrc!

  1. #1
    Join Date
    Jul 2006
    Beans
    1,152

    Show us your .bashrc!

    I've only recently started playing with the ~/.bashrc file and want more ideas to play with. Please share your bashrc file and show all of us what cool and handy things you can do with bash.

    Here is my bashrc:

    Code:
    # ~/.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
    [ -z "$PS1" ] && return
    
    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups
    
    # 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)
        PS1='[${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\h\[\033[00m\]] \[\033[01;34m\]\w\[\033[00m\]\$ '
        ;;
    *)
        PS1='[${debian_chroot:+($debian_chroot)}\h] \w\$ '
        ;;
    esac
    
    # enable color support of ls and also add handy aliases
    if [ "$TERM" != "dumb" ]; then
        eval "`dircolors -b`"
        alias ls='ls --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
    
    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
    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 "---------------------------------------------------"
    }
    
    #dirsize - finds directory sizes and lists them for the current directory
    dirsize ()
    {
    du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
    egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
    egrep '^ *[0-9.]*M' /tmp/list
    egrep '^ *[0-9.]*G' /tmp/list
    rm -rf /tmp/list
    }
    
    #copy and go to dir
    cpg (){
      if [ -d "$2" ];then
        cp $1 $2 && cd $2
      else
        cp $1 $2
      fi
    }
    
    #move and go to dir
    mvg (){
      if [ -d "$2" ];then
        mv $1 $2 && cd $2
      else
        mv $1 $2
      fi
    }
    
    # Directory navigation aliases
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias .....='cd ../../../..'
    
    export OOO_FORCE_DESKTOP=gnome
    Last edited by urukrama; January 27th, 2008 at 05:03 PM.

  2. #2
    Join Date
    Dec 2005
    Location
    Kingston, Ontario
    Beans
    1,919
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Show us your .bashrc!

    That looks somewhat familiar.

    Code:
    ## LoKe's ~/.bashrc
    [ -z "$PS1" ] && return
    
    # Basic options
    export HISTCONTROL=ignoredups
    export COLORFGBG='default;default'
    
    shopt -s checkwinsize
    eval "$(dircolors -b /etc/dircolors)"
    
    # Aliases
    alias ls='ls -h --color=auto'
    alias ll='ls -l'
    alias la='ls -A'
    alias l='ls -CF'
    alias svim='sudo vim'
    alias h='cd'
    alias ..='cd ..'
    alias cd..='cd ..'
    alias ...='cd ../..'
    alias cim='vim'
    alias back='cd $OLDPWD'
    alias root='sudo su'
    alias runlevel='sudo /sbin/init'
    alias grep='grep --color=auto'
    alias dfh='df -h'
    alias gvim='gvim -geom 84x26'
    alias start='dbus-launch startx'
    
    # Prompt
    BGREEN='\[\033[1;32m\]'
    GREEN='\[\033[0;32m\]'
    BRED='\[\033[1;31m\]'
    RED='\[\033[0;31m\]'
    BBLUE='\[\033[1;34m\]'
    BLUE='\[\033[0;34m\]'
    NORMAL='\[\033[00m\]'
    PS1="${BLUE}(${RED}\w${BLUE}) ${NORMAL}\h ${RED}\$ ${NORMAL}"
    
    # Paths
    PATH=$PATH:${HOME}/bin:/usr/lib/wine/bin:/sbin:/usr/sbin
    export PATH=$PATH:/usr/local/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/wine/lib:/usr/local/lib
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    
    # X Terminal titles
    case "$TERM" in
    xterm*|rxvt*)
    	PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    	;;
    *)
    	;;
    esac
    
    # Functions
    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	;;
    			*)			echo "'$1' cannot be extracted via extract()" ;;
    		esac
    	else
    		echo "'$1' is not a valid file"
    	fi
    }
    ziprm () {
    	if [ -f $1 ] ; then
    		unzip $1
    		rm $1
    	else
    		echo "Need a valid zipfile"
    	fi
    }
    psgrep() {
    	if [ ! -z $1 ] ; then
    		echo "Grepping for processes matching $1..."
    		ps aux | grep $1 | grep -v grep
    	else
    		echo "!! Need name to grep for"
    	fi
    }
    grab() {
    	sudo chown -R ${USER} ${1:-.}
    }
    
    # Bash completion
    if [ -f /etc/bash_completion ]; then
    	. /etc/bash_completion
    fi
    
    # Locale and editor
    export EDITOR=nano
    export BROWSER="firefox '%s' &"
    +Solace @DeviantArt | Awesome Guide | Beginners Team Member
    Canadian Forces 2007-present

  3. #3
    Join Date
    May 2007
    Location
    3-Dimensional Spacetime
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Show us your .bashrc!

    What does the .bashrc file do actually? What's its function?

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Beans
    1,805

    Re: Show us your .bashrc!

    Quote Originally Posted by Ebuntor View Post
    What does the .bashrc file do actually? What's its function?
    It is a configuration file that is read every time that you open the terminal. As an example of its use, you can create an alias like
    Code:
    alias rm='rm -iv'
    Now, every time you use the command rm, bash will in reality execute rm -iv which means that you will be asked to confirm any removals. You will also get an output that tells you what has been done.
    Last edited by mali2297; January 27th, 2008 at 05:53 PM.

  5. #5
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,083
    Distro
    Ubuntu Studio 13.04 Raring Ringtail

    Re: Show us your .bashrc!

    Quote Originally Posted by Ebuntor View Post
    What does the .bashrc file do actually? What's its function?
    bash reads it as it starts (eg when you start a terminal). it lets you customise how the terminal works, and set up shortcuts

    i like these handy shortcuts
    Code:
    alias h="history|grep "
    alias f="find . |grep "
    alias p="ps aux |grep "
    alias o="gnome-open "
    first three let you search command line history, files in current directory and subdirs, and running processes. the 'o' lets you open a file in what ever it would use if you double clicked it.

    Code:
    alias pc='python -ic "from __future__ import division; from math import *"'
    opens python with settings that make it useful for quick calculations. (similar to bc, but i am used to python syntax. the future division but means that 1/2 = 0.5 instead of 0).

    Code:
    alias ps1_short="PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '"
    alias ps1_long="PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '"
    switches between shown the whole path in the prompt, and just the top bit. i like to see where i am, but sometimes it just gets too deep.

  6. #6
    Join Date
    Jul 2006
    Beans
    1,152

    Re: Show us your .bashrc!

    Quote Originally Posted by Ebuntor View Post
    What does the .bashrc file do actually? What's its function?
    It is the configuration file of bash. You can use the bashrc file to add functions or aliases to bash.

    For example, in my bashrc file the "extract" section allows me to extract any archived file from the command line with the command extract, for example "extract example.tar.gz". These aliases basically tell bash to run certain applications, in this example the tar command, with certain options as specified in the bashrc file, in this case xzf.

    Have a look at the bashrc files posted in this thread. Most of the aliases should make sense as they are.

    You can also use the bashrc file to change your terminal header (generally "username@computer-name ~$" in Ubuntu). See here for more on that.

    EDIT: Seems I was a bit slow...
    Last edited by urukrama; January 27th, 2008 at 06:03 PM.

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Beans
    1,805

    Re: Show us your .bashrc!

    ... here is my entire .bashrc:

    Code:
    # ~/.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
    [ -z "$PS1" ] && return
    
    # don't put duplicate lines in the history. See bash(1) for more options
    # export HISTCONTROL=ignoredups
    
    # 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 "$(lesspipe)"
    
    # the prompt information
    export PS1="[\w]\$ "
    
    # leave some commands out of history log
    export HISTIGNORE="&:??:[ ]*:clear:exit:logout"
    
    # default editor
    export EDITOR=jmacs
    
    # define color to additional file types
    export LS_COLORS=$LS_COLORS:"*.wmv=01;35":"*.wma=01;35":"*.flv=01;35":"*.m4a=01;35"
    
    
    # Alias definitions.
    
    # enable color support of ls and also add handy aliases
    if [ "$TERM" != "dumb" ]; then
        eval "`dircolors -b`"
        alias ls='ls --color=auto' 
        alias dir='ls --color=auto --format=vertical'
        alias vdir='ls --color=auto --format=long'
    fi
    
    # user-defined aliases
    alias rm='rm -vi'
    alias cp='cp -vi'
    alias mv='mv -vi'
    alias clean='rm -f "#"* "."*~ *~ *.bak *.dvi *.aux *.log'
    alias nano='nano -w'
    alias psi='ps h -eo pmem,comm | sort -nr | head'
    alias sucs='sudo jmacs'
    
    # 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

  8. #8
    Join Date
    May 2007
    Location
    3-Dimensional Spacetime
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Show us your .bashrc!

    Thanks to all of you for explaining. Sure sounds like a very handy config file.

  9. #9
    Join Date
    Jul 2006
    Beans
    1,152

    Re: Show us your .bashrc!

    Anyone else?

  10. #10
    Join Date
    Aug 2006
    Location
    Poland
    Beans
    Hidden!

    Re: Show us your .bashrc!



    /home/user/.bashrc http://pastebin.com/f628171ce
    /root/.bashrc http://pastebin.com/f5c1c0405 (in case you're using 'su' instead of 'sudo')
    Last edited by andrek; February 4th, 2008 at 07:16 PM.

Page 1 of 18 12311 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •