====== Z Shell ====== Configuration de [[wpfr>ZSH]], changement en shell par défaut, et ajout du framework [[https://ohmyz.sh/|Oh-My-Zsh]]. ===== Fonctionnalités ===== Zsh apporte les fonctionnalités suivantes : * complétion des commandes, des options et des arguments de la plupart des commandes. En particulier, taper la suite de caractères « cd » ne permettra la complétion que par des répertoires ; * des fonctions de "Globbing" ou "Expansion" très avancées ; * partage de l'historique des commandes entre tous les shells zsh actuellement actifs ; * utilisation améliorée des variables et des tableaux ; * édition des commandes multi-lignes dans un seul buffer ; * correction « orthographique » des commandes tapées ; * plusieurs modes de compatibilité (zsh peut par exemple être vu comme un shell bourne quand il est exécuté en tant que /bin/sh) ; * invite de commande personnalisable, avec la possibilité d'afficher des informations sur le côté droit de l'écran qui disparaissent si la commande tapée est trop longue. ===== Installation de Z Shell ===== ==== Installation des paquets ==== sudo apt update && sudo apt install zsh ==== Changer le shell par défaut ==== chsh Mot de passe : Changement d'interpréteur de commandes initial pour d2air Entrez la nouvelle valeur ou « Entrée » pour conserver la valeur proposée Interpréteur de commandes initial [/bin/bash]: /bin/zsh ===== Oh my zsh ===== [[http://ohmyz.sh/|Oh-My-Zsh]] est un framework communautaire open source pour gérer une configuration ZSH. Il est livré avec une tonne de fonctions utiles, des aides, des plugins et des thèmes. git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc ==== Configuration .zshrc ==== Le nouveau fichier ''~/.zschrc'' peut être édité pour personnaliser la configuration, mais il existe un dossier ''~/.oh-my-zsh/custom'' afin d'ajouter un (ou plusieurs) fichier de configurations ''fichier.zsh'' qui écrasera les paramètres par défaut et ne sera pas modifié par les mises à jour. Cependant les plugins doivent absolument se déclarer dans le fichier ''.zshrc'' juste avant le paramètre source ''$ZSH/oh-my-zsh.sh''. L'activation des plugins se fait en les passant en paramètres de la fonction ''plugins'' : plugins=(git github...) Pour obtenir la liste des plugins disponibles il faudra utiliser la commande ''omz'' : omz plugin list #!/usr/bin/env zsh # _________ _ _ ____ ____ # |__ / ___|| | | | _ \ / ___| # / /\___ \| |_| | |_) | | # _ / /_ ___) | _ | _ <| |___ #(_)____|____/|_| |_|_| \_\\____| # # # Plugins # plugins=(git github common-aliases dirhistory sudo nmap web-search python pip urltools copyfile encode64 history colored-man-pages ubuntu) # # # _ ____ _ _ # __| |___ \ __ _(_)_ __ _______| |__ # / _` | __) / _` | | '__|_ / __| '_ \ # | (_| |/ __/ (_| | | | _ / /\__ \ | | | # \__,_|_____\__,_|_|_|(_)___|___/_| |_| # # bindkey "${key[Up]}" up-line-or-history bindkey "${key[Down]}" down-line-or-history bindkey "${key[PageUp]}" history-beginning-search-backward bindkey "${key[PageDown]}" history-beginning-search-forward # # Alias # alias cdiff='colordiff -u' alias cdir='dir --color=always' alias weather="curl http://wttr.in/paris" alias meteo="curl http://wttr.in/paris" alias meteoparis="curl http://wttr.in/paris" alias code="< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32" alias code8="apg -a 0 -M sncl -n 4 -x 8 -m 8" alias code16="apg -a 0 -M sncl -n 6 -x 16 -m 16" alias code32="apg -a 0 -M sncl -n 8 -x 32 -m 32" alias aptup="sudo apt update && sudo apt upgrade && sudo apt dist-upgrade && sudo rkhunter --propupd" # # Functions # transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; } # # Banner # whoami | figlet -f smslant ippub=`curl -s http://checkip.amazonaws.com/` iplan=`ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}'` echo "Adresse IP $ippub ($iplan)" unset ippub iplan if [ ${#plugins[@]} -gt 1 ]; then echo "${#plugins[@]} plugins oh-my-zsh sont activés."; elif [ ${#plugins[@]} -eq 1 ]; then echo "Le plugin \e[1m${plugins[1]} \e[0md'oh-my-zsh est activé."; else echo "Aucun plugin oh-my-zsh ne fut activé"; fi nb_alias=`alias | wc -l` if [ $nb_alias -gt 1 ]; then echo "$nb_alias alias sont définis."; elif [ $nb_alias -eq 1 ]; then echo "Un alias est défini."; else echo "Aucun alias n'est défini"; fi unset nb_alias echo "L'entropie est de $(cat /proc/sys/kernel/random/entropy_avail)/$(cat /proc/sys/kernel/random/poolsize)" Enfin, pour connaître les fonctionnalités d'un plugin la commande ''omz'' peut s'utiliser ainsi : omz plugin info git ==== Thèmes ==== Il possible de modifier un thème en le copiant ou d'en créer un dans le dossier ''~/.oh-my-zsh/custom/themes''. Pour obtenir la liste des thèmes disponibles avec la commande ''omz'' : omz plugin themes Le thème se délare dans le fichier ''.zshrc'' juste avant le paramètre source ''$ZSH/oh-my-zsh.sh''. #!/usr/bin/env zsh # _________ _ _ ____ ____ # |__ / ___|| | | | _ \ / ___| # / /\___ \| |_| | |_) | | # _ / /_ ___) | _ | _ <| |___ #(_)____|____/|_| |_|_| \_\\____| # # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes ZSH_THEME="robbyrussell" # plugins=(git github common-aliases dirhistory sudo nmap web-search python pip urltools copyfile encode64 history colored-man-pages ubuntu) # source $ZSH/oh-my-zsh.sh # Et pour obtenir la liste des thèmes disponibles avec la commande ''omz'' : omz theme list ===== Configuration de ZSH ===== Un exemple de fichier de configuration : #!/usr/bin/env zsh # _________ _ _ ____ ____ # |__ / ___|| | | | _ \ / ___| # / /\___ \| |_| | |_) | | # _ / /_ ___) | _ | _ <| |___ #(_)____|____/|_| |_|_| \_\\____| # # # Complétion autoload -U compinit compinit zstyle ':completion:*:descriptions' format '%U%B%d%b%u' zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b' zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \ /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin # Crée un cache des complétion possibles # très utile pour les complétion qui demandent beaucoup de temps # comme la recherche d'un paquet aptitude install moz zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh_cache # des couleurs pour la complétion # faites un kill -9 pour voir :) zmodload zsh/complist setopt extendedglob zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31" # Correction des commandes setopt correctall # If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. export ZSH="/home/d2air/.oh-my-zsh" # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes ZSH_THEME="robbyrussell" # Set list of themes to pick from when loading at random # Setting this variable when ZSH_THEME=random will cause zsh to load # a theme from this variable instead of looking in ~/.oh-my-zsh/themes/ # If set to an empty array, this variable will have no effect. # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true" # Uncomment the following line to use hyphen-insensitive completion. # Case-sensitive completion must be off. _ and - will be interchangeable. # HYPHEN_INSENSITIVE="true" # Uncomment the following line to disable bi-weekly auto-update checks. # DISABLE_AUTO_UPDATE="true" # Uncomment the following line to change how often to auto-update (in days). # export UPDATE_ZSH_DAYS=13 # Uncomment the following line to disable colors in ls. # DISABLE_LS_COLORS="true" # Uncomment the following line to disable auto-setting terminal title. # DISABLE_AUTO_TITLE="true" # Uncomment the following line to enable command auto-correction. # ENABLE_CORRECTION="true" # Uncomment the following line to display red dots whilst waiting for completion. # COMPLETION_WAITING_DOTS="true" # Uncomment the following line if you want to disable marking untracked files # under VCS as dirty. This makes repository status check for large repositories # much, much faster. # DISABLE_UNTRACKED_FILES_DIRTY="true" # Uncomment the following line if you want to change the command execution time # stamp shown in the history command output. # You can set one of the optional three formats: # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" # or set a custom format using the strftime function format specifications, # see 'man strftime' for details. # HIST_STAMPS="mm/dd/yyyy" # Would you like to use another custom folder than $ZSH/custom? # ZSH_CUSTOM=/path/to/new-custom-folder # Which plugins would you like to load? # Standard plugins can be found in ~/.oh-my-zsh/plugins/* # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. #plugins=( # git nmap github web-search #) plugins=(git github common-aliases dirhistory sudo nmap web-search python pip urltools copyfile encode64 history colored-man-pages ubuntu) source $ZSH/oh-my-zsh.sh # User configuration # export MANPATH="/usr/local/man:$MANPATH" # You may need to manually set your language environment # export LANG=en_US.UTF-8 # Preferred editor for local and remote sessions if [[ -n $SSH_CONNECTION ]]; then export EDITOR='vim' else export EDITOR='vim' fi # Compilation flags # export ARCHFLAGS="-arch x86_64" # ssh # export SSH_KEY_PATH="~/.ssh/rsa_id" # Set personal aliases, overriding those provided by oh-my-zsh libs, # plugins, and themes. Aliases can be placed here, though oh-my-zsh # users are encouraged to define aliases within the ZSH_CUSTOM folder. # For a full list of active aliases, run `alias`. # # Example aliases # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh" alias zshconf="vim ~/.zshrc" alias ohmyzsh="vim ~/.oh-my-zsh/custom/fichier.zsh" #