The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Your .bashrc file

    Discussion in 'Linux Compatibility and Software' started by Enunes, Jul 12, 2009.

  1. Enunes

    Enunes Notebook Consultant

    Reputations:
    156
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    30
    Hey,

    based on this reply from archer7 some topics ago, I thought it would be cool to share some .bashrc tips around! :D
    As Bash is our always-there friend and we usually spend some good time on it, I think it is natural to tweak it a bit to have our personality.

    For ones that might not have messed with it so far, .bashrc is a textfile generally located at your home directory which is run when you start a bash terminal.
    And that is awesome, you can do great things with it.
    For instance, you can set your PS1 variable there. The PS1 variable is the one responsible for setting the appearance of the command line's "line". Mine, for example, which is pretty standard, is:
    Code:
    [erico@hp ~]$ 
    As archer7 pointed, you can put things there like only show the name of current directory instead of whole path to it, show the time/date... make it colored and these stuff.
    This is a cool topic from Arch wiki which points some tips about customizing it. (The title talks about colors, but in fact it points tips in general and lists some options.) (This is Arch wiki but this will work on whatever distro.)

    I also think this file is a good file to get started on dealing with Linux's file based customizing (skill which I'd call essential in Arch at least). It is simple, there are plenty tutorials around and you can see some visual results with it, at the same time you aren't breaking anything if you do something wrong.
    There are many 'post your .bashrc' topics on forums around, just googleing something like 'bashrc tips' or 'your bashrc' gives some results.

    So, here's mine:

    Code:
    # Check for an interactive session
    [ -z "$PS1" ] && return
    
    if [ -f /etc/bash_completion ]; then
    	. /etc/bash_completion
    fi
    
    alias ls='ls --color=auto'
    alias sl='ls'
    alias ll='ls -la'
    alias :q='exit'
    alias :Q='exit'
    alias :e='vim'
    alias :s='locate'
    alias exir='exit'
    alias exti='exit'
    alias xeit='exit'
    alias xeti='exit'
    alias exi='exit'
    
    fortune
    printf "\n"
    PS1='[\u@\h \w]\$ '
    
    Which is pretty simple, but does the job to me so far. I like the simple. The two first structures were pasted from somewhere...

    As you can see, I do alot of typos and I don't like to read something like "exti: command not found". Also there are some vim aliases there for when I am somewhat sleepy coding and I don't want to spend time thinking whether i'm inside vim or outside it.

    Oh, and in case you haven't used it, fortune is a program which prints a random quote everytime you run it. I put it there, so everytime I run a bash, I'm pleased with a random quote! :D
    I even installed the fortune chuck norris mod from Arch's aur, so sometimes I get a random chuck norris fact there. :p

    And finally, my PS1 is the Arch's standard, except I prefer to see the whole path of where I am instead of just the folder name (/w instead of /W), so it saves me some pwd.

    [​IMG]

    So, got any tips to share?
     
  2. archer7

    archer7 Notebook Evangelist

    Reputations:
    289
    Messages:
    647
    Likes Received:
    0
    Trophy Points:
    30
    It looks like you and I are alone, Enunes. :D I'm using fortune-mod in my .bashrc as well, after seeing this post, but I use it with the "archlinux" plugin. I also have a pair of new (and very useful aliases):
    Code:
    alias df='df -hT' ##filesystem usage
    alias dudir='du -hs' ##get the size of a directory
    [​IMG]
     
  3. theZoid

    theZoid Notebook Savant

    Reputations:
    1,338
    Messages:
    5,202
    Likes Received:
    22
    Trophy Points:
    206
    Code:
    alias dammit=iceweasel "http://www.distrowatch.com"
    :D :D :D
     
  4. D-EJ915

    D-EJ915 Notebook Consultant

    Reputations:
    123
    Messages:
    161
    Likes Received:
    0
    Trophy Points:
    30
    I've got a fairly fancy PS1 I picked up somewhere but I can't recall exactly...otherwise it's the stock (k)ubuntu one.

    anyway it's this:
    Code:
    PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\]"
    
    pic

    Depending on how many files there are in a directory it might take a while to CD into it.
     
  5. archer7

    archer7 Notebook Evangelist

    Reputations:
    289
    Messages:
    647
    Likes Received:
    0
    Trophy Points:
    30
    Oh... wow... my horizons have been broadened.
     
  6. Enunes

    Enunes Notebook Consultant

    Reputations:
    156
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    30
    Yeah.. now that's pretty different.

    Just in case, anyone which wants to 'try' it without breaking anything, you can paste that PS1 code in your terminal and check how that PS1 looks like. In case ctrlC/ctrlV doesnt work, you can try right click+copy/paste. Just executing "PS1=" something will change your PS1 and it will be reseted once you restart your terminal ;) (you can try PS1=adjfaodjf to check what i mean).

    I shall look after a new one for me now, my standard stock one seems sooo funless now.