8Feb/102
Stick this in your bash
This isn't a tutorial or anything. Its merely just me dropping all my bash scripts/prompt stuff here so maybe I'll get some comments/tips on cool stuff to add, and so that I can always rip it if I'm on a remote computer.
My pride and joy is that bash prompt. So much info. Its a pretty cool bash prompt if I do say so myself (toot toot) ![]()
Username@Host
List of IP Addresses
Number of files in the directory
Current Path
History Command Number
Git Branch (if a git repo)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # ~/.bash_login # Shell Options shopt -s checkwinsize shopt -s cdspell # Exports export EDITOR="mate -w" export VISUAL="mate -w" export HISTFILESIZE=3000 export HISTCONTROL=ignoredups export DISPLAY=:0.0 export GEM_PATH="/Library/Ruby/Gems/1.8/gems" export PATH=~/bin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:~/bin:/usr/local/bin:/Applications/flex_sdk_3/bin:$PATH # include functions, aliases & bashrc if [ -f ~/.functions ]; then . ~/.functions; fi if [ -f ~/.aliases ]; then . ~/.aliases; fi if [ -f ~/.bashrc ]; then . ~/.bashrc; fi if [ -f ~/.bash_prompt ]; then . ~/.bash_prompt; fi if [ -f /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completion fi complete -C ~/.bash_completion.d/rake -o default rake date if [ -x /opt/local/bin/fortune ]; then /opt/local/bin/fortune -s fi |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # ~/.bash_prompt # Define a few Color's 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[0;37m\]' NC='\[\e[0m\]' # No Color function drpmpt () { first_prompt_line="$WHITE($CYAN\u@\h$WHITE)-($CYAN$(ip)$WHITE)->" second_prompt_line="$WHITE($CYAN$(ls -1|wc -l|tr -d "[:blank:]") files$WHITE)-($CYAN\w$WHITE)->" third_prompt_line="$WHITE($GREEN!\!$WHITE)$GREEN$(parse_git_branch)$WHITE" working_prompt="$first_prompt_line\n$second_prompt_line\n$third_prompt_line> $NC" PS1=$working_prompt } PROMPT_COMMAND=drpmpt |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # ~/.aliases # TO BYPASS AN ALIAS DO THE ORIGINAL COMMAND W \, ie \ls # Aliases alias pastie='sake pastie:clip' alias ..='cd ..' alias igem='sudo gem install --no-rdoc --no-ri' alias c='clear' alias dsrm="find . -type f -name .DS_Store -print0 | xargs -0 rm" alias gcpp='dsrm; git commit .; git pull; git push' alias sha1sum='openssl sha1' alias lgem='gem install --no-rdoc --no-ri -i ./gems --ignore-dependencies' alias start_wowza='/Library/WowzaMediaServerPro/bin/startup.sh' alias stop_wowza='/Library/WowzaMediaServerPro/bin/shutdown.sh' alias hist='history | grep $1' alias ps='ps aux' alias home='cd ~' alias utgz='tar -zxvf' alias tgz='tar -zcvf' alias mnts='df -h' # Alias to multiple ls commands alias la='ls -Al' # show hidden files #alias ls='ls -aF ' # add colors and file type extensions #alias lx='ls -lXB' # sort by extension alias lk='ls -lSr' # sort by size alias lc='ls -lcr' # sort by change time alias lu='ls -lur' # sort by access time alias lr='ls -lR' # recursive ls alias lt='ls -ltr' # sort by date alias lm='ls -al |more' # pipe through 'more' # Alias chmod commands alias mx='chmod a+x' alias 000='chmod 000' alias 644='chmod 644' alias 755='chmod 755' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # ~/.functions # Parse git branch parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/' } # Get assigned ip address ip(){ OS=`uname` case $OS in Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;; FreeBSD|OpenBSD|Darwin) IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;; SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;; *) IP="Unknown";; esac # Remove new lines and trailing whitespace. echo "$IP" | awk '{ printf "%s | ", $0 }' | awk '{ sub(/(\ \|\ )$/, ""); print}' } #Determine if an app is running list(){ ps aux -m -r | grep $1 } git_prompt_ip(){ export GIT_PROMPT_IP=$1 } |
February 10th, 2010 - 09:04
My prompt: http://i.imgur.com/eassO.png
I stole most of it from… somewhere I can’t remember. My only addition is the git file change count, which I find immensely useful. Here’s how I did that: http://pastie.org/818455
I use the grml zshrc (http://www.archlinux.org/packages/extra/any/grml-zsh-config/) on my laptop. It has some amazing functions for git and others that I would recommend checking out.
February 10th, 2010 - 10:28
Ah… the changed file count is slick! I’m adding it to mine, thanks!