Page 13 of 18 FirstFirst ... 31112131415 ... LastLast
Results 121 to 130 of 173

Thread: Show us your .bashrc!

  1. #121
    Join Date
    Aug 2007
    Location
    Cluj/Kolozsvár, Romania
    Beans
    189

    Re: Show us your .bashrc!

    Quote Originally Posted by BryanFRitt View Post
    [...] What did that line do? Was it just a check to see if the file ended in .iso, or did it do anything else?
    short answer: it should check whether '$1' is a readable with its file name ending in '.iso' (or .ISO, .Iso, etc.)


    elif [ -r "$1" ] && [ ! -z `echo "$1" | grep -i .iso$` ]; then

    "elif" and "; then": part of the if-then-else logic
    "[ -r $1 ]": true if '$1' is a readable file; just to avoid passing mistyped words
    "`echo "$1" | grep -i .iso$`": true if the file name has '.iso' at the end ($), case-insensitively (grep -i); to avoid passing anything but iso files
    "[ ! -z `TEST` ]": true if the string returned by `TEST` is non-zero (that will mean that grep found the file name to be ending with '.iso')

    i suspect the problem to have been caused by the latter part - with the string returned by grep, '[ ! -z File Name With Spaces.iso ]' will error out
    this can probably be circumvented by enclosing the `TEST` part within double quotes

    then again, this whole part might not be necessary at all, i just like doing tests to make sure my scripts return somewhat informative error messages

  2. #122
    Join Date
    Aug 2007
    Location
    Cluj/Kolozsvár, Romania
    Beans
    189

    Re: Show us your .bashrc!

    Quote Originally Posted by adamlau View Post
    Code:
    PS1='\[\e[0;00m\]\u\[\e[m\] \[\e[0;00m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[0;00m\] '
    expanding on this and another version that gives a different color if you're root, i have

    Code:
    # set prompt
    if [ "$SSH_CONNECTION" ]; then # grey ssh connection
      PS1='\[\033[01;30m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
    elif [ $(id -u) -eq 0 ]; then # red root
      PS1='\[\033[01;31m\]\u\[\033[00m\]:\[\033[01;35m\]\W\[\033[00m\]\$ '
    else # green regular user
      PS1='\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
    fi
    $SSH_CONNECTION will only be set if bash is running in an ssh client, so its value can be used to detect an ssh session
    the root part will only work if we're using the root account with sudo (e.g. 'sudo -s' or 'sudo bash'); using su will lead to /root/.bashrc being sourced instead of the current ~/.bashrc

    i didn't yet figure out how to test for the case when i'm both logged in through ssh and using the root account, so that i can have a red \u@\h:\W for the prompt, instead of the plain \u:\W
    any ideas anyone?
    Last edited by kaiju; February 28th, 2009 at 08:35 PM. Reason: if [ "$VAR" ] seems to do the same as if [ ! -z "$VAR" ], at least logically it should + simple is sexy :)

  3. #123
    Join Date
    Jun 2006
    Beans
    140
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Show us your .bashrc!

    Thanks kaiju
    That fixed it!
    and now I also modified the code to accept a mountpoint that has spaces in them.
    Code:
    miso() # mount iso file
    {
    _mountpoint="/Drives/Mounted_iso/Default"
    if [ -z "$1" ]; then
      echo "usage:"
      echo "  miso file.iso to   mount FILE.iso at   '$_mountpoint'"
      echo "  miso -u       to unmount FILE.iso from '$_mountpoint'"
      echo "  Where FILE.iso is the name, or path and name, of the iso file to mount"
    elif [ "$1" = "-u" ]; then
      sudo umount "$_mountpoint"
      echo "'$_mountpoint' unmounted."
    # if you don't want to verify if the file name ends in a .iso 
    # (case insensitive, -i) remove
    # && [ ! -z "`echo "$1" | grep -i .iso$`" ]
    elif [ -r "$1" ] && [ ! -z "`echo "$1" | grep -i .iso$`" ]; then
      if [ `ls "$_mountpoint" | wc -w` -ne 0 ]; then
        echo -e "error: '$_mountpoint' is not empty, \ntry miso -u to unmount it"
      else
        sudo mount -o loop "$1" "$_mountpoint" 
        echo -e "'$1'\n  is mounted at\n'$_mountpoint'"
      fi
    else
      echo "error: '$1' is not a readable *.iso file."
    fi
    }
    Last edited by BryanFRitt; March 2nd, 2009 at 10:43 AM. Reason: formated the code so that the scroll bar doesn't show up (at least on the browser that I'm using, Firefox 3.06)

  4. #124
    Join Date
    Aug 2007
    Location
    Cluj/Kolozsvár, Romania
    Beans
    189

    Re: Show us your .bashrc!

    a way to quickly list, view, edit and source a ~/.bash_functions file
    of course it will only work with an editor that will take +N FILENAME to mean that we want to open FILENAME at line N (nano and vim work fine)
    Code:
    func(){ #view and edit ~/.bash_functions
    if [ "$1" = "ed" ]; then
      _LINEN=`grep -n ^${2}.*\(\)\{\ \# ~/.bash_functions | head -n 1 | sed 's/:.*//'`
      $EDITOR +${_LINEN} ~/.bash_functions
      source ~/.bash_functions && echo "info: ~/.bash_functions sourced"
    elif [ "$1" = "ls" ]; then
      less ~/.bash_functions
    else
      grep \(\)\{\ \# ~/.bash_functions | sed -e 's/(){//' -e 's/ #/ - /' | sort
    fi
    unset -v _LINEN
    }
    as you can see from the grep line, the pattern searching part is tuned to the format of the first line - that line is used to find out where a given function starts (for jumping to the first function that matches $2 when editing) and also to provide a quick description (for when we're just listing the functions contained in the file)

  5. #125
    Join Date
    Nov 2006
    Beans
    72

    Re: Show us your .bashrc!

    ~/.bashrc
    Code:
    alias ls='ls --color=auto'
    PROMPT_COMMAND="source /etc/profile.d/color-prompt.inc"
    /etc/profile.d/color-prompt.inc
    Code:
    ## -*-shell-script-*-
    
    ## FILE /etc/profile.d/color-prompt.inc
    #
    # implement a function that will randomly colorize
    # individual characters in a bash prompt
    #
    
    ## COPYING
    #
    # color-prompt is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or (at your
    # option) any later version.
    #
    # color-prompt is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
    # more details.
    #
    # You should have received a copy of the GNU General Public License along with
    # color-prompt.  If not, see <http://www.gnu.org/licenses/>.
    #
    ## END COPYING
    
    ## INCLUDED FILES
    #
    
    #
    ## END INCLUDED FILES
    
    ## MAIN color-prompt
    #
    # randomly colorize individual characters in a bash prompt
    #
    
    #printf "debug: entering color_prompt.inc\n"
    
    index=$(( ${#USER} - 1 ))
    colorized_name=""
    brightness=
    hue=
    last_hue=
    dir=
    i="0"
    
    while test "$i" -le "$index"; do
    
    	brightness=$RANDOM
    	let "brightness %= 2"
    
    	hue="0"
    
    	# shuffle colours..don't repeat and don't pick black
    	while test "$hue" -eq "0" || \
    	      test "$hue" = "$last_hue"; do
    		hue=$RANDOM
    		let "hue %= 8"
    	done
    
    	this_color="\[\e[${brightness};3${hue}m\]"
    
    	last_hue="$hue"
    
    	if test -z "$colorized_name"; then
    		colorized_name="${this_color}${USER:${i}:1}"
    	else
    		colorized_name="${colorized_name}${this_color}${USER:${i}:1}"
    	fi
    
    	i="$(( $i + 1 ))"
    
    done
    
    tput sgr0
    
    if test "$PWD" = "/home/${USER}"; then
    	dir="~"
    else
    	dir=$(basename "$PWD")
    fi
    
    export PS1="[${colorized_name}\[$(tput sgr0)\]@${HOSTNAME} ${dir}]$ "
    
    unset index colorized_name brightness hue last_hue dir i
    
    #
    #
    #
    ## END OF FILE /etc/profile.d/color-prompt.inc

  6. #126
    Join Date
    Feb 2009
    Location
    Edinburgh, Scotland
    Beans
    50
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Show us your .bashrc!

    Hi all,

    I've just been modifying my default out-of-the-box .bashrc with some of the suggestions above and seem to have messed something up so that when I type a command of a certain length, instead of looping onto a new line it overtypes what I've just written... It only does this once, if I keep on typing then (what should be the 3rd line) loops onto line 2.

    Any ideas what I've done? See my .bashrc below:

    Code:
    ## Chris's ~/.bashrc
    
    # Define a few Colours
    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'              # No Color
    
    ## Some Basics
    export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
    export HISTCONTROL=ignoreboth
    shopt -s histappend
    shopt -s checkwinsize
    
    # make less more friendly for non-text input files, see lesspipe(1)
    [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
    
    
    ## Setup Prompt
    PS1="${BLUE}(${RED}\W${BLUE}) ${NORMAL}\h ${RED}\$ ${NC}"
    
    
    # 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
    
    
    # Aliases
    alias ls='ls --color=auto'
    alias ll='ls -l --color=auto'
    alias la='ls -A --color=auto'
    alias l='ls -CF --color=auto'
    alias ..='cd ..'
    alias gerp='grep --color=auto'
    alias del='rm --target-directory=$HOME/.Trash/'
    
    # Bash Completion
    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
    
    # 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
    }
    
    
    # WELCOME SCREEN
    ################################################## #####
    
    clear
    
    echo -ne "${LIGHTBLUE}" "Hello, $USER. Today is, "; date
    echo -e "${BLACK}"; cal -3;
    #echo -ne "${CYAN}";
    Attached Images Attached Images

  7. #127
    Join Date
    Aug 2006
    Location
    US
    Beans
    1,681

    Re: Show us your .bashrc!

    Here's mine

    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
    
    #dbbolton
    
    # 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)"
    
    # 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\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    #    ;;
    #*)
    #    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    #    ;;
    #esac
    
    # Comment in the above and uncomment this below for a color prompt
    #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    
    PS1='${debian_chroot:+($debian_chroot)}\[\033[0;38;5;32m\][\[\033[0;38;5;202m\] \w \[\033[0;38;5;32m\]]\[\033[00m\] '
    
    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
        ;;
    *)
        ;;
    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 [ "$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
    
    # some more ls aliases
    #alias ll='ls -l'
    #alias la='ls -A'
    #alias l='ls -CF'
    
    alias install='sudo aptitude install'
    alias ntrgn='nitrogen --sort=alpha /home/daniel/Images/Wallpaper'
    alias up='cd ..'
    alias update='sudo aptitude update'
    alias upgrade='sudo aptitude safe-upgrade'
    alias gmail='/home/daniel/bin/Scripts/checkgmail'
    
    # 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
    
    # set PATH so it includes user's private bin if it exists
    if [ -d ~/bin ] ; then
        PATH=~/bin:"${PATH}"
    fi
    Attached Images Attached Images

  8. #128
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    Re: Show us your .bashrc!

    Quote Originally Posted by WhiskyChris View Post
    Hi all,

    I've just been modifying my default out-of-the-box .bashrc with some of the suggestions above and seem to have messed something up so that when I type a command of a certain length, instead of looping onto a new line it overtypes what I've just written... It only does this once, if I keep on typing then (what should be the 3rd line) loops onto line 2.

    Any ideas what I've done? See my .bashrc below:
    I had the same problem once.
    It's because you didn't use the '\[' and '\]' to indicate beginning and end of a sequence of non-printing characters.

    Here's a fixed version of your .bashrc:
    Code:
    ## Chris's ~/.bashrc
    
    # Define a few Colours for PS1
    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\]'              # No Color
    
    # Define a few Colours for echo
    _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'              # No Color
    
    ## Some Basics
    export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
    export HISTCONTROL=ignoreboth
    shopt -s histappend
    shopt -s checkwinsize
    
    # make less more friendly for non-text input files, see lesspipe(1)
    [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
    
    
    ## Setup Prompt
    PS1="${BLUE}(${RED}\W${BLUE}) ${NORMAL}\h ${RED}\$ ${NC}"
    
    
    # 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
    
    
    # Aliases
    alias ls='ls --color=auto'
    alias ll='ls -l --color=auto'
    alias la='ls -A --color=auto'
    alias l='ls -CF --color=auto'
    alias ..='cd ..'
    alias gerp='grep --color=auto'
    alias del='rm --target-directory=$HOME/.Trash/'
    
    # Bash Completion
    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
    
    # 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
    }
    
    
    # WELCOME SCREEN
    ################################################## #####
    
    clear
    
    echo -ne "${_LIGHTBLUE}" "Hello, $USER. Today is, "; date
    echo -e "${_BLACK}"; cal -3;
    #echo -ne "${_CYAN}";
    I had to add other color commands for the echo command because otherwise it displays '\[\]' for each color command.
    There may be a better way to do this like using several echo commands, but this works.

  9. #129
    Join Date
    Feb 2009
    Location
    Edinburgh, Scotland
    Beans
    50
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Show us your .bashrc!

    Thanks for your help KIAaze, works nicely now!

  10. #130
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: Show us your .bashrc!

    Nice to see this thread getting some traffic.

    KIAaze: you hit the nail on the head , very nice solution as well. I am going to add that to my blog and .bashrc.

    See this page, look at the most recent comments at the bottom :

    http://blog.bodhizazen.net/linux/sha...ions-over-ssh/
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

Page 13 of 18 FirstFirst ... 31112131415 ... 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
  •