#1 Le 28/08/2013, à 20:54
- omnimax
mettons nos .zshrc en ligne !
Salut les ubunteros
A l'instar de github, je vous propose de partager nos zshrc.
Je commence par le mien en espérant que d'autres suivront
# /etc/zsh/zshrc: system-wide .zshrc file for zsh(1).
#
# This file is sourced only for interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
#DEPENDANCES NECESSAIRES :
# >>> sudo apt-get install -y autojump pdftk imagemagick msmtp unrar mplayer evince
#VARIABLES A REMPLACER SELON USAGE
# monmail@gmail.com
# Ubuntu\ One/
# $HOME/Ubuntu\ One/voice-system-activated.wav (SON POUR AVERTIR DE LA FIN D'UNE COMMANDE)
# nomreseau
# exempledecode
#CHARGEMENT DE AUTOJUMP
. /usr/share/autojump/autojump.sh
#COMPLETION
autoload -U bashcompinit
bashcompinit
autoload -U compinit
compinit
#AMELIORATION COMPLETION
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BDésolé, pas de résultats pour : %d%b'
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
#Pour éviter de proposer un élément déjà présent lors d'un cp, mv ou rm :
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes
#Sur Ubuntu, on utilise souvent sudo, donc il peut être intéressant d'avoir la complétion lorsque la #commande n'est pas dans votre $PATH
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
/usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
#COMPLETION SOUS BASH
autoload -U bashcompinit
bashcompinit
#PROMPT
autoload -U colors && colors
autoload -U promptinit
setopt PROMPT_CR
setopt PROMPT_SP
promptinit
export PS1="CHEMIN: %d %F{green}DATE: %D{%a %d %b %H:%M:%S}
-->%f %F{white}%f"
#HISTORY
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory auto_cd auto_pushd nomatch notify correct
#IGNORER COMMANDES DOUBLONS
setopt hist_ignore_all_dups
#IGNORER COMMANDES PRECEDEES D'UN ESPACE
setopt hist_ignore_space
#CD AUTO
setopt autocd
#CORRECTION
setopt correctall
#VARIABLES ZSH
setopt nocaseglob
setopt extendedglob
#SUPPORT DES MIMES
autoload -U zsh-mime-setup
autoload -U zsh-mime-handler
zsh-mime-setup
#SUPER FONCTION INTERNES
autoload -U zfinit
zfinit
#zcalc : une calculatrice (plus besoin de bc ou autres expr)
#zargs : un super xargs
#zmv : une commande permettant de faire du renommage/déplaçage en masse de fichiers.
#zftp : un client ftp natif
# CASE-INSENSITIVE (uppercase from lowercase) completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
## case-insensitive (all) completion
#zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
## case-insensitive,partial-word and then substring completion
#zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
#ALIAS MAISON ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
alias zo='cp $HOME/.zshrc $HOME/Ubuntu\ One/'
alias zub='cp $HOME/Ubuntu\ One/.zshrc $HOME/'
alias ls='ls -c --color --reverse'
# ls avec affichage du dernier fichier modifié en bas + indication taille et permissions
alias lt='ls -l -t -h --reverse'
alias ca='cd .. && ls'
alias rr='rm -r'
alias infopaquet='dpkg -L'
alias zi='sudo apt-get install -y'
alias pu='sudo apt-get remove --purge'
alias ge='sudo gedit'
alias cx='sudo chmod +x'
alias up='sudo apt-get update'
alias upg='sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoclean'
alias list='sudo gedit /etc/apt/sources.list'
alias config='gedit /home/$USER/.zshrc &'
alias applyconfig='source ~/.zshrc'
alias dodo='sudo shutdown -P now'
alias reboot='sudo reboot'
alias fx='firefox &'
alias trouve="find . -iname"
alias na='nautilus . &'
alias to='mplayer $HOME/Ubuntu\ One/voice-system-activated.wav 2>/dev/null'
#ALIAS OUVERTURE PAR DEFAUT
alias -s doc="libreoffice"
alias -s pdf="evince"
#ALIAS EXEMPLE DE SCRIPT
alias fos='cat $HOME/Ubuntu\ One/exempledecode'
#ALIAS RADIO
alias pure='wget http://www.static.rtbf.be/radio/purefm/m3u/pure_128k.m3u && mplayer pure_128k.m3u'
alias mint='firefox http://mint.radio.fr/broadcast_info.jsf &'
#ALIAS RESEAU
alias cl='cd /home/$USER/.gvfs/nomreseau && ls'
#FONCTIONS INTERNET
y() {firefox "http://www.youtube.com/results?search_type=&search_query=$*&aq=f" 2>/dev/null &}
p() {firefox "http://maps.google.com?q=$*" 2>/dev/null &}
i() {firefox "http://images.google.be/images?q=$*" 2>/dev/null &}
g() {firefox "http://www.$1" 2>/dev/null &}
# usage g apple.com (par exemple)
u() {firefox "http://www.google.fr/search?hl=fr&q=$*+site%3Adoc.ubuntu-fr.org" 2>/dev/null &}
f() {firefox "http://www.google.fr/search?q=$*+site%3Aforum.ubuntu-fr.org" 2>/dev/null &}
r() {firefox "http://www.google.fr/search?q=$*" 2>/dev/null &}
#FONCTIONS MAIL
me() {echo "$*" | msmtp monmail@gmail.com}
#FONCTIONS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
c() {cd "$*" && sls}
de() {cd && umount /media/$1}
mk() {mkdir "$1" && cd "$1"}
#FONCTIONS COMPLEXES ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#CREE UN DOSSIER ET COPIE DES FICHIERS DEDANS > USAGE : mkp pathdossier fichier(s)
mkp()
{
mon_dir="$1"; shift
mkdir -p "$mon_dir" && cp "$@" "$mon_dir"
}
#REGROUPE LES PDF DANS UN SEUL FICHIER ET REDUIT SA TAILLE > USAGE: gpdf nomfichiergroupé ou gpdf nomfichiergroupé #fichier1.pdf fichier2.pdf etc...
gpdf()
{
if [ "$#" -eq 1 ]; then
if [ "$#" -eq 0 ]; then
echo "vous devez indiquer le nom final du fichier"
elif [[ $1 == *.(pdf|PDF) ]]; then
echo "vous ne devez pas mettre l'extension, nous la mettons pour vous"
else
pdftk *.(pdf|PDF) cat output "$1".pdf && gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf "$1".pdf && mv out.pdf "$1".pdf && mplayer $HOME/Ubuntu\ One/voice-system-activated.wav && ls -l -t -h
fi
else
group="$1"; shift
pdftk "$@" cat output "$group".pdf && gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf "$group".pdf && mv out.pdf "$group".pdf && mplayer $HOME/Ubuntu\ One/voice-system-activated.wav && ls -l -t -h
fi
}
#REDUIT LA TAILLE D'UN PDF
rpdf()
{
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf "$1"
nouveau=$1
mv out.pdf ${nouveau%.*}.pdf && mplayer $HOME/Ubuntu\ One/voice-system-activated.wav && ls -l -t -h
}
# EXTRAIT TOUS LES FORMATS D'ARCHIVES
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar 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 ;;
*.xz) unxz $1 ;;
*.exe) cabextract $1 ;;
*) echo "\`$1': unrecognized file compression" ;;
esac
else
echo "\`$1' is not a valid file"
fi
}
#TELEPORTATION AVEC LA CONSOLE
tel()
{
PS3='Choisissez le fichier à ouvrir : ' # Affiche l'invite.
echo
select fichier in **/"$1"*
do
cd "$fichier"
echo
break # Qu'arriverait-il s'il n'y avait pas de 'break' ici ?
#+ fin.
done
}
#TELEPORTATION AVEC NAUTILUS
rep()
{
PS3='Choisissez le fichier à ouvrir : ' # Affiche l'invite.
echo
select fichier in **/"$1"*
do
nautilus "$fichier"
echo
break # Qu'arriverait-il s'il n'y avait pas de 'break' ici ?
#+ fin.
done
}
#CHERCHE ET OUVRE LES FICHIERS LIBREOFFICE/OFFICE
libre()
{
PS3='Choisissez le fichier libreoffice à ouvrir : '
echo
select fichier in **/"$1"*(ods|xls|doc|odt)
do
libreoffice "$fichier"
echo
break
done
}
#CHERCHE ET OUVRE LES FICHIERS PDF
ev()
{
PS3='Choisissez le fichier pdf à ouvrir : '
echo
select fichier in **/"$1"*pdf
do
if [ -f /share/evince ]; then
evince "$fichier"
else
okular "$fichier"
fi
echo
break
done
}
#SCRIPT REDUCTION IMAGES +ZIP
reduire()
{
convert *.(jpg|JPG|BMP|bmp|png|PNG|JPEG) imagered.jpeg
mogrify -resize 2500x2500 *.jpeg
mkdir imagesreduites
cp *.jpeg imagesreduites
zip imagesreduites/imagesreduites.zip *.jpeg
rm *.jpeg
mplayer $HOME/Ubuntu\ One/voice-system-activated.wav 2>/dev/null
cd imagesreduites
ls -l -t -h
}
#LECTURE DE FICHIERS MUSICAUX ET VIDEOS
mp()
{
PS3='Choisissez le fichier musical ou vidéo à ouvrir : '
echo
select fichier in **/*"$1"*(mp3|mp4|mkv|flv|wav|mpeg|avi|ogg)
do
mplayer "$fichier"
echo
break
done
}
#AFFICHAGE PAR EXTENSION
yls()
{
local filetype=""
local oldtype=""
LC_ALL=C ls -l $1 \
| grep -v "^total" \
| sort \
| sed -r -e 's/^(d.*)$/\1 [Dossier]/' -e 's/^(l.*)$/\1 [Lien symbolique]/' -e 's/^([^d].*)\.([^\.~]+)(~?)$/\1\.\2\3 [\2]/' \
| sed -r -e 's/^(.*[^]])$/NULL\t\1/' -e 's/^(.*) \[([^]]+)\]$/\2\t\1/' \
| sort -i \
| while read line; \
do \
filetype=$(echo "$line" | cut -d$'\t' -f1); \
if ! echo "$filetype" | grep -iq "^${oldtype}$"; \
then \
[[ "$oldtype" != "" ]] && echo;
echo -e "$(echo $filetype | sed 's/NULL/Aucune extension/') \n---------------------------------------------------------"; \
oldtype="$filetype"; \
fi; \
echo "$line" | sed -r 's/^[^\t]+\t//'; \
done
type noglob >/dev/null || alias noglob=''
}
#AFFICHAGE STRUCTURE DOSSIER + FICHIERS SCINDES
sls ()
{
fichiers=$(ls -l -t -h -c --color * 2>/dev/null)
dossiers=$(ls -l -t -h -c --color -F 2>/dev/null| grep /)
[ ! -d $dossiers ] &&
echo -e /n echo "\033[36m$PWD DOSSIERS\033[36m" && echo "-------------------------------------------------" && echo "\033[37m$dossiers" && echo ;
[ ! -e $fichiers ] && echo "\033[36m$PWD FICHIERS" && echo "-------------------------------------------------" && echo "\033[37m$fichiers";
}
exempledecode
$* contient tous les arguments passés à la fonction
$# contient le nombre d'argument
$? contient le code de retour de la dernière opération
$0 contient le nom du script
$n contient l'argument n, n étant un nombre
$! contient le PID de la dernière commande lancée
-e fichier renvoie 0 si fichier existe.
-d fichier renvoie 0 si fichier existe et est un répertoire.
-f fichier renvoie 0 si fichier existe et est un fichier 'normal'.
-w fichier renvoie 0 si fichier existe et est en écriture.
-x fichier renvoie 0 si fichier existe et est exécutable.
f1 -nt f2 renvoie 0 si f1 est plus récent que f2.
f1 -ot f2 renvoie 0 si f1 est plus vieux que f2.
$A -lt 5 renvoie 0 si $A est strictement inférieur à 5
$A -le 5 renvoie 0 si $A est inférieur ou égal à 5
$A -gt 5 renvoie 0 si $A est strictement supérieur à 5
$A -ge 5 renvoie 0 si $A est supérieur ou égal à 5
$A -eq 5 renvoie 0 si $A est égal à 5
$A -ne 5 renvoie 0 si $A est différent de 5
for i in ${commande}; do echo $i; done
----------------------------------------------------------
find . -type f -exec file '{}' \;
----------------------------------------------------------
[[ -f /etc/passwd ]]
echo $?
0
----------------------------------------------------------
echo -n "Entrez un nom de fichier: "
read file
if [ -e "$file" ]; then
echo "Le fichier existe!"
else
echo "Le fichier n'existe pas, du moins n'est pas dans le répertoire d'exécution du script"
fi
exit 0
----------------------------------------------------------
echo -n "Voulez-vous voir la liste des fichiers Y/N : "
read ouinon
if [ "$ouinon" = "y" ] || [ "$ouinon" = "Y" ]; then
echo "Liste des fichiers :"
ls -la
elif [ "$ouinon" = "n" ] || [ "$ouinon" = "N" ]; then
echo "Ok, bye! "
else
echo "Il faut taper Y ou N!! Pas $ouinon"
fi
----------------------------------------------------------
cmpt=1
cm=3
echo -n "Mot de passe : "
read mdp
while [ "$mdp" != "ubuntu" ] && [ "$cmpt" != 4 ]
do
echo -n "Mauvais mot de passe, plus que "$cm" chance(s): "
read mdp
cmpt=$(($cmpt+1))
cm=$(($cm-1))
done
echo "Non mais, le brute-force est interdit en France !!"
exit 0
----------------------------------------------------------
echo -n "Etes-vous fatigué ? "
read on
case "$on" in
oui | o | O | Oui | OUI ) echo "Allez faire du café !";;
non | n | N | Non | NON ) echo "Programmez !";;
* ) echo "Ah bon ?";;
esac
exit 0
Dernière modification par omnimax (Le 28/08/2013, à 21:01)
14.04 unity et Linux Mint KDE 13 zsh-meilleur shell script fire
Hors ligne