You are not logged in.
I use this .bashrc function to find regular files and symbolic links whose last modification or last status time is within a certain number of minutes. It prints last modification and status times, highlighting where those times are different, as well as file name, file size, and a guess (!) at the file type. Headers are printed, and numeric fields (file size, in this case) are right-adjusted. Useful for investigating what is going on in your system!
QDIRS is an whitespace-delimited environment variable holding the directories to be searched. BLUE and RESET are, respectively, '\033[1;34m' and '\033[0m'.
rf () {
# Find regular files and symbolic links whose last modification or last status time is within $1 minutes,
# highlighting where those two times are different.
# File names containing a tab character will not be processed correctly.
# File names containing a newline will be processed correctly but will print oddly!
# Any error messages other than "find: ... permission denied" (which is suppressed) will appear before the main report.
declare t=${1:-2}
declare -i i
declare -a a
( (( $# <= 1 )) && [[ "$t" =~ [[:digit:]]+ ]] ) || return $(die "Usage: $FUNCNAME [number of minutes]")
{
while IFS=$'\t' read -d $'\x0' -a a; do
for ((i = 0; i < ${#a[@]}; i++)); do
# Edit timestamps.
if ((i <= 1)); then
echo -n "${a[i]:0:10} ${a[i]:11:8}"
else
echo -n "${a[i]}"
fi
echo -ne '\t'
done
# Append a (sometimes not very good!) guess at what type of file this is.
echo -n $(file -pb "${a[2]}")
echo -ne '\x0'
done < <(find -O2 $QDIRS -xdev \( -mmin -"$t" -o -cmin -"$t" \) \( -type f -o -type l \) -printf '%T+\t%C+\t%p\t%s\0') |
sort -z -t $'\t' -s -k 1,1r -k 2,2r -k 3,3 |
gawk -v RS='\0' -v ORS='\0' -v header='Last mod\tLast status\tFile name\tSize\tFile type' -f ~/scripts/gawk/format |
gawk -v blue=$BLUE -v reset=$RESET 'BEGIN {RS="\0"; FS=OFS=" "} NR > 1 && $1 != $2 {$2 = blue $2 reset} {print}'
} 2>&1 | grep -v '^find.*Permission denied$'
}The function uses this bash error-handling helper function...
die () {
declare -i r=${2:-9}
echo "$1" 1>&2
return $r
}... and a general-purpose gawk program, ~/scripts/gawk/format, for formatting tab-delimited output, optionally adding a header:
BEGIN {
FS = "\t"; magenta = "\033[1;35m"; reset = "\033[0m"
if (header != "") {
nr = 1
nf = split(header, h, "\t")
for (f = 1; f <= nf; f++) {
line[nr,f] = h[f]
len[f] = length(h[f])
dec[f] = 1
}
}
}
{
nr++
for (f = 1; f <= NF; f++) {
sub(/ +$/, "", $f)
line[nr,f] = $f
if (length($f) > len[f])
len[f] = length($f)
if (nr == 1) {
nf = NF
dec[f] = 1
}
else {
if (dec[f] != 0 && $f !~ /^ *[[:digit:]]+$/)
dec[f] = 0
}
}
}
END {
printf magenta
for (f = 1; f <= nf; f++) {
if (dec[f] != 0) {
format[f] = "%" (len[f]) "s "
printf(format[f], line[1,f])
format[f] = "%" (len[f]) "d "
}
else {
format[f] = (f < nf) ? "%-" (len[f]) "s " : "%s"
printf(format[f], line[1,f])
}
}
print reset
for (r = 2; r <= nr; r++) {
for (f = 1; f <= nf; f++)
printf(format[f], line[r,f])
print ""
}
}A screenshot:
Last edited by qi (2009-11-15 01:19:01)
Offline
My last "bashrc" :
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# Pager
export PAGER=most
# 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
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# 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 "$(SHELL=/bin/sh 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) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='\[\033[1;34m\]┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ \[\033[0;34m\]'
else
PS1='┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ '
fi
unset color_prompt force_color_prompt
# 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
# 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 [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias install='sudo apt-get install'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get -u upgrade'
alias agi='sudo apt-get install'
alias agu='sudo apt-get update'
alias agg='sudo apt-get -u upgrade'
# 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 ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
#------------------------------------------////
# 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:
#------------------------------------------////
clear
echo -e ""
echo -e "${lightblue}Welcome on 'Kooka-PC'"
echo -e ""
echo -e "${lighblue}Today:\t\t" `date`
echo -e "${lightblue}System: Debian-Squeeze on Kernel" `uname -or`
echo -e ""My Fluidr (= Fickr) : http://www.fluidr.com/photos/kookadimi/sets
Offline
I'm working on my .bashrc right now, but I wonder if it is possible to export the value of COLUMNS and LINE (from checkwinsize)?
I've tried:
export COLUMNSbut it only returns an empty variable.
Last edited by Ouroboros (2010-02-09 22:09:44)
Offline
My Arch Linux .bashrc:
export LC_ALL=en_US.utf8
export BROWSER=firefox
export EDITOR=nano
export PAGER=less
export VISUAL=nano
export HISTSIZE=10000
export HISTFILESIZE=${HISTSIZE}
export HISTCONTROL="ignoredups"
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;38;5;74m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[38;5;246m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[04;38;5;146m'
PS1='\[\033[01;34m\]\w \[\033[01;32m\]\$\[\033[00m\] '
# Check for an interactive session
[ -z "$PS1" ] && return
# bash aliases
[ -f ~/.bash_aliases ] && . ~/.bash_aliases
shopt -s checkwinsize
shopt -s histappend
PROMPT_COMMAND='history -a'
start()
{
for arg in $*; do
sudo /etc/rc.d/$arg start
done
}
stop()
{
for arg in $*; do
sudo /etc/rc.d/$arg stop
done
}
restart()
{
for arg in $*; do
sudo /etc/rc.d/$arg restart
done
}
reload()
{
for arg in $*; do
sudo /etc/rc.d/$arg reload
done
}Note: ** Please read before posting **
BTW if you wish to contact me, send me an e-mail instead of a PM.
Offline
I'm working on my .bashrc right now, but I wonder if it is possible to export the value of COLUMNS and LINE (from checkwinsize)?
I've tried:
export COLUMNSbut it only returns an empty variable.
$COLUMNS and $LINES work fine for me without having to do anything
try
echo $COLUMNS x $LINES - - - - - - - - Wiki Pages - - - - - - -
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts
Offline
Offline
may I post a zshrc here?
go for it 
- - - - - - - - Wiki Pages - - - - - - -
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts
Offline
Or maybe not?
fhsm wrote:Little off topic but if you are interested in a .zshrc I've posted mine.
Agreed, let's stick to .bashrc here
Note: ** Please read before posting **
BTW if you wish to contact me, send me an e-mail instead of a PM.
Offline
Those of you that alias ssh's to remote machines might be interested in the following:
# run stuff on or connect to ione
io () { ssh -c arcfour -XC jt@192.168.xxx.xxx ${1+"$@"}; }
# copy file to ione's desktop
ioc () { scp ${1+"$@"} jt@192.168.xxx.xxx:/home/jt/Desktop/; }
# download file onto Desktop
iodl () { ssh jt@192.168.xxx.xxx nohup wget -b -P /home/jt/Desktop/ ${1+"$@"}; }Ione is my desktop/mediaserver/download machine, so the only time I access it is from inside my home network. Hence using arcfour compression on SSH - the speed increase when running applications using X-forwarding is astonishing, and I don't need the security as it's not going over the internet.
Because these are functions rather than aliases, they can have values passed to them by bash. So, say I can't remember which kernel my desktop is running, I can do:
jt@laptop:~$ io uname -aOn my laptop and it runs 'uname -a' on the remote machine and returns the result. running 'io' on it's own just connects me to Ione. I have passphraseless ssh auth set up between the two machines, so I never need to enter a password.
jt@laptop:~$ iodl http://crunchbanglinux.org/[...]/crunchbang-10-alpha-01-openbox-i686.isoWould download the statler iso on my desktop machine, meaning I can put my laptop back to sleep when I'm done with it, rather than waiting for downloads to finish.
hope this is useful to someone. 
Offline
i add to my .bashrc these lines, the only differences from the others' are the 2 function "psp" e "my_kill" at he end of the code.
psp $1 prints all the processes which has the string $1 in the name,
my_kill $1 kills all the processes which has the string $1 in the name
my_kill SIGNAME PROCESS_NAME instead not kill the processes but its behaviour depends on the type of signal (SIGNAME) you want to send to all the processes which has the string 'PROCESS_NAME' in the name
I hope this will be useful to someone.
alias governor='sudo cpufreq-set -g'
alias cpuinfo='cpufreq-info'
## Sudo fixes
alias install='sudo apt-get install'
alias remove='sudo apt-get --purge remove'
alias dupgrade='sudo apt-get update && sudo apt-get dist-upgrade'
alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias updatedb='sudo updatedb'
# 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 ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
#------------------------------------------////
# 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:
#------------------------------------------////
clear
echo -e "${LIGHTGRAY}";figlet "Realgpp";echo ""
echo ""
echo -ne "${red}Today is:\t\t${cyan}" `date`; echo ""
echo -e "${red}Kernel Information: \t${cyan}" `uname -smr`
echo -e "${yellow}"; cal -3
#------------------------------------------////
# Man Pages Colorate
#------------------------------------------////
export MANPAGER="/usr/bin/most -s"
#------------------------------------------
#------Extraction of compressed files------
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
my_kill () {
if ( [ $# -gt 2 ] || [ $# -lt 1 ] )
then
echo "ERR. Correct usage: $0 SIGNAME PROCESS_NAME"
exit 1
fi
SIGN=''
NAME=''
if [ $# -eq 2 ]
then
SIGN=$1
NAME=$2
else if [ $# -eq 1 ]
then
SIGN='SIGKILL'
NAME=$1
fi
fi
PD=$( ps -A | grep $NAME | awk '{print $1}' )
P=$(echo $PD)
for i in $P
do
sudo kill -s $SIGN $i
done
}
psp () {
if [ $# -lt 2 ]
then
ps -A | grep $1
else
echo "err: too parameter"
exit 1
fi
}Offline
Here's mine. It's pretty much the default for statler, just edited a bit.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# 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
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# 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 "$(SHELL=/bin/sh 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) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|screen*)
PS1="┌─[\A][\u@\h:\w]\n└─> "
;;
*)
;;
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 [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
# 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 ] && ! shopt -oq posix; then
. /etc/bash_completion
fiA world without what makes us, us. One without you or me.
A world with no differences, this is the world I see.
Offline
Here's a few functions from mine that you might find useful:
#a mkdir $dir && cd $dir shortcut
md () { mkdir -p "$1" && cd "$1"; }
#a quick history search
alias hgrep='history | grep'
#re-read ~/.bash_aliases
alias bashup='. ~/.bash_aliases'
#show time in various places
alias tz-la='TZ=":America/Los_Angeles" date'
alias tz-ny='TZ=":America/New_York" date'
alias tz-dv='TZ=":America/Denver" date'
alias tz-ldn='TZ=":Europe/London" date'
alias tz-bej='TZ="Asia/Shanghai" date'
alias tz-par='TZ=":Europe/Paris" date'
alias tz-ber='TZ=":Europe/Berlin" date'
alias tz-bang='TZ=":Asia/Bangkok" date'Laptop: Asus EEEPC 1201T | 2 gig RAM | Onboard ATI 3200 | Ubuntu 10.04 on HDD + Crunchbang Statler on 16gig SD Card
Desktop AMD Phenom x4 925 | 4gig RAM | Onboard AT1 3200 | Ubuntu 10.04 + Crunchbang on HDD
Offline
Here's mine :
############################################################################################################################################################
# AUTO-COMPLETION
############################################################################################################################################################
# Active la completion automatique
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# tab completion pour les hosts ssh
if [ -f ~/.ssh/known_hosts ]; then
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
uniq | \
egrep -v [0123456789]) )
complete -o default -W "${SSH_COMPLETE[*]}" ssh
fi
# Completion avec sudo
complete -cf sudo
############################################################################################################################################################
# SHOPTS
############################################################################################################################################################
shopt -s cdspell # Pour que bash corrige automatiquement les fautes de frappes ex: cd ~/fiml sera remplacé par cd ~/film
shopt -s checkwinsize # Pour que bash vérifie la taille de la fenêtre après chaque commande
shopt -s cmdhist # Pour que bash sauve dans l'historique les commandes qui prennent plusieurs lignes sur une seule ligne.
shopt -s dotglob # Pour que bash montre les fichiers qui commencent par un .
shopt -s expand_aliases # # Pour que bash montre la commande complete au lieu de l'alias
shopt -s extglob # Pour que bash, interprète les expressions génériques
shopt -s histappend # Pour que bash ajoute au lieu d'écraser dans l'histo
shopt -s hostcomplete # Pour que bash tente de résoudre le nom pour les ip suivis d'un @
shopt -s nocaseglob # Pour que bash ne soit pas sensible a la casse
shopt -s cdable_vars # utilisé pour la fonction bookmarks pour que bash n'ai pas besoin de $ pour sourcer le fichier .dirs
############################################################################################################################################################
# ALIAS
############################################################################################################################################################
alias ls='ls --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls par default (dossier en 1er + mise en forme de l'heure)
alias lsfp='ls | sed s#^#$(pwd)/#' # ls avec full PATH
alias ll='ls -l --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls détaille
alias la='ls -la --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls aussi les fichiers cachés .*
alias lsofnames="lsof | awk '!/^\$/ && /\// { print \$9 }' | sort -u" # noms des fichiers ouverts
alias grep='grep --color=tty -d skip'
alias cp="cp -i" # Confirmer avant d'écraser un fichier existant
alias df='df -h' # Tailles lisibles par l'homme
alias free='free -m' # voir la taille en MB
alias vp='vim PKGBUILD' # spécifique Arch
alias vs='vim SPLITBUILD' # spécifique Arch
alias ports="lsof -i -n -P" # Voir les process qui utilisent une connection internet
alias estab="ss -p | grep STA" # Voir seulement les sockets établis
alias netstat80="netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1" # nombre de connections sur le port 80 du serveur par IP
alias openports="netstat -nape --inet" # Voir les ports ouverts
alias netpid="netstat -tlnp" # Voir le port qui écoute avec le PID du process associé
alias appson="netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq" # Voir une liste des noms de process qui utilisent une connection
alias rscp='rsync -aP --no-whole-file --inplace' # rsync cp // a(garder permissions) P(progress bar)
alias rsmv='rscp --remove-source-files' # rsync mv avec progressbar
alias install='sudo apt-get install'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get -u upgrade'
alias remove='sudo apt-get --purge remove'
alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias calc='python -ic "from math import *; from random import *"' # Une calculatrice en python
alias servethis="python -m SimpleHTTPServer 8000" # Serveur python sur le port 8000
if type -P htop >/dev/null; then
alias top='htop' # toujours utiliser htop si installé
fi
alias reload_bash="source ~/.bashrc" # recharger le ~/.bashrc
alias ncmpc='ncmpc -c' # Ncurse mpc en couleur
alias psp='ps u -C' # ps sur un seul process
bind '"\C-l"':"\"clear\r\"" # Ctrl+l vide le terminal
############################################################################################################################################################
# COULEURS
############################################################################################################################################################
txtblk='\e[0;30m' # Noir
txtred='\e[0;31m' # Rouge
txtgrn='\e[0;32m' # Vert
txtylw='\e[0;33m' # Jaune
txtblu='\e[0;34m' # Bleu
txtpur='\e[0;35m' # Violet
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # Blanc
bldblk='\e[1;30m' # Noir - Bold
bldred='\e[1;31m' # Rouge
bldgrn='\e[1;32m' # Vert
bldylw='\e[1;33m' # Jaune
bldblu='\e[1;34m' # Bleu
bldpur='\e[1;35m' # Violet
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # Blanc
unkblk='\e[4;30m' # Noir - Underline
undred='\e[4;31m' # Rouge
undgrn='\e[4;32m' # Vert
undylw='\e[4;33m' # Jaune
undblu='\e[4;34m' # Bleu
undpur='\e[4;35m' # Violet
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # Blanc
bakblk='\e[40m' # Noir - Background
bakred='\e[41m' # Rouge
badgrn='\e[42m' # Vert
bakylw='\e[43m' # Jaune
bakblu='\e[44m' # Bleu
bakpur='\e[45m' # Violet
bakcyn='\e[46m' # Cyan
bakwht='\e[47m' # Blanc
txtrst='\e[0m' # Text Reset
txtbluj="\[\e[01;34m\]" # Bleu prompt
txtarobasc="\[\e[05;33m\]" # Orange clignote prompt
txtarobas="\[\e[02;33m\]" # Orange prompt
txtvertj="\[\e[01;32m\]" # Vert fluo prompt
txtjaunj="\[\e[01;33m\]" # Jaune prompt
txtbleucj="\[\033[1;36m\]" # Bleu clair prompt
txtheure="\[\e[02;36m\]" # turquoise, heure prompt
txtgrisj="\[\e[30;1m\]" # gris prompt
############################################################################################################################################################
# ALIAS POUR LES BOOKMARKS EN BASH
############################################################################################################################################################
# show pour voir la liste des bookmarks existants // save foo sauvergarde le dossier courant dans le bookmark foo // cd foo pour y revenir
############################################################################################################################################################
if [ ! -f ~/.dirs ]; then # si ~/.dirs n'existe pas, le créer
touch ~/.dirs
fi
alias show='cat -n ~/.dirs | sed "s/^\([^.]*\)\=\(.*\)/-\1 --> \2/g"'
save (){ command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;}
source ~/.dirs # Initialisation de la fonction 'save': source le fichier .sdirs
############################################################################################################################################################
# VARIABLES
############################################################################################################################################################
# Historique
export HISTSIZE=10000 # taille de l'historique
export HISTFILESIZE=${HISTSIZE}
export HISTIGNORE="ls:cd:[bf]g:exit" # ignorer les lignes w/ ls, cd, ...
export HISTCONTROL="ignoreboth" # ignorer les doublons et les commandes qui commencent par un espace
# Specifique a vim
export EDITOR=vim
export VISUAL=vim
if type -P vim >/dev/null; then
alias vi=vim # toujours utiliser vim au lieu de vi si installe
fi
# Taper 2 fois Ctrl+D pour quitter le shell
export IGNOREEOF=1
# Font ancienne apps
export QT_XFT=true
export GDK_USE_XFT=1
# meilleur que less ou more pour man
export PAGER=most
# Python doc
export PYTHONDOCS=/usr/share/doc/python/html/
# $PATH (cope en 1er pour couleur de certaines commandes)
# http://github.com/cytzol/cope
# MODIFIER LE CHEMIN DE COPE
export PATH=/usr/share/perl5/vendor_perl/auto/share/dist/Cope:$PATH:/usr/local/bin/
export PATH="/opt/android-sdk/tools/:$PATH" # sdk-android
export PATH="/tmp/yaourt-tmp-jlaunay/aur-komodoedit-beta/pkg/opt/komodoedit-beta/bin:$PATH" # komodoedit
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='\[\e[0;32m\]┌┼───┤\[\e[0;36m\] \u@\h \[\e[0;32m\]├───────────────────────────────────────────────────────┤\[\e[0;33m\]\w\[\e[0;32m\]├────\n└┼─\[\e[1;33m\]$\[\e[0;32m\]─┤▶ \[\e[0;37m\]'
else
PS1='┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ '
fi
unset color_prompt force_color_prompt
# Affiche [95%] de batterie avec apm
# PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ "
# Ajouter de la couleur a ces comamndes si grc installé
# http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
if which grc &>/dev/null; then
alias .cl='grc -es --colour=auto'
alias configure='.cl ./configure'
alias diff='.cl diff'
alias make='.cl make'
alias gcc='.cl gcc'
alias g++='.cl g++'
alias ld='.cl ld'
alias netstat='.cl netstat'
alias ping='.cl ping -c 10'
alias traceroute='.cl traceroute'
fi
############################################################################################################################################################
# FONCTIONS
############################################################################################################################################################
# myip - Obtenir IP publique
# usage: myip
myip(){ wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//';}
# Créer une archive pour un repertoire donne.
mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; }
mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }
# ex - Extraire une archive
# usage: ex <fichier>
ex ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjvf $1 ;;
*.tar.gz) tar xzvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xjvf $1 ;;
*.tgz) tar xzvf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1;;
*.7z) 7z x $1 ;;
*) echo -e "${bldred}'$1' ne peut pas etre decompresse avec ex()" ;;
esac
else
echo -e "\n${bldred}'$1' n'est pas un fichier valide"
fi
}
# clock - Affiche une horloge simple
# usage: clock
clock() { while true;do clear;echo -e "\e[30;1m===========\e[0m\e[01;33m";date +"%r";echo -e "\e[0m\e[30;1m===========\e[0m";sleep 1;done; }
# definef - Definition francaise d'un mot a l'aide de google
# usage: definef <mot>
definef(){ local y="$@";curl -sA"Opera" "http://www.google.fr/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
# define - Definition Anglaise d'un mot a l'aide de google
# usage: definef <word>
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;}
# resetperm - restaurer les permissions des repertoires et fichiers avec leurs valeurs "normales" (644/755)
# usage: resetperm <dossier>
resetperm()
{
chmod -R u=rwX,go=rX "$@"
chown -R ${USER}:users "$@"
}
# XXX - mise en forme des permissions symbolic en octal (644)
# usage : ls -l | XXX
XXX() { sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g' ; }
# Convertir l'encodage d'un fichier iso2utf8/utf82iso
# usage : changeEncoding <fichier>
changeEncoding()
{
if [ -f "$1" ] ; then
case "`file -bi "$1"`" in
*iso-8859-1) iconv --from-code=ISO-8859-1 --to-code=UTF-8 "$1" > "$1".utf-8 && echo -e "\n${bldgrn}Nouveau fichier : "$1".utf-8" ;;
*utf-8) iconv --from-code=UTF-8 --to-code=ISO-8859-1 "$1" > "$1".iso-8859-1 && echo -e "\n${bldgrn}Nouveau fichier : "$1".iso-8859-1" ;;
*us-ascii) echo -e "\n${bldylw}Encodage US-ASCII pas besoin de convertir" ;;
*) echo -e "\n${bldred}L'encodage de '$1' ne peut pas etre converti avec changeEncoding(`file -bi "$1"`)" ;;
esac
else
echo -e "\n${bldred}'$1' n'est pas un fichier valide"
fi
}
# Afficher une quote depuis danstonchat.com
# usage: dtc
dtc()
{
url=http://danstonchat.com/random.html?toto=`date +%N`
lynx --dump --display_charset=utf8 $url 2>&1 \
| awk '$1~"#" && $0!~"RSS" { getline; while ($1!~"#") { print $0; getline;}; exit}'
}
# télecharger un site complet avec Wget
# Les pages seront mise en html (E), les liens seront transformés (k) et c'est récursif (r) sur 5 niveaux maxi (l5)
# Usage wdl <URL>
# tip : utiliser servethis pour servir les pages télechargées
wdl(){ wget -r -l5 -k -E ${1} && cd $_;}
# Prendre une capture d'écran
# Usage: screenshot [delai en sc] [qualite]
screenshot() {
if ! which scrot &>/dev/null; then
echo "${FUNCNAME[0]}(): Vous devez d'abord installer 'scrot'."
return 1
fi
local delay=1
local quality=95
[ "$1" ] && delay="$1"
[ "$2" ] && quality="$2"
scrot -q $quality -d $delay "$HOME/screenshot_`date +'%F_%Hh%M'`.jpg"
}
# Transforme une image (depuis une URL) en ascci html
# servethis pour voir sur le port 8000 ou mongoose http://code.google.com/p/mongoose/
# usage : toascii <URL>
toascii() { convert $1 jpg:- | jp2a - --color --fill --background=light --html > $HOME/ascii_`date +'%F_%Hh%M'`.html;}
# Construire une galerie html avec toutes les photo d'un dossier
# usage : galerie
galerie()
{
echo -e "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1- \
transitional.dtd\">\n<HTML>\n<head>\n<title>Gallerie photo du `date +'%F_%Hh%M'`</title>\n\n<style type=\"text/css\">\nhtml \
, body {\n\tmargin: 0px;\n\tpadding: 0px;\n\tborder: 0px;\n}\n#main {\n\tmargin: 5px 20px;\n}\ndiv.left {\n\tfloat: left;\n\tmargin \
-right: 300px;\n\twidth: 400px;\n\tmargin-bottom: 10px;\n}\ndiv.left p {\n\ttext-align: center;\n}\nimg {\n\tborder: 0px none;\n}\ndiv. \
center {\n\twidth: 600px;\n}\n.clear {\n clear : both;\n}\n</style>\n</head>\n\n<body>\n<div id=\"main\">\n <h1>Gallerie photo du \
`date +'%F_%Hh%M'`</h1>\n" > gallerie_`date +'%F'`.html;
for i in *.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF};
do echo -e "\t<div class="left">\n\t\t<a href='$i'><img src='$i' width="300" height="300" border="0" /></a><br />\n\t\t<p>$i</p>\n\t</div>\n";
done >> gallerie_`date +'%F'`.html
echo -e "</div>\n</body>\n</html>" >> gallerie_`date +'%F'`.html
echo -e "\n${bldgrn}La gallerie gallerie_`date +'%F'`.html contient les photos du dossier `pwd`."
}
# chext - modifier l'extension
# usage : chext new_ext *.old_ext
function chext(){
local fname
local new_ext="$1"
shift
IFS=$'\n'
for fname in $@
do
mv "$fname" "${fname%.*}.$new_ext"
done
}
# cbt - Count by Type - affiche le nombre de fichiers par type
# usage : cbt
cbt() { find ${*-.} -type f -print0 | xargs -0 file | awk -F, '{print $1}' | awk '{$1=NULL;print $0}' | sort | uniq -c | sort -nr ;}
# Renomme en minuscules
# usage tolowercase <*.txt>
toLowercase() { for i in "$@"; do mv -f "$i" "`echo $i| tr [A-Z] [a-z]`" &>/dev/null; done }
# Renomme en majuscules
# usage toupercase <*.txt>
toUpercase() { for i in "$@"; do mv -f "$i" "`echo $i| tr [a-z] [A-Z]`" &>/dev/null; done }
# remplacer les espaces par des _
# usage underscorespace <*.txt>
underscorespace() { for i in "$@"; do mv "$i" "`echo $i| tr ' ' '_'`" &>/dev/null; done }
# tempsrep - temps de réponse pour un URL
# usage : tempsrep <URL> (TTFB:time to first bit)
tempsrep() { curl -o /dev/null -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" $1; }
# getserver - Determine le serveur utilisé par un site
# usage : getserver <URL>
getserver() { curl -I $1 2>&1 | grep Server;}
# start, stop, restart, reload - Controler les services
# usage: start nom_du_daemon
start() { for arg in $*; do sudo /etc/init.d/$arg start; done }
stop() { for arg in $*; do sudo /etc/init.d/$arg stop; done }
restart() { for arg in $*; do sudo /etc/init.d/$arg restart; done }
reload() { for arg in $*; do sudo /etc/init.d/$arg reload; done }
# Affiche une liste des fonctions comme alias le fait pour les alias
fonctions()
{
echo -e "\n${txtpur}FONCTIONS
----------------------------------------------------------------------${txtrst}"
echo -e "${txtcyn}myip : ${txtrst}affiche l'adresse ip"
echo -e "${txtcyn}mktar() <dossier> :${txtrst} creer une archive tar du dossier"
echo -e "${txtcyn}mktgz() <dossier> :${txtrst} creer une archive tar.gz du dossier"
echo -e "${txtcyn}mktbz() <dossier> :${txtrst} creer une archive tar.bz2 du dossier"
echo -e "${txtcyn}ex <fichier> :${txtrst} extraire un fichier"
echo -e "${txtcyn}clock :${txtrst} Affiche une horloge simple"
echo -e "${txtcyn}definef <mot> :${txtrst} Definition francaise d'un mot a l'aide de google"
echo -e "${txtcyn}define <word> :${txtrst} Definition anglaise d'un mot a l'aide de google"
echo -e "${txtcyn}resetperm <dossier> :${txtrst} restaurer les permissions des repertoires et fichiers avec leurs valeurs normales (644/755)"
echo -e "${txtcyn}ls -l | XXX :${txtrst} XXX - mise en forme des permissions symbolic en octal (644)"
echo -e "${txtcyn}changeEncoding <fichier>:${txtrst} Convertir l'encodage d'un fichier iso2utf8/utf82iso"
echo -e "${txtcyn}dtc :${txtrst} affiche une quote depuis danstonchat.com"
echo -e "${txtcyn}wdl <URL> :${txtrst} telecharger un site complet avec Wget"
echo -e "${txtcyn}toascii <URL> :${txtrst} Transforme une image (depuis une URL) en ascci html"
echo -e "${txtcyn}screenshot [delai en sc] [qualite] :${txtrst} prendre une capture d'ecran"
echo -e "${txtcyn}toascii <URL> :${txtrst} tranforme une image en ascii html"
echo -e "${txtcyn}gallerie :${txtrst} Construire une gallerie html avec toutes les photo d'un dossier"
echo -e "${txtcyn}chext new_ext *.old_ext :${txtrst} modifier l'extension"
echo -e "${txtcyn}cbt (Count by Type) :${txtrst} affiche le nombre de fichiers par type"
echo -e "${txtcyn}toLowercase <*.txt> :${txtrst} renommer en minuscules"
echo -e "${txtcyn}toUpercase <*.txt> :${txtrst} renommer en majuscules"
echo -e "${txtcyn}underscorespace <*.txt>:${txtrst} remplacer les espaces par des _"
echo -e "${txtcyn}tempsrep <URL> :${txtrst} temps de reponse pour un URL"
echo -e "${txtcyn}getserver <URL> :${txtrst} Determine le serveur utilise par un site"
echo -e "${txtcyn}start() stop() restart() reload() <daemon> :${txtrst} Controler les services"
}
function bashtips {
echo -e "
${txtpur}REPERTOIRES
----------------------------------------------------------------------${txtrst}
${txtcyn}~- ${txtrst}repertoire precedent
${txtcyn}pushd tmp ${txtrst}Push tmp && cd tmp
${txtcyn}popd ${txtrst}Pop && cd
${txtcyn}save foo ${txtrst}bookmark le dossier courant dans foo
${txtcyn}show ${txtrst}voir une liste des bookmarks
${txtpur}HISTORIQUE
----------------------------------------------------------------------${txtrst}
${txtcyn}!! ${txtrst}Derniere commande
${txtcyn}!!:p ${txtrst}Apercu sans execution de la derniere commande
${txtcyn}!?foo ${txtrst}Derniere commande contenant \`foo'
${txtcyn}^foo^bar^ ${txtrst}Derniere commande contenant \`foo', mais substitue avec \`bar'
${txtcyn}!!:0 ${txtrst}Derniere commande mot
${txtcyn}!!:^ ${txtrst}1er argument de la derniere commande
${txtcyn}!\$ ${txtrst}Dernier argument de la derniere commande
${txtcyn}!!:* ${txtrst}Tout les arguments de la derniere commande
${txtcyn}!!:x-y ${txtrst}Arguments x a y de la derniere commande
${txtcyn}[Ctrl]-s ${txtrst}Rechercher en avant dans l'historique
${txtcyn}[Ctrl]-r ${txtrst}Rechercher en arriere dans l'historique
${txtpur}EDITION DE LIGNE
----------------------------------------------------------------------${txtrst}
${txtcyn}[Ctrl]-a ${txtrst}aller au debut de la ligne
${txtcyn}[Ctrl]-e ${txtrst}aller a la fin de la ligne
${txtcyn}[ Alt]-d ${txtrst}efface jusqu'a la fin d'un mot
${txtcyn}[Ctrl]-w ${txtrst}efface jusqu'au debut d'un mot
${txtcyn}[Ctrl]-k ${txtrst}efface jusqu'a la fin de la ligne
${txtcyn}[Ctrl]-u ${txtrst}efface jusqu'au debut de la ligne
${txtcyn}[Ctrl]-y ${txtrst}coller le contenu du buffer
${txtcyn}[Ctrl]-r ${txtrst}revert all modifications to current line
${txtcyn}[Ctrl]-] ${txtrst}chercher en avant dans la ligne
${txtcyn}[ Alt]-
${txtcyn}[Ctrl]-] ${txtrst}chercher en arriere dans la ligne
${txtcyn}[Ctrl]-t ${txtrst}switch lettre
${txtcyn}[ Alt]-t ${txtrst}switch mot
${txtcyn}[ Alt]-u ${txtrst}mot en Majuscule
${txtcyn}[ Alt]-l ${txtrst}Mot en Minuscule
${txtcyn}[ Alt]-c ${txtrst}1ere lettre du mot en Majuscule
${txtpur}COMPLETION
----------------------------------------------------------------------${txtrst}
${txtcyn}[ Alt]. ${txtrst}faire defiler les arguments de la derniere commande
${txtcyn}[ Alt]-/ ${txtrst}completer le nom de fichier
${txtcyn}[ Alt]-~ ${txtrst}completer le nom d'utilisateur
${txtcyn}[ Alt]-@ ${txtrst}completer le nom d'host
${txtcyn}[ Alt]-\$ ${txtrst}completer le nom de variable
${txtcyn}[ Alt]-! ${txtrst}completer le nom d'une commande
${txtcyn}[ Alt]-^ ${txtrst}completer l'historique"
}
# Auto Completion dans le style Ncurse avec la touche [TAB]
function kingbash.fn() {
echo -n "KingBash> $READLINE_LINE"
OUTPUT=`/usr/bin/kingbash "$(compgen -ab -A function)"`
READLINE_POINT=`echo "$OUTPUT" | tail -n 1`
READLINE_LINE=`echo "$OUTPUT" | head -n -1`
echo -ne "\r\e[2K"; }
bind -x '"\t":kingbash.fn'
# Historique pour KingBash avec la touche [Ctrl]+r
function kingbash.hs() {
echo -n "KingBash> $READLINE_LINE"
history -a
OUTPUT=`/usr/bin/kingbash -r <(tac ~/.bash_history)`
READLINE_POINT=`echo "$OUTPUT" | tail -n 1`
READLINE_LINE=`echo "$OUTPUT" | head -n -1`
echo -ne "\r\e[2K"; }
bind -x '"\x12":kingbash.hs'I found the base here : http://www.bordel-de-nerd.net/2010/08/c … omment-827
and I modified some little thing for my needs. There is many stuff and I found it quiet good for starting biuld one. Voila!
Offline
Here's mine :
############################################################################################################################################################ # AUTO-COMPLETION ############################################################################################################################################################ # Active la completion automatique if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi # tab completion pour les hosts ssh if [ -f ~/.ssh/known_hosts ]; then SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \ cut -f 1 -d ' ' | \ sed -e s/,.*//g | \ uniq | \ egrep -v [0123456789]) ) complete -o default -W "${SSH_COMPLETE[*]}" ssh fi # Completion avec sudo complete -cf sudo ############################################################################################################################################################ # SHOPTS ############################################################################################################################################################ shopt -s cdspell # Pour que bash corrige automatiquement les fautes de frappes ex: cd ~/fiml sera remplacé par cd ~/film shopt -s checkwinsize # Pour que bash vérifie la taille de la fenêtre après chaque commande shopt -s cmdhist # Pour que bash sauve dans l'historique les commandes qui prennent plusieurs lignes sur une seule ligne. shopt -s dotglob # Pour que bash montre les fichiers qui commencent par un . shopt -s expand_aliases # # Pour que bash montre la commande complete au lieu de l'alias shopt -s extglob # Pour que bash, interprète les expressions génériques shopt -s histappend # Pour que bash ajoute au lieu d'écraser dans l'histo shopt -s hostcomplete # Pour que bash tente de résoudre le nom pour les ip suivis d'un @ shopt -s nocaseglob # Pour que bash ne soit pas sensible a la casse shopt -s cdable_vars # utilisé pour la fonction bookmarks pour que bash n'ai pas besoin de $ pour sourcer le fichier .dirs ############################################################################################################################################################ # ALIAS ############################################################################################################################################################ alias ls='ls --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls par default (dossier en 1er + mise en forme de l'heure) alias lsfp='ls | sed s#^#$(pwd)/#' # ls avec full PATH alias ll='ls -l --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls détaille alias la='ls -la --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F' # ls aussi les fichiers cachés .* alias lsofnames="lsof | awk '!/^\$/ && /\// { print \$9 }' | sort -u" # noms des fichiers ouverts alias grep='grep --color=tty -d skip' alias cp="cp -i" # Confirmer avant d'écraser un fichier existant alias df='df -h' # Tailles lisibles par l'homme alias free='free -m' # voir la taille en MB alias vp='vim PKGBUILD' # spécifique Arch alias vs='vim SPLITBUILD' # spécifique Arch alias ports="lsof -i -n -P" # Voir les process qui utilisent une connection internet alias estab="ss -p | grep STA" # Voir seulement les sockets établis alias netstat80="netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1" # nombre de connections sur le port 80 du serveur par IP alias openports="netstat -nape --inet" # Voir les ports ouverts alias netpid="netstat -tlnp" # Voir le port qui écoute avec le PID du process associé alias appson="netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq" # Voir une liste des noms de process qui utilisent une connection alias rscp='rsync -aP --no-whole-file --inplace' # rsync cp // a(garder permissions) P(progress bar) alias rsmv='rscp --remove-source-files' # rsync mv avec progressbar alias install='sudo apt-get install' alias update='sudo apt-get update' alias upgrade='sudo apt-get -u upgrade' alias remove='sudo apt-get --purge remove' alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge' alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand' alias calc='python -ic "from math import *; from random import *"' # Une calculatrice en python alias servethis="python -m SimpleHTTPServer 8000" # Serveur python sur le port 8000 if type -P htop >/dev/null; then alias top='htop' # toujours utiliser htop si installé fi alias reload_bash="source ~/.bashrc" # recharger le ~/.bashrc alias ncmpc='ncmpc -c' # Ncurse mpc en couleur alias psp='ps u -C' # ps sur un seul process bind '"\C-l"':"\"clear\r\"" # Ctrl+l vide le terminal ############################################################################################################################################################ # COULEURS ############################################################################################################################################################ txtblk='\e[0;30m' # Noir txtred='\e[0;31m' # Rouge txtgrn='\e[0;32m' # Vert txtylw='\e[0;33m' # Jaune txtblu='\e[0;34m' # Bleu txtpur='\e[0;35m' # Violet txtcyn='\e[0;36m' # Cyan txtwht='\e[0;37m' # Blanc bldblk='\e[1;30m' # Noir - Bold bldred='\e[1;31m' # Rouge bldgrn='\e[1;32m' # Vert bldylw='\e[1;33m' # Jaune bldblu='\e[1;34m' # Bleu bldpur='\e[1;35m' # Violet bldcyn='\e[1;36m' # Cyan bldwht='\e[1;37m' # Blanc unkblk='\e[4;30m' # Noir - Underline undred='\e[4;31m' # Rouge undgrn='\e[4;32m' # Vert undylw='\e[4;33m' # Jaune undblu='\e[4;34m' # Bleu undpur='\e[4;35m' # Violet undcyn='\e[4;36m' # Cyan undwht='\e[4;37m' # Blanc bakblk='\e[40m' # Noir - Background bakred='\e[41m' # Rouge badgrn='\e[42m' # Vert bakylw='\e[43m' # Jaune bakblu='\e[44m' # Bleu bakpur='\e[45m' # Violet bakcyn='\e[46m' # Cyan bakwht='\e[47m' # Blanc txtrst='\e[0m' # Text Reset txtbluj="\[\e[01;34m\]" # Bleu prompt txtarobasc="\[\e[05;33m\]" # Orange clignote prompt txtarobas="\[\e[02;33m\]" # Orange prompt txtvertj="\[\e[01;32m\]" # Vert fluo prompt txtjaunj="\[\e[01;33m\]" # Jaune prompt txtbleucj="\[\033[1;36m\]" # Bleu clair prompt txtheure="\[\e[02;36m\]" # turquoise, heure prompt txtgrisj="\[\e[30;1m\]" # gris prompt ############################################################################################################################################################ # ALIAS POUR LES BOOKMARKS EN BASH ############################################################################################################################################################ # show pour voir la liste des bookmarks existants // save foo sauvergarde le dossier courant dans le bookmark foo // cd foo pour y revenir ############################################################################################################################################################ if [ ! -f ~/.dirs ]; then # si ~/.dirs n'existe pas, le créer touch ~/.dirs fi alias show='cat -n ~/.dirs | sed "s/^\([^.]*\)\=\(.*\)/-\1 --> \2/g"' save (){ command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;} source ~/.dirs # Initialisation de la fonction 'save': source le fichier .sdirs ############################################################################################################################################################ # VARIABLES ############################################################################################################################################################ # Historique export HISTSIZE=10000 # taille de l'historique export HISTFILESIZE=${HISTSIZE} export HISTIGNORE="ls:cd:[bf]g:exit" # ignorer les lignes w/ ls, cd, ... export HISTCONTROL="ignoreboth" # ignorer les doublons et les commandes qui commencent par un espace # Specifique a vim export EDITOR=vim export VISUAL=vim if type -P vim >/dev/null; then alias vi=vim # toujours utiliser vim au lieu de vi si installe fi # Taper 2 fois Ctrl+D pour quitter le shell export IGNOREEOF=1 # Font ancienne apps export QT_XFT=true export GDK_USE_XFT=1 # meilleur que less ou more pour man export PAGER=most # Python doc export PYTHONDOCS=/usr/share/doc/python/html/ # $PATH (cope en 1er pour couleur de certaines commandes) # http://github.com/cytzol/cope # MODIFIER LE CHEMIN DE COPE export PATH=/usr/share/perl5/vendor_perl/auto/share/dist/Cope:$PATH:/usr/local/bin/ export PATH="/opt/android-sdk/tools/:$PATH" # sdk-android export PATH="/tmp/yaourt-tmp-jlaunay/aur-komodoedit-beta/pkg/opt/komodoedit-beta/bin:$PATH" # komodoedit # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='\[\e[0;32m\]┌┼───┤\[\e[0;36m\] \u@\h \[\e[0;32m\]├───────────────────────────────────────────────────────┤\[\e[0;33m\]\w\[\e[0;32m\]├────\n└┼─\[\e[1;33m\]$\[\e[0;32m\]─┤▶ \[\e[0;37m\]' else PS1='┌────[\u@\h]──────────────────────────────────────────────────────[\t]────┐ \n└───>[${PWD}] \$ ' fi unset color_prompt force_color_prompt # Affiche [95%] de batterie avec apm # PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ " # Ajouter de la couleur a ces comamndes si grc installé # http://kassiopeia.juls.savba.sk/~garabik/software/grc.html if which grc &>/dev/null; then alias .cl='grc -es --colour=auto' alias configure='.cl ./configure' alias diff='.cl diff' alias make='.cl make' alias gcc='.cl gcc' alias g++='.cl g++' alias ld='.cl ld' alias netstat='.cl netstat' alias ping='.cl ping -c 10' alias traceroute='.cl traceroute' fi ############################################################################################################################################################ # FONCTIONS ############################################################################################################################################################ # myip - Obtenir IP publique # usage: myip myip(){ wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//';} # Créer une archive pour un repertoire donne. mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; } mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; } # ex - Extraire une archive # usage: ex <fichier> ex () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjvf $1 ;; *.tar.gz) tar xzvf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xvf $1 ;; *.tbz2) tar xjvf $1 ;; *.tgz) tar xzvf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo -e "${bldred}'$1' ne peut pas etre decompresse avec ex()" ;; esac else echo -e "\n${bldred}'$1' n'est pas un fichier valide" fi } # clock - Affiche une horloge simple # usage: clock clock() { while true;do clear;echo -e "\e[30;1m===========\e[0m\e[01;33m";date +"%r";echo -e "\e[0m\e[30;1m===========\e[0m";sleep 1;done; } # definef - Definition francaise d'un mot a l'aide de google # usage: definef <mot> definef(){ local y="$@";curl -sA"Opera" "http://www.google.fr/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;} # define - Definition Anglaise d'un mot a l'aide de google # usage: definef <word> define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Po '(?<=<li>)[^<]+'|nl|perl -MHTML::Entities -pe 'decode_entities($_)' 2>/dev/null;} # resetperm - restaurer les permissions des repertoires et fichiers avec leurs valeurs "normales" (644/755) # usage: resetperm <dossier> resetperm() { chmod -R u=rwX,go=rX "$@" chown -R ${USER}:users "$@" } # XXX - mise en forme des permissions symbolic en octal (644) # usage : ls -l | XXX XXX() { sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g' ; } # Convertir l'encodage d'un fichier iso2utf8/utf82iso # usage : changeEncoding <fichier> changeEncoding() { if [ -f "$1" ] ; then case "`file -bi "$1"`" in *iso-8859-1) iconv --from-code=ISO-8859-1 --to-code=UTF-8 "$1" > "$1".utf-8 && echo -e "\n${bldgrn}Nouveau fichier : "$1".utf-8" ;; *utf-8) iconv --from-code=UTF-8 --to-code=ISO-8859-1 "$1" > "$1".iso-8859-1 && echo -e "\n${bldgrn}Nouveau fichier : "$1".iso-8859-1" ;; *us-ascii) echo -e "\n${bldylw}Encodage US-ASCII pas besoin de convertir" ;; *) echo -e "\n${bldred}L'encodage de '$1' ne peut pas etre converti avec changeEncoding(`file -bi "$1"`)" ;; esac else echo -e "\n${bldred}'$1' n'est pas un fichier valide" fi } # Afficher une quote depuis danstonchat.com # usage: dtc dtc() { url=http://danstonchat.com/random.html?toto=`date +%N` lynx --dump --display_charset=utf8 $url 2>&1 \ | awk '$1~"#" && $0!~"RSS" { getline; while ($1!~"#") { print $0; getline;}; exit}' } # télecharger un site complet avec Wget # Les pages seront mise en html (E), les liens seront transformés (k) et c'est récursif (r) sur 5 niveaux maxi (l5) # Usage wdl <URL> # tip : utiliser servethis pour servir les pages télechargées wdl(){ wget -r -l5 -k -E ${1} && cd $_;} # Prendre une capture d'écran # Usage: screenshot [delai en sc] [qualite] screenshot() { if ! which scrot &>/dev/null; then echo "${FUNCNAME[0]}(): Vous devez d'abord installer 'scrot'." return 1 fi local delay=1 local quality=95 [ "$1" ] && delay="$1" [ "$2" ] && quality="$2" scrot -q $quality -d $delay "$HOME/screenshot_`date +'%F_%Hh%M'`.jpg" } # Transforme une image (depuis une URL) en ascci html # servethis pour voir sur le port 8000 ou mongoose http://code.google.com/p/mongoose/ # usage : toascii <URL> toascii() { convert $1 jpg:- | jp2a - --color --fill --background=light --html > $HOME/ascii_`date +'%F_%Hh%M'`.html;} # Construire une galerie html avec toutes les photo d'un dossier # usage : galerie galerie() { echo -e "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1- \ transitional.dtd\">\n<HTML>\n<head>\n<title>Gallerie photo du `date +'%F_%Hh%M'`</title>\n\n<style type=\"text/css\">\nhtml \ , body {\n\tmargin: 0px;\n\tpadding: 0px;\n\tborder: 0px;\n}\n#main {\n\tmargin: 5px 20px;\n}\ndiv.left {\n\tfloat: left;\n\tmargin \ -right: 300px;\n\twidth: 400px;\n\tmargin-bottom: 10px;\n}\ndiv.left p {\n\ttext-align: center;\n}\nimg {\n\tborder: 0px none;\n}\ndiv. \ center {\n\twidth: 600px;\n}\n.clear {\n clear : both;\n}\n</style>\n</head>\n\n<body>\n<div id=\"main\">\n <h1>Gallerie photo du \ `date +'%F_%Hh%M'`</h1>\n" > gallerie_`date +'%F'`.html; for i in *.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}; do echo -e "\t<div class="left">\n\t\t<a href='$i'><img src='$i' width="300" height="300" border="0" /></a><br />\n\t\t<p>$i</p>\n\t</div>\n"; done >> gallerie_`date +'%F'`.html echo -e "</div>\n</body>\n</html>" >> gallerie_`date +'%F'`.html echo -e "\n${bldgrn}La gallerie gallerie_`date +'%F'`.html contient les photos du dossier `pwd`." } # chext - modifier l'extension # usage : chext new_ext *.old_ext function chext(){ local fname local new_ext="$1" shift IFS=$'\n' for fname in $@ do mv "$fname" "${fname%.*}.$new_ext" done } # cbt - Count by Type - affiche le nombre de fichiers par type # usage : cbt cbt() { find ${*-.} -type f -print0 | xargs -0 file | awk -F, '{print $1}' | awk '{$1=NULL;print $0}' | sort | uniq -c | sort -nr ;} # Renomme en minuscules # usage tolowercase <*.txt> toLowercase() { for i in "$@"; do mv -f "$i" "`echo $i| tr [A-Z] [a-z]`" &>/dev/null; done } # Renomme en majuscules # usage toupercase <*.txt> toUpercase() { for i in "$@"; do mv -f "$i" "`echo $i| tr [a-z] [A-Z]`" &>/dev/null; done } # remplacer les espaces par des _ # usage underscorespace <*.txt> underscorespace() { for i in "$@"; do mv "$i" "`echo $i| tr ' ' '_'`" &>/dev/null; done } # tempsrep - temps de réponse pour un URL # usage : tempsrep <URL> (TTFB:time to first bit) tempsrep() { curl -o /dev/null -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" $1; } # getserver - Determine le serveur utilisé par un site # usage : getserver <URL> getserver() { curl -I $1 2>&1 | grep Server;} # start, stop, restart, reload - Controler les services # usage: start nom_du_daemon start() { for arg in $*; do sudo /etc/init.d/$arg start; done } stop() { for arg in $*; do sudo /etc/init.d/$arg stop; done } restart() { for arg in $*; do sudo /etc/init.d/$arg restart; done } reload() { for arg in $*; do sudo /etc/init.d/$arg reload; done } # Affiche une liste des fonctions comme alias le fait pour les alias fonctions() { echo -e "\n${txtpur}FONCTIONS ----------------------------------------------------------------------${txtrst}" echo -e "${txtcyn}myip : ${txtrst}affiche l'adresse ip" echo -e "${txtcyn}mktar() <dossier> :${txtrst} creer une archive tar du dossier" echo -e "${txtcyn}mktgz() <dossier> :${txtrst} creer une archive tar.gz du dossier" echo -e "${txtcyn}mktbz() <dossier> :${txtrst} creer une archive tar.bz2 du dossier" echo -e "${txtcyn}ex <fichier> :${txtrst} extraire un fichier" echo -e "${txtcyn}clock :${txtrst} Affiche une horloge simple" echo -e "${txtcyn}definef <mot> :${txtrst} Definition francaise d'un mot a l'aide de google" echo -e "${txtcyn}define <word> :${txtrst} Definition anglaise d'un mot a l'aide de google" echo -e "${txtcyn}resetperm <dossier> :${txtrst} restaurer les permissions des repertoires et fichiers avec leurs valeurs normales (644/755)" echo -e "${txtcyn}ls -l | XXX :${txtrst} XXX - mise en forme des permissions symbolic en octal (644)" echo -e "${txtcyn}changeEncoding <fichier>:${txtrst} Convertir l'encodage d'un fichier iso2utf8/utf82iso" echo -e "${txtcyn}dtc :${txtrst} affiche une quote depuis danstonchat.com" echo -e "${txtcyn}wdl <URL> :${txtrst} telecharger un site complet avec Wget" echo -e "${txtcyn}toascii <URL> :${txtrst} Transforme une image (depuis une URL) en ascci html" echo -e "${txtcyn}screenshot [delai en sc] [qualite] :${txtrst} prendre une capture d'ecran" echo -e "${txtcyn}toascii <URL> :${txtrst} tranforme une image en ascii html" echo -e "${txtcyn}gallerie :${txtrst} Construire une gallerie html avec toutes les photo d'un dossier" echo -e "${txtcyn}chext new_ext *.old_ext :${txtrst} modifier l'extension" echo -e "${txtcyn}cbt (Count by Type) :${txtrst} affiche le nombre de fichiers par type" echo -e "${txtcyn}toLowercase <*.txt> :${txtrst} renommer en minuscules" echo -e "${txtcyn}toUpercase <*.txt> :${txtrst} renommer en majuscules" echo -e "${txtcyn}underscorespace <*.txt>:${txtrst} remplacer les espaces par des _" echo -e "${txtcyn}tempsrep <URL> :${txtrst} temps de reponse pour un URL" echo -e "${txtcyn}getserver <URL> :${txtrst} Determine le serveur utilise par un site" echo -e "${txtcyn}start() stop() restart() reload() <daemon> :${txtrst} Controler les services" } function bashtips { echo -e " ${txtpur}REPERTOIRES ----------------------------------------------------------------------${txtrst} ${txtcyn}~- ${txtrst}repertoire precedent ${txtcyn}pushd tmp ${txtrst}Push tmp && cd tmp ${txtcyn}popd ${txtrst}Pop && cd ${txtcyn}save foo ${txtrst}bookmark le dossier courant dans foo ${txtcyn}show ${txtrst}voir une liste des bookmarks ${txtpur}HISTORIQUE ----------------------------------------------------------------------${txtrst} ${txtcyn}!! ${txtrst}Derniere commande ${txtcyn}!!:p ${txtrst}Apercu sans execution de la derniere commande ${txtcyn}!?foo ${txtrst}Derniere commande contenant \`foo' ${txtcyn}^foo^bar^ ${txtrst}Derniere commande contenant \`foo', mais substitue avec \`bar' ${txtcyn}!!:0 ${txtrst}Derniere commande mot ${txtcyn}!!:^ ${txtrst}1er argument de la derniere commande ${txtcyn}!\$ ${txtrst}Dernier argument de la derniere commande ${txtcyn}!!:* ${txtrst}Tout les arguments de la derniere commande ${txtcyn}!!:x-y ${txtrst}Arguments x a y de la derniere commande ${txtcyn}[Ctrl]-s ${txtrst}Rechercher en avant dans l'historique ${txtcyn}[Ctrl]-r ${txtrst}Rechercher en arriere dans l'historique ${txtpur}EDITION DE LIGNE ----------------------------------------------------------------------${txtrst} ${txtcyn}[Ctrl]-a ${txtrst}aller au debut de la ligne ${txtcyn}[Ctrl]-e ${txtrst}aller a la fin de la ligne ${txtcyn}[ Alt]-d ${txtrst}efface jusqu'a la fin d'un mot ${txtcyn}[Ctrl]-w ${txtrst}efface jusqu'au debut d'un mot ${txtcyn}[Ctrl]-k ${txtrst}efface jusqu'a la fin de la ligne ${txtcyn}[Ctrl]-u ${txtrst}efface jusqu'au debut de la ligne ${txtcyn}[Ctrl]-y ${txtrst}coller le contenu du buffer ${txtcyn}[Ctrl]-r ${txtrst}revert all modifications to current line ${txtcyn}[Ctrl]-] ${txtrst}chercher en avant dans la ligne ${txtcyn}[ Alt]- ${txtcyn}[Ctrl]-] ${txtrst}chercher en arriere dans la ligne ${txtcyn}[Ctrl]-t ${txtrst}switch lettre ${txtcyn}[ Alt]-t ${txtrst}switch mot ${txtcyn}[ Alt]-u ${txtrst}mot en Majuscule ${txtcyn}[ Alt]-l ${txtrst}Mot en Minuscule ${txtcyn}[ Alt]-c ${txtrst}1ere lettre du mot en Majuscule ${txtpur}COMPLETION ----------------------------------------------------------------------${txtrst} ${txtcyn}[ Alt]. ${txtrst}faire defiler les arguments de la derniere commande ${txtcyn}[ Alt]-/ ${txtrst}completer le nom de fichier ${txtcyn}[ Alt]-~ ${txtrst}completer le nom d'utilisateur ${txtcyn}[ Alt]-@ ${txtrst}completer le nom d'host ${txtcyn}[ Alt]-\$ ${txtrst}completer le nom de variable ${txtcyn}[ Alt]-! ${txtrst}completer le nom d'une commande ${txtcyn}[ Alt]-^ ${txtrst}completer l'historique" } # Auto Completion dans le style Ncurse avec la touche [TAB] function kingbash.fn() { echo -n "KingBash> $READLINE_LINE" OUTPUT=`/usr/bin/kingbash "$(compgen -ab -A function)"` READLINE_POINT=`echo "$OUTPUT" | tail -n 1` READLINE_LINE=`echo "$OUTPUT" | head -n -1` echo -ne "\r\e[2K"; } bind -x '"\t":kingbash.fn' # Historique pour KingBash avec la touche [Ctrl]+r function kingbash.hs() { echo -n "KingBash> $READLINE_LINE" history -a OUTPUT=`/usr/bin/kingbash -r <(tac ~/.bash_history)` READLINE_POINT=`echo "$OUTPUT" | tail -n 1` READLINE_LINE=`echo "$OUTPUT" | head -n -1` echo -ne "\r\e[2K"; } bind -x '"\x12":kingbash.hs'I found the base here : http://www.bordel-de-nerd.net/2010/08/c … omment-827
and I modified some little thing for my needs. There is many stuff and I found it quiet good for starting biuld one. Voila!
This .bashrc is mine and if someone need I can translate the comments into English (just ask).
Here 2 extra functions you could find interesting :
# usage findXXX <path>
findXXX() { find "$1" -maxdepth 1 -printf '%.5m %10M %#9u:%-9g %#5U:%-5G [%AD | %TD | %CD] [%Y] %p\n' ; }# ompload a file from command line
# usage ompload <file>
ompload() { curl -# -F file1=@"$1" [url]http://omploader.org/upload|awk[/url] '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}and as this is the only thing removed from my original .bashrc here is my prompt
# COLORS
txtrst='\e[0m' # Text Reset
txtbluj="\[\e[01;34m\]" # Bleu prompt
txtarobasc="\[\e[05;33m\]" # Orange clignote prompt
txtarobas="\[\e[02;33m\]" # Orange prompt
txtvertj="\[\e[01;32m\]" # Vert fluo prompt
txtjaunj="\[\e[01;33m\]" # Jaune prompt
txtbleucj="\[\033[1;36m\]" # Bleu clair prompt
txtheure="\[\e[02;36m\]" # turquoise, heure prompt
txtgrisj="\[\e[30;1m\]" # gris prompt
# PROMPT (modify $PS1)
# USER@HOST:PATH (nb files size Mb) [HH:mm:ss] #N°Command
# (nb jobs)-(screen num) :-)
function truncate_pwd # replace pwd with {...} if > 1/3 of the terminal
{
newPWD="${PWD/#$HOME/~}"
local pwdmaxlen=$((${COLUMNS:-20}/3))
if [ ${#newPWD} -gt $pwdmaxlen ]
then
newPWD=" {...} ${newPWD: -$pwdmaxlen}"
fi
}
PROMPT_COMMAND=truncate_pwd # Run by bash just before each command
ROOT_UID=0 # Root is $UID 0.
# check if we are inside a screen
if [ -n "${STY#*.}" ]; then
export PS1="\n${txtbluj}\u${txtrst}${txtarobasc}@${txtrst}${txtvertj}\h${txtrst}:${txtjaunj}\w ${txtrst}(${txtbleucj}$(ls -1 | wc -l | sed 's: ::g') fichiers ${txtjaunj}$(ls -lah | grep -m 1 total | sed 's/total //')b${txtrst}) ${txtrst}${txtbleucj}[\t]${txtgrisj} #\#\n${txtgrisj}(jobs:${txtbluj}\j${txtgrisj}) - (screen:${txtbluj}$WINDOW${txtgrisj})\`if [ \$? -eq 0 ]; then echo '${txtvertj} :-)'; else echo '${bldred} :-(' ; fi\`${txtrst}\n$"
else
if [ "$UID" -eq "$ROOT_UID" ] # if user root the @ flash,
then
export PS1="\n${txtbluj}\u${txtrst}${txtarobasc}@${txtrst}${txtvertj}\h${txtrst}:${txtjaunj}\w ${txtrst}(${txtbleucj}$(ls -1 | wc -l | sed 's: ::g') fichiers ${txtjaunj}$(ls -lah | grep -m 1 total | sed 's/total //')b${txtrst}) ${txtrst}${txtbleucj}[\t]${txtgrisj} #\#\n${txtgrisj}(jobs:${txtbluj}\j${txtgrisj})\`if [ \$? = "0" ]; then echo '${txtvertj} :-)'; else echo '${bldred} :-(' ; fi\`${txtrst}\n$"
else
export PS1="\n${txtbluj}\u${txtrst}${txtarobas}@${txtrst}${txtvertj}\h${txtrst}:${txtjaunj}\w ${txtrst}(${txtbleucj}$(ls -1 | wc -l | sed 's: ::g') fichiers ${txtjaunj}$(ls -lah | grep -m 1 total | sed 's/total //')b${txtrst}) ${txtrst}${txtbleucj}[\t]${txtgrisj} #\#\n${txtgrisj}(jobs:${txtbluj}\j${txtgrisj})\`if [ \$? = "0" ]; then echo '${txtvertj} :-)'; else echo '${bldred} :-(' ; fi\`${txtrst}\n$"
fi
fi
export PS2="continu-> " # for longer commands, replace >
# show [95%] battery usage with apm
# PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ "Offline
@ JLaunay: thanks for sharing, appreciate the job.
I think I will use the ompload one.
Offline
Pretty basic here:
function prompt_command {
local BXHL=`echo -e "\xE2\x94\x80"`
TERMWIDTH=${COLUMNS}
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
usernam=$(whoami)
cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
let upSeconds="$(cat /proc/uptime | cut -d'.' -f1)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
uptime="${days} ${hours}:${mins}:${secs}";
newPWD="${PWD}"
memuse=$(free -m | grep ^Mem: | sed "s/ * /\t/g" | cut -f 3 | sed "s/\t/\//g")
swpuse=$(free -m | grep ^Swap: | sed "s/ * /\t/g" | cut -f 3 | sed "s/\t/\//g")
# Add all the accessories below ...
let p1size=$(echo -n "+--(${usernam}@${hostnam}:${cur_tty})---(${memuse} ${swpuse} ${uptime})---($(date '+%a, %d %b %y %H:%M:%S'))--+" | wc -c | tr -d " ")
let f1size=${TERMWIDTH}-${p1size}
let p2size=$(echo -n "+-{${PWD}}-+" | wc -c | tr -d " ")
let f2size=${TERMWIDTH}-${p2size}
if [ "$f1size" -gt "$f2size" ]
then
let f1size=${f1size}-${f2size};
let f2size=0;
else
let f2size=${f2size}-${f1size};
let f1size=0;
fi
f1=""
while [ "$f1size" -gt "0" ]
do
f1="${f1}$BXHL"
let f1size=${f1size}-1
done
f2=""
while [ "$f2size" -gt "0" ]
do
f2="${f2}$BXHL"
let f2size=${f2size}-1
done
if [ "$f2size" -lt "0" ]
then
let cut=3-${f2size}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fi
twtty
}
PROMPT_COMMAND=prompt_command
function twtty {
local NOCOLOR="\[\033[0m\]"
local BLACK="\[\033[0;30m\]"
local BLUE="\[\033[0;34m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local RED="\[\033[0;31m\]"
local PURPLE="\[\033[0;35m\]"
local BROWN="\[\033[0;33m\]"
local LTGREY="\[\033[0;37m\]"
local DKGREY="\[\033[1;30m\]"
local LTBLUE="\[\033[1;34m\]"
local LTGREEN="\[\033[1;32m\]"
local LTCYAN="\[\033[1;36m\]"
local LTRED="\[\033[1;31m\]"
local LTPURPLE="\[\033[1;35m\]"
local YELLOW="\[\033[1;33m\]"
local WHITE="\[\033[1;37m\]"
local BXTLC=`echo -e "\xE2\x94\x8C"`
local BXTRC=`echo -e "\xE2\x94\x90"`
local BXBLC=`echo -e "\xE2\x94\x94"`
local BXBRC=`echo -e "\xE2\x94\x98"`
local BXHL=`echo -e "\xE2\x94\x80"`
local FC=$DKGREY
local BC=$GREEN
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS2="$RED$BXHL>$NOCOLOR "
PS1="$TITLEBAR\
$BC$BXTLC$BXHL\
$FC$BXHL{$CYAN\$usernam$BLUE@$LTPURPLE\$hostnam$BLUE:$LTGREY${cur_tty}$FC}$BXHL\
$BC\${f1}$BXHL\
$FC$BXHL{$PURPLE\${memuse}$LTBLUE $CYAN\${swpuse} $LTRED\${uptime}$FC}$BXHL\
$BC$BXHL\
$FC$BXHL{$CYAN\$(date \"+%a, %d %b %y %H:%M:%S\")$FC}$BXHL\
$BC$BXHL$BXTRC\
\n\
$BC$BXBLC\
$FC$BXHL{$BROWN\${newPWD}$FC}$BXHL\
$BC\${f2}\
$BC$BXBRC\
\n\
$PS2"
}Thinkpad x120e 8GB DDR3, 1.6Ghz X2 - Laptop/Netbook
AMD Athlon X2 OC'ed to 3.33GHz, 4GB DDR2 2TBx2 - Desktop/Seedbox
Offline
Here's a 10,000 line bashrc with loads of useful stuff.
O.O
"Of course it's happening inside your head, Harry, but why on earth should that mean that it is not real?" -Albus Dumbledore
Offline
Many thanks to all the above!! I have learned a lot from this thread 
Now that it is orderd, and as I did not change that much anymore in the last days, here is mine:
bashrc - aliases - inputrc
EXPLANATION OF SOME FEATURES:
I uses the same files on all systems so I put in some
case `uname` in
Linux) # ...
Darwin) # ...
esacto have system specific stuff sorted. In general its just some environment vars and shell options. This summs it up:
# ENVIREMENT VARIABLES
##############################################################################
if type most >/dev/null 2>&1 ; then
PAGER=most # does not need LESS_TERMCAP_*
export PAGER
else
# default pager program should be "less"
LESS_TERMCAP_mb=$'\033[01;31m' # begin blinking
LESS_TERMCAP_md=$'\033[01;31m' # begin bold
LESS_TERMCAP_me=$'\033[0m' # end mode
LESS_TERMCAP_se=$'\033[0m' # end standout-mode
LESS_TERMCAP_so=$'\033[01;44;33m' # begin standout-mode - info box
LESS_TERMCAP_ue=$'\033[0m' # end underline
LESS_TERMCAP_us=$'\033[01;32m' # begin underline
export LESS_TERMCAP_{mb,md,me,se,so,ue,us}
fi
EDITOR=vi # for command line editing with ^x+e
IGNOREEOF=1 # type ^D twice to logout
HISTCONTROL=erasedups # save same line to history only once
HISTSIZE=2000
FIGNORE='~:.o:.bak:.swp' # also see "shopt -u force_fignore"
# SHELL OPTIONS
##############################################################################
shopt -s checkwinsize # check window size after a process completes
shopt -u force_fignore # don't complete w/ <TAB> iff other files availablesome functions are also defined in the aliases file. I especially like this one:
comp () { #compare the speed of two ($1, $2) commands (loop $3 times)
if [ $# -ne 3 ]; then return 1; fi
type $1 >/dev/null 2>&1 || return 2
type $2 >/dev/null 2>&1 || return 3
printf 1
time for ((i=0; i<${3:-10}; i++)) ; do $1 ; done >/dev/null 2>&1
printf 2
time for ((i=0; i<${3:-10}; i++)) ; do $2 ; done >/dev/null 2>&1
}It helps me to find the faster of two alternative commands if I write a shell script.
happy bashing 
luc
Offline
Here's a 10,000 line bashrc with loads of useful stuff.
I'm sure there is, the only lines I'm 100% certain of though are the blank lines though. And there are a LOT of those. 
But I have to admit it is interesting to go through it and see what's what.
Last edited by Sector11 (2011-02-04 20:40:54)
#! Etiquette | Conky PitStop | VSIDO | Interactive LUA
Weather v9000 | Teo x4 Sites | Arclance | Finnish
Offline
@10000 lines bashrc
what is the use of 350kb of newlines and comments where you do not find anything again? And from a scroll over the first hundred lines I can see some redundant stuff already. (also why have an "if .. fi " span from line 172 to EOF ?) No doubt if you have the time to read that all and sort the rubish out you would have learned something about bash and end up with a nice bashrc.
But I prefer small and tidy code 
Offline
@10000 lines bashrc
what is the use of 350kb of newlines and comments where you do not find anything again? And from a scroll over the first hundred lines I can see some redundant stuff already. (also why have an "if .. fi " span from line 172 to EOF ?) No doubt if you have the time to read that all and sort the rubish out you would have learned something about bash and end up with a nice bashrc.
But I prefer small and tidy code
Small, tidy, well documented and no CRAP!
I mean I don't know what's what in a bash script for the most part, but like OLD "Basic" or "BAT" files, remember the autoexec.bat file - lean and mean makes for fast efficient files.
#! Etiquette | Conky PitStop | VSIDO | Interactive LUA
Weather v9000 | Teo x4 Sites | Arclance | Finnish
Offline
@10000 lines bashrc
what is the use of 350kb of newlines and comments where you do not find anything again? And from a scroll over the first hundred lines I can see some redundant stuff already. (also why have an "if .. fi " span from line 172 to EOF ?) No doubt if you have the time to read that all and sort the rubish out you would have learned something about bash and end up with a nice bashrc.
But I prefer small and tidy code
my .zshrc (I don't use bash) is only 270 lines unfortunaly 
"I'd rather run Linux on a 6.5KHz machine through an ARM emulator than run Vista"
Offline
@10000 lines bashrc
what is the use of 350kb of newlines and comments where you do not find anything again? And from a scroll over the first hundred lines I can see some redundant stuff already. (also why have an "if .. fi " span from line 172 to EOF ?) No doubt if you have the time to read that all and sort the rubish out you would have learned something about bash and end up with a nice bashrc.
But I prefer small and tidy code
I spend some time with this 10000 lines and there's some great stuff in it. I'll post my new .bash_aliases here soon. 
sed 's/stress/relaxation/g'
Privacy & Security on #!
Offline
I mean I don't know what's what in a bash script for the most part, but like OLD "Basic" or "BAT" files, remember the autoexec.bat file.
Heh. The golden days!! ... Constantly tweaking EMM386 and HIMEM variables in teh autoexec.bat and config.sys, trying to squeeze out as much as I could from my whopping 2MB (that's Megabyte for you giga people) just to play Comanche Maximum Overkill!!

my .zshrc (I don't use bash) is only 270 lines unfortunately
Lucky you!! My .zshrc is currently approaching 4500 lines, and I'm pretty sure I only utilize around 1500 of those for my usual tasks (I do a lot of syncing with CVS and Git). The rest is mostly redundant..... here's an example;
I have these lines...
# Rip an audio CD
#f5# Rip an audio CD
audiorip() {
mkdir -p ~/ripps
cd ~/ripps
cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
echo " * Would you like to burn the cd now? (yes/no)"
read input
if [[ "$input" = "yes" ]] ; then
echo " ! Burning Audio CD"
audioburn
echo " * done."
else
echo " ! Invalid response."
fi
}
# and burn it
#f5# Burn an audio CD (in combination with audiorip)
audioburn() {
cd ~/ripps
cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
echo " * Should I remove the temporary files? (yes/no)"
read input
if [[ "$input" = "yes" ]] ; then
echo " ! Removing Temporary Files."
cd ~
rm -rf ~/ripps
echo " * done."
else
echo " ! Invalid response."
fi
}
#f5# Make an audio CD from all mp3 files
mkaudiocd() {
# TODO: do the renaming more zshish, possibly with zmv()
emulate -L zsh
cd ~/ripps
for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
normalize -m *.wav
for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
}... on the .zshrc in my netbook.
Netbooks don't even have an optical drive!! 
Point & Squirt
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.