# ~/.bashrc: executed by bash(1) for non-login shells. # ~/.bashrc is read and executed by Bash every time you start a subshell. # # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # # THIS FILE IS FOR PERSONAL ALIASES AND FUNCTIONS # # Customized by Ataualpa. Last Change: 3 dicembre 2008 # check "PS1", se non è definito (sessione non interattiva) -> STOP if [ -z "$PS1" ]; then return fi # Altrimenti, con sessione interattiva, prosegui: if [ "$PS1" ]; then # --------------------------------------------------------------- # SHELL/TERMINALE # --------------------------------------------------------------- # Include alias e funzioni dal file /etc/bash.bashrc se esiste if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi # Settaggio del titolo della finestra del terminale X # Impostato a: user@host:dir # (Bash esegue il valore della variabile PROMPT_COMMAND # come un comando prima di visualizzare il prompt $PS1) # case $TERM in xterm*|rxvt|rxvt-unicode|urxvt|Eterm|eterm) PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' ;; screen) PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' ;; esac # Non crea file coredump. # Per creare file coredump "ulimit -c unlimited" (rischio segmentation fault). ulimit -c 0 # grep e ls a colori export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32' export LS_OPTIONS='--color=auto' # Abilita la programmable completion features. # Se già abilitato in /etc/bash.bashrc può essere # commentato # (va installato il pacchetto bash-completion) if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi # --------------------------------------------------------------- # altre SHOPT options # --------------------------------------------------------------- # verifica la dimensione della finestra dopo ogni comando # e aggiorna il valore di LINES e COLUMNS se necessario. shopt -s checkwinsize # corregge errori di digitazione digitati nel comando 'cd' shopt -s cdspell # consente la tab completion per i file nascosti (.*) shopt -s dotglob # Impedisce che il fallimento di comandi `exec' provochi il flush della shell. shopt -s execfail # show status of terminated programs immediately set -o notify # --------------------------------------------------------------- # HISTORY # --------------------------------------------------------------- # Numero massimo dei comandi archiviati nel file history. Default 500. export HISTSIZE=1000 # Numero massimo di linee contenute nel file history. Defaults 500. export HISTFILESIZE=1000 # Inserimento di data e ora di registrazione di ogni comando export HISTTIMEFORMAT="[%Y-%m-%d - %H:%M:%S] " # Lista di pattern utilizzati per decidere quali comandi NON salvare nel file history export HISTIGNORE="[ ]*:&:]*:[bf]g:ls:su:fetchmail*:pwd:exit:clear:logout:ls*:history*:find ." # Non aggiunge nel file history comandi duplicati (ignoredups) e comandi # preceduti da uno spazio (ignorespace) #export HISTCONTROL=ignoredups #export HISTCONTROL=ignorespace export HISTCONTROL=ignoreboth # aggiunge i comandi invece di sovrascriverli nel file history shopt -s histappend # scrive comandi multi riga come una unica riga nel file history shopt -s cmdhist # ogni volta che viene visualizzato un prompt, aggiunge al file history # la linea precedente e rilegge la history #PROMPT_COMMAND='history -a' #PROMPT_COMMAND='history -a; history -n; \$PROMPT_COMMAND' # --------------------------------------------------------------- # Colori da utilizzare in variabili (es: per il prompt) # --------------------------------------------------------------- # I colori definiti Light, sono tali in console, mentre al terminale # diventano colori Bold # Foreground colors BLACK='\[\033[30m\]' DARKGRAY='\[\033[1;30m\]' RED='\[\033[31m\]' LIGHTRED='\[\033[1;31m\]' GREEN='\[\033[32m\]' LIGHTGREEN='\[\033[1;32m\]' BROWN='\[\033[33m\]' YELLOW='\[\033[1;33m\]' BLUE='\[\033[34m\]' LIGHTBLUE='\[\033[1;34m\]' PURPLE='\[\033[35m\]' LIGHTPURPLE='\[\033[1;35m\]' CYAN='\[\033[36m\]' LIGHTCYAN='\[\033[1;36m\]' LIGHTGRAY='\[\033[37m\]' WHITE='\[\033[1;37m\]' # Background colors BG_BLACK='\[\033[40m\]' BG_RED='\[\033[41m\]' BG_GREEN='\[\033[42m\]' BG_BROWN='\[\033[43m\]' BG_BLUE='\[\033[44m\]' BG_PURPLE='\[\033[45m\]' BG_CYAN='\[\033[46m\]' BG_WHITE='\[\033[47m\]' # Meta-colors BOLD='\[\033[1m\]' UNDERSCORE='\[\033[4m\]' BLINK='\[\033[5m\]' REVERSE='\[\033[7m\]' NONE='\[\033[0m\]' # No Color # --------------------------------------------------------------- # PROMPT # http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ # http://www.linuxhelp.net/guides/bashprompt/bashprompt-print.php # --------------------------------------------------------------- # Principali variabili utilizzabili nella costruzione del prompt # \u = nome utente # \H = hostname completo # \h = hostname ridotto # \w = directory corrente intera, es.: /home/ataualpa/Mail # \W = basename della directory corrente, es.: Mail # \$ = identificatore di utente ($ per utenti, # per root) # \t = ora in formato 24 ore # \T = ora in formato 12 ore # \@ = ora in formato 12 ore am/pm # \d = data # \! = numero del comando history # \# = numero del comando # \l = numero del terminal device (tty), es.: 2 # \j = numero dei processi in background/sospesi # \l = basename del nome del terminale # \s = shell # \n = newline # \r = carriage return # \\ = backslash # Prompt di default (su due righe, la prima per l'ora e la path) # (colorato per individuarlo meglio quando si scrolla) #PS1='\u@\h:\w\$ ' export PS1="${GREEN}[\t]-[\$PWD]${NONE}\\n${GREEN}\u\$ ${NONE}" # Command continuations are indicated by the PS2 string export PS2="${GREEN}+++${NONE}: " # Midnight-Commander Color export MC_COLOR_TABLE=base_color=black,white:normal=blue,white:selected=white,blue:marked=black,white:markselect=yellow,white:directory=blue,white:executable=red,white:link=green,white:device=brightmagenta,white:special=brown,white:errors=white,blue:reverse=brightred,white:gauge=green,white:input=black,white:dnormal=white,blue:dfocus=white,red:dhotnormal=white,blue:dhotfocus=brightcyan,blue:menu=white,blue:menuhot=red,blue:menusel=blue,white:menuhotsel=magenta,blue:helpnormal=white,blue:editnormal=green,black:editbold=white,brightred:editmarked=yellow,black:stalelink=red,white # Poichè il .bashrc dell'utente root nel mio sistema è # creato come link simbolico al .bashrc dell'utente, con questo # test modifico il prompt quando divento root. # Prompt per utente root # if [ `id -u` -eq 0 ] # test mediante uid (root ha 0) if test $USER = root then export PS1="${RED}[\$PWD]${NONE}\\n${RED}\u# ${NONE}" export PS2="${RED}+++${NONE}: " # Midnight-Commander Color per Root export MC_COLOR_TABLE=base_color=white,red:normal=lightgray,red:input=white,brown:errors=white,brightred:reverse=white,blue:gauge=brown,black:selected=black,white:marked=yellow,red:markselect=yellow,white:directory=white,red:executable=brightgreen,red:link=brightblue,red:device=brightmagenta,red:special=brightcyan,red:core=brighyellow,red:menu=black,white:menuhot=brightblue,white:menuhotsel=brightred,black:dnormal=black,white:dfocus=white,lightgray:dhotnormal=blue,white:dhotfocus=brightred,lightgray:editnormal=white,black:editmarked=black,white fi # Prompt per utente ataualpa if test $USER = ataualpa then export PS1="${GREEN}[\$PWD]${NONE}\\n${GREEN}\u\$ ${NONE}" export PS2="${GREEN}+++${NONE}: " # Midnight-Commander Color per utente export MC_COLOR_TABLE=base_color=black,white:normal=blue,white:selected=white,blue:marked=black,white:markselect=yellow,white:directory=blue,white:executable=red,white:link=green,white:device=brightmagenta,white:special=brown,white:errors=white,blue:reverse=brightred,white:gauge=green,white:input=black,white:dnormal=white,blue:dfocus=white,red:dhotnormal=white,blue:dhotfocus=brightcyan,blue:menu=white,blue:menuhot=red,blue:menusel=blue,white:menuhotsel=magenta,blue:helpnormal=white,blue:editnormal=green,black:editbold=white,brightred:editmarked=yellow,black:stalelink=red,white fi # Keyword per settaggio colori mc (midnight commander) # Base colors: normal, selected, marked, markselect, errors, input, reverse, gauge # Menu colors: menu, menusel, menuhot, menuhotsel # Dialog colors: dnormal, dfocus, dhotnormal, dhotfocus # Help colors: helpnormal, helpitalic, helpbold, helplink, helpslink # Viewer color: viewunderline # Special highlighting colors: executable, directory, link, stalelink, device, special, core # Editor colors: editnormal, editbold, editmarked # # La sintassi per ogni keyword (tra loro separate da :): # =, # # Possibili colori: # black, gray, red, green, brown, blue, yellow, magenta, cyan, white # brightred, brightgreen, brightblue, brightmagenta, brightcyan, lightgray # Special keyword for transparent background: default # --------------------------------------------------------------- # ALIAS # --------------------------------------------------------------- # Ricarica .bashrc (dopo una modifica) alias reload="source ~/.bashrc" # Alias - navigazione nel sistema alias cd..="cd .." #alias .='cwd' alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias p='cd -' alias back='cd $OLDPWD' alias src='cd /usr/src' # change to source dir alias log='cd /var/log' # change to log dir alias down='cd ~/MyDownloads' alias film='cd ~/MyDownloads/Films' alias foto='cd ~/Documenti/Immagini' alias donk='cd ~/.mldonkey/incoming/files' alias torr='cd ~/deluge/incoming' # ls colorato eval `dircolors -b` alias ls='ls --color=auto' alias dir='ls --color=auto --format=vertical' alias vdir='ls --color=auto --format=long' # Altri alias per ls #alias d='ls' #alias ll='ls -l' #alias la='ls -A' #alias l='ls -CF' #alias ls="ls -s -F -T 0 -b -H -1 -C --color=auto" # Alias gestione file alias cp="cp -i" # chiedi conferma prima di sovrascrivere alias mv="mv -i" # chiedi conferma prima di sovrascrivere alias rm="rm -i" # chiedi conferma prima di eliminare # Alias gestione sistema alias hi="history" alias x='exit' alias shutdown='sudo shutdown -h now' alias reboot='sudo shutdown -r now' # Elenca i comandi più utilizzati # from: http://lifehacker.com/software/how-to/turbocharge-your-terminal-274317.php alias mucom="history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"} {print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr" # Elenca i 10 file di maggiori dimensioni (path corrente) alias bigfiles="BLOCKSIZE=1048576; du -x | sort -nr | head -10" # Elenca i 20 file modificati più di recente alias lastfile='ls -alt | head -20' # Elenca la dimensione della directory corrente alias du="du -h -c --max-depth=1" # Elenca le partizioni e relative informazioni alias df="df -Th" # va installato il pacchetto htop alias top="htop" # Elenca i processi alias ps='ps auxfwww' # Alias - rete alias netstat='netstat -nap --inet' alias openports="netstat -nape --inet" alias ping='ping -c 5' # alias per gestione CD alias cdrin='mount /cdrom ; cd /cdrom ; ls' alias cdrout='cd ; umount /cdrom ; eject' alias cdwin='mount /cdburner ; cd /cdburner ; ls' alias cdwout='cd ; umount /cdburner ; eject' #alias startx='startx -- -nolisten tcp' #alias per posta e news alias sendposta='sudo /usr/sbin/sendmail -q -v' alias prendinews='sudo /usr/sbin/fetchnews -vvv' alias mutty='mutt -y' alias slrn='slrn' # Debian package management alias -- -search="apt-cache search" alias -- -show="apt-cache show" alias -- -install="apt-get install" alias -- -remove="apt-get remove" alias -- -update="apt-get update" alias -- -upgrade="apt-get upgrade" alias -- -source="dpkg -S" alias -- -list="dpkg -l" alias -- -files="dpkg -L" # --------------------------------------------------------------- # FUNCTIONS # --------------------------------------------------------------- # from http://www.macosxhints.com/article.php?story=20020716005123797 # The following aliases (save & show) are for saving frequently # used directories. You can save a directory using an abbreviation # of your choosing. Eg.: save ms You can subsequently move to one of # the saved directories by using cd with the abbreviation you chose. # Eg. cd ms (Note that no '$' is necessary.) # crea il file per le abbreviazioni (se non già esistente) if [ ! -f ~/.dirs ]; then # if doesn't exist, create it touch ~/.dirs fi # per visualizzare le abbreviazioni salvate alias show='cat ~/.dirs' # funzione per il salvataggio save () { command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ; } source ~/.dirs # Initialization for the above 'save' facility: source the .sdirs file shopt -s cdable_vars # set the bash option so that no '$' is required when using the above facility # dimensione del file indicato, in MB sizeof () { shr "puts sizeof('$1')" } # dimensione della directory corrente dirsize () { shr "puts dirsize" } # invia un HUP al NOME del processo indicato hup () { kill -HUP `pidof $1`; } # elenca i processi zombie zombi () { ps hr -Nos | awk '$1=="Z" {print $1}' } # edita ~/.bashrc e lo ricarica function ebash { if [ ! -z $DISPLAY ]; then xjed ~/.bashrc; reload;. else jed ~/.bashrc; reload; fi; } # ricerca la stringa indicata tra i processi function psgrep { command ps -A -o pid,uname,%cpu,%mem,stat,time,args | grep "$@" } # elenca i file più recenti nella directory lsnew () { ls -lt ${1+"$@"} | head -20; } # bugs RC per la nuova debian-release function debre { links -dump http://bugs.debian.org/release-critical/ | grep "next release" | grep -v graphs } # Ricerca History function hgrep { history | grep $1 | sed '$d' } # Cambia estensione (rinomina *.foo in *.bar) # il primo argomento è l'estensione da cambiare # il secondo argomento è l'estensione da assegnare function rename_ext { for f in *.$1; do mv $f ${f%$1}$2 done } # Mostra la struttura della directory # Stolen from no other than Harald Hannelius himself :) # tree () { echo -e "\033[1;33m" (cd ${1-.} ; pwd) find ${1-.} -print | sort -f | sed \ \ -e "s,^${1-.},," \ -e "/^$/d" \ -e "s,[^/]*/\([^/]*\)$,\ |-->\1," \ -e "s,[^/]*/, | ,g" echo -e "\033[0m" } # Mostra la struttura delle directory (più veloce di tree) # from Kevin Hatfield's .bashrc tre () { find . | ${BIN_PATH}sed -e 's/[^\/]*\//|----/g' -e 's/---- |/|/g' | $PAGER } # Rinomina i file in lettere minuscole # lowercase () { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } # Visualizza i colori ANSI ansi() { esc="\033[" echo -e "\t 40\t 41\t 42\t 43\t 44 45\t46\t 47" for fore in 30 31 32 33 34 35 36 37; do line1="$fore " line2=" " for back in 40 41 42 43 44 45 46 47; do line1="${line1}${esc}${back};${fore}m Normal ${esc}0m" line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m" done echo -e "$line1\n$line2" done echo "" echo "# Esempio:" echo "#" echo "# Scrive un FANCULO lampeggiante nei colori del Parma (Giallo Blu)" echo "#" echo "# ESC" echo "# | CD" echo "# | | CD2" echo "# | | | FG" echo "# | | | | BG + m" echo "# | | | | | END-CD" echo "# | | | | | |" echo "# echo -e '\033[1;5;33;44mFANCULO\033[0m'" echo "#" } # Crea un archivio della directory specificata mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; } mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; } # Crea un archivio tar.bz2 della directory specificata # Sintassi: bz2dir path.della.directory.da.comprimere bz2dir() { if [ "$1" != "" ]; then FOLDER_IN=`echo $1 |sed -e 's/\/$//'`; FILE_OUT="$FOLDER_IN.tar.bz2"; FOLDER_IN="$FOLDER_IN/"; echo "Sto comprimendo $FOLDER_IN nel file $FILE_OUT\u2026"; echo "tar cjf $FILE_OUT $FOLDER_IN"; tar cjf "$FILE_OUT" "$FOLDER_IN"; echo "Fatto."; fi } # Crea un archivo tar.bz2 del file specificato # Sintassi: bz2 nome.del.file.da.comprimere bz2 () { tar cvpjf $1.tar.bz2 $1 } # estrae file da archivi compressi. # sintassi: extract nomearchivio 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 "Filetype di '$1' non riconosciuto" ;; esac else echo "Sintassi: extract nomefile" fi } # roll - archive wrapper # usage: roll ./foo ./bar roll () { FILE=$1 case $FILE in *.tar.bz2) shift && tar cjf $FILE $* ;; *.tar.gz) shift && tar czf $FILE $* ;; *.tgz) shift && tar czf $FILE $* ;; *.zip) shift && zip $FILE $* ;; *.rar) shift && rar $FILE $* ;; esac } # define - ricava la definizione di una parola da google # sintassi: define define () { lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 5 -w "*" | sed 's/;/ -/g' | cut -d- -f5 > ~/temp/templookup.txt if [[ -s ~/temp/templookup.txt ]] ;then until ! read response do echo "${response}" done < ~/temp/templookup.txt else echo "Mi dispiace $USER, ma non trovo il termine \"${1}\"" fi rm -f ~/temp/templookup.txt } # Simple reminder (lasciare la shell aperta!) # Sintassi: ricorda