#!/bin/bash #------------------------------------------//// # Lapbox ~/.bashrc file ยค BK # Last Modified 21 June 2011 # Running on Debian GNU/Linux - Squeeze #------------------------------------------//// #------------------------------------------//// # Colors: #------------------------------------------//// 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' #--------------------------------------------//// # System Information Visible in TerminalFu: #--------------------------------------------//// clear echo -e "${LIGHTGRAY}";figlet "TerminalFu"; #date +%T|figlet #echo -e "${white}";ddate #echo -ne "${cyan}"`date`; echo -e "${cyan}\t"`uname -smr` #echo -e "${cyan}"; cal -3 #echo "Bask in the Terminal-Fu. Be the Terminal-Fu" | pv -qL 10 #echo -e "${LIGHTGRAY}";fortune debian-hints #------------------------------------------//// # Prompt: #------------------------------------------//// PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] $(date +%H:%M) [ \[\033[01;34m\]\w\[\033[00m\] ]:\$ ' #--------------------------------------------//// # Sane: #--------------------------------------------//// if [ "$PS1" ]; then xmodmap -e "remove lock = Caps_Lock" fi export EDITOR=/usr/bin/nano export HISTCONTROL=ignoredups:ignorespace #------------------------------------------//// # Proxy: #------------------------------------------//// #http_proxy=http://127.0.0.1:8118/ #HTTP_PROXY=$http_proxy #export http_proxy HTTP_PROXY #------------------------------------------//// # Aliases: #------------------------------------------//// alias findbig='find . -type f -exec ls -s {} \; | sort -n -r | head -5' alias cleanmem='sudo sync && echo 1 > /proc/sys/vm/drop_caches' alias orphans='sudo deborphan' alias sleep='sudo /usr/sbin/pm-suspend' alias update='sudo aptitude update' alias upgrade='sudo aptitude full-upgrade' alias cpf='sudo aptitude clean && sudo aptitude purge ~c && sudo aptitude -f install' alias search='aptitude search' alias remove='sudo aptitude --purge remove' alias install='sudo aptitude --without-recommends install' alias again='sudo shutdown -r now' alias off='sudo shutdown -h now' alias show='aptitude show' alias list='dpkg -L' alias apps='sudo synaptic' alias weather='sh ~/.config/scripts/weather.sh -a [b]put your zip code here[/b]' alias java='/usr/local/jre1.6.0_25/bin/java' alias terms='sudo cryptsetup luksOpen /dev/sdb1 terms && mount /mnt/terms' alias closeterms='sudo umount /mnt/terms && sudo cryptsetup luksClose terms' alias ports='sudo netstat -nape --inet' alias ping='ping -c 4' alias ns='sudo netstat -alnp --protocol=inet' alias router='opera --newtab --nomail http://192.168.1.1 &' export LS_OPTIONS='--color=auto' eval "`dircolors`" alias ls='ls -la $LS_OPTIONS' alias lx='ls -lXB' alias lk='ls -lSr' alias lc='ls -lcr' alias lu='ls -lur' alias lr='ls -lR' alias lt='ls -ltr' alias lm='ls -al |more' #------------------------------------------//// # Functions and Scripts: #------------------------------------------//// #------------------------------------------//// # Handy One-Liners: #------------------------------------------//// function historyawk(){ history|awk '{a[$2]++}END{for(i in a){printf"%5d\t%s\n",a[i],i}}'|sort -nr|head; } function mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } function lsmac() { sudo ifconfig -a | awk '/HWaddr/ {print $5}' ; } function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; } function wordnet() { curl dict://dict.org/d:${1}:wn; } #------------------------------------------//// # Handy Utility: #------------------------------------------//// function sitepass() { echo -n "$@" | md5sum | sha1sum | sha224sum | sha256sum | sha384sum | sha512sum | gzip - | strings -n 1 | tr -d "[:space:]" | tr -s '[:print:]' | tr '!-~' 'P-~!-O' | rev | cut -b 2-11; history -d $(($HISTCMD-1)); } function fix() { if [ -d $1 ]; then find $1 -type d -exec chmod 755 {} \; find $1 -type f -exec chmod 644 {} \; else echo "$1 is not a directory." fi } function mkcdr() { mkdir -p -v $1 cd $1 } function stopwatch() { # copyright 2007 - 2010 Christopher Bratusek BEGIN=$(date +%s) while true; do NOW=$(date +%s) DIFF=$(($NOW - $BEGIN)) MINS=$(($DIFF / 60)) SECS=$(($DIFF % 60)) echo -ne "Time elapsed: $MINS:`printf %02d $SECS`\r" done } ###### lowercase all files in the current directory function lcfiles() { print -n 'Really lowercase all files? (y/n) ' if read -q ; then for i in * ; do mv $i $i:l done fi } ###### Space removal and lowercases folders in current dir. function rmspaces() { ls | while read -r FILE do mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'` done } ###### Convert the first letter into uppercase letters function ucfirst() { if [ -n "$1" ]; then perl -e 'print ucfirst('$1')' else cat - | perl -ne 'print ucfirst($_)' fi } function cd() { if [ -n "$1" ]; then builtin cd "$@" && ls else builtin cd ~ && ls fi } function encrypt () { gpg -ac --no-options "$1" } function decrypt () { gpg --no-options "$1" } function encfile () { zenity --title="zcrypt: Select a file to encrypt" --file-selection > zcrypt encryptthisfile=`cat zcrypt`;rm zcrypt # Use ascii armor # --no-options (for NO gui usage) gpg -acq --yes ${encryptthisfile} zenity --info --title "File Encrypted" --text "$encryptthisfile has been encrypted" } function decfile () { zenity --title="zcrypt: Select a file to decrypt" --file-selection > zcrypt decryptthisfile=`cat zcrypt`;rm zcrypt # NOTE: This will OVERWRITE existing files with the same name !!! gpg --yes -q ${decryptthisfile} zenity --info --title "File Decrypted" --text "$encryptthisfile has been decrypted" } function extract() { if [ -f "$1" ] ; then case "$1" in *.tar.bz2) tar xjf "$1" ;; *.tar.gz) tar xzf "$1" ;; *.tar.Z) tar xzf "$1" ;; *.bz2) bunzip2 "$1" ;; *.rar) unrar x "$1" ;; *.gz) gunzip "$1" ;; *.jar) unzip "$1" ;; *.tar) tar xf "$1" ;; *.tbz2) tar xjf "$1" ;; *.tgz) tar xzf "$1" ;; *.zip) unzip "$1" ;; *.Z) uncompress "$1" ;; *) echo "'$1' cannot be extracted." ;; esac else echo "'$1' is not a file." fi } #------------------------------------------//// # Handy Network: #------------------------------------------//// function myip () { lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | grep "Current IP Address" | cut -d":" -f2 | cut -d" " -f2 } function portscan() { $HOST=127.0.0.1;for((port=1;port<=65535;++port));do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null;then echo -en "\n\nport $port/tcp is open\n\n";fi;done } function hostis() # Get current host related info. { echo -e "\nYou are logged on ${RED}$HOST" echo -e "\nAdditionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date :$NC " ; date echo -e "\n${RED}Machine stats :$NC " ; uptime echo -e "\n${RED}Memory stats :$NC " ; free my_ip 2>&- ; echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"} echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"} echo -e "\n${RED}Open connections :$NC "; netstat -pan --inet; echo } function localnet () { /sbin/ifconfig | awk /'inet addr/ {print $2}' echo "" /sbin/ifconfig | awk /'Bcast/ {print $3}' echo "" } #------------------------------------------//// # Handy Info: #------------------------------------------//// function fact() { dict -d world02 $@ } function ii() { echo -e "\n${RED}You are logged onto:$NC " ; hostname echo -e "\n${RED}Additionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date:$NC " ; date echo -e "\n${RED}Machine stat:$NC " ; uptime echo -e "\n${RED}Disk space:$NC " ; df -h echo -e "\n${RED}Memory stats (in MB):$NC " ; if [ "$OS" = "Linux" ]; then free -m elif [ "$OS" = "Darwin" ]; then vm_stat fi echo -e "\n${RED}IPs:$NC " ; ips } ###### usage: pronounce "word1" "word2" "word3" "..." function pronounce() { wget -qO- $(wget -qO- "http://dictionary.reference.com/browse/$@" | grep 'soundUrl' | head -n 1 | sed 's|.*soundUrl=\([^&]*\)&.*|\1|' | sed 's/%3A/:/g;s/%2F/\//g') | mpg123 -; } function showfile() { width=72 for input do lines="$(wc -l < $input | sed 's/ //g')" chars="$(wc -c < $input | sed 's/ //g')" owner="$(ls -ld $input | awk '{print $3}')" echo "-----------------------------------------------------------------" echo "File $input ($lines lines, $chars characters, owned by $owner):" echo "-----------------------------------------------------------------" while read line do if [ ${#line} -gt $width ] ; then echo "$line" | fmt | sed -e '1s/^/ /' -e '2,$s/^/+ /' else echo " $line" fi done < $input echo "-----------------------------------------------------------------" done | more } function 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 /tmp/list } function newest () { find . -mtime -1 -print } function upinfo () { echo -ne "${green}$HOSTNAME ${red}uptime is ${cyan} \t ";uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}' } function facts () { wget randomfunfacts.com -O - 2>/dev/null | grep \ | sed -e "s;^.*\(.*\).*$;\1;g" } function futurama () { curl -sI http://slashdot.org/ | sed -nr 's/X-(Bender|Fry)(.*)/\1\2/p' } #------------------------------------------//// # Some original .bashrc contents: #------------------------------------------//// # If not running interactively, don't do anything ##[ -z "$PS1" ] && return # 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