Subscribe

Archive | Technology

.bashrc fu

So either you were born in the MSDOS era or you just enjoy typing commands over clicking GUI elements. Then there are a few tips and tricks that you can use to make your terminal more customized to your liking.

So this is a screen shot of my Terminal (running bash) on my OSX:

Personally I still haven’t figured how the rename clicking thing works in OSX, you click once, nothing happens, then click again, and click, long click, short click, (hard click, soft click, personally I still think you just have to get the pressure and timing right to rename a file with Finder. jk) until the filename highlights itself. but at times, I will be very fed up with the (over) user friendless of OSX and  just have to go to Terminal to perform the tasks that I want my computer to perform. With that in mind, if you use .bashrc or .profile then there are tons of neat tricks and tips you can use to make Terminal much faster for you.

Without further ado, here is my .profile file:

#!/bin/bash
shopt -s histappend # append, don't over write
export HISTFILESIZE=3000 # the bash history should save 3000 commands
export HISTCONTROL=ignoredups #don't put duplicate lines in the history.
#------------------------------------------////
# Fink:
#------------------------------------------////
test -r /sw/bin/init.sh && . /sw/bin/init.sh
test -r /sw/bin/init.sh && . /sw/bin/init.sh
#------------------------------------------////
# Colors:
#------------------------------------------////
black='\033[0;30m'
blue='\033[0;34m'
green='\033[0;32m'
cyan='\033[0;36m'
red='\033[0;31m'
purple='\033[0;35m'
brown='\033[0;33m'
lightgray='\033[0;37m'
darkgray='\033[1;30m'
lightblue='\033[1;34m'
lightgreen='\033[1;32m'
lightcyan='\033[1;36m'
lightred='\033[1;31m'
lightpurple='\033[1;35m'
yellow='\033[1;33m'
white='\033[1;37m'
nc='\033[0m'
#------------------------------------------////
# Prompt:
#------------------------------------------////
export PS1="
\[${brown}\][\!]\`
if [[ \$? = "0" ]]; then
	echo "\\[\\033[32m\\]";
else
	echo "\\[\\033[31m\\]";
fi
\`[\u.\h: \`
if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then
	echo "\\W";
else
	echo "\\w";
fi
\`]\$\[\033[0m\] ";
echo -ne "\033]0;
`hostname -s`:`pwd`\007"
#------------------------------------------////
# Alias
#------------------------------------------////
alias ls='ls -l'
alias la='ls -A'
alias lc='clear; ls'
alias lsd='ls -l | grep "^d"'   #list only directories
alias reload='source ~/.profile'
alias back='cd $OLDPWD'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias uwdc='ssh root@uwdc.ca'
alias hist='history | grep $1' #Requires one input
#------------------------------------------////
# System Information: On Load
#------------------------------------------////
clear
figlet BASH FU
echo -ne "${red}Today is:\t\t${cyan}" `date`;echo "";
echo -e "${red}Kernel Information:\t${cyan}" `uname -smr`
echo -ne "${red}Up Time:\t\t ${cyan}";uptime;echo ""
cal
cd() {
	if [ -n "$1" ]; then
		builtin cd "$@" && ls
	else
		builtin cd ~ && ls
	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
}