shell:zsh

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
shell:zsh [2020/04/13 13:37] – [Configuration .zshrc] d2airshell:zsh [2025/01/01 19:54] (Version actuelle) – [Configuration de ZSH] d2air
Ligne 1: Ligne 1:
 ====== Z Shell ====== ====== Z Shell ======
 +Configuration de [[wpfr>ZSH]], changement en shell par défaut, et ajout du framework [[https://ohmyz.sh/|Oh-My-Zsh]].
 ===== Fonctionnalités ===== ===== Fonctionnalités =====
 Zsh apporte les fonctionnalités suivantes : Zsh apporte les fonctionnalités suivantes :
Ligne 27: Ligne 28:
 ==== Configuration .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. 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.
-<file sh fichier.zsh>+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''
 +<code> 
 +plugins=(git github...) 
 +</code> 
 +Pour obtenir la liste des plugins disponibles il faudra utiliser la commande ''omz''
 +<code sh> 
 +omz plugin list 
 +</code> 
 +<file sh .zshrc> 
 +#!/usr/bin/env zsh
 #   _________  _   _ ____   ____  #   _________  _   _ ____   ____ 
 #  |__  / ___|| | | |  _ \ / ___| #  |__  / ___|| | | |  _ \ / ___|
Ligne 34: Ligne 45:
 #(_)____|____/|_| |_|_| \_\\____| #(_)____|____/|_| |_|_| \_\\____|
 # #
-alias cdiff='colordiff -u' + 
-alias cdir='dir --color=always'+# Plugins 
 +
 +plugins=(git github common-aliases dirhistory sudo nmap web-search python pip urltools copyfile encode64 history colored-man-pages ubuntu) 
 +
 +</file> 
 +<file sh fichier.zsh> 
 +
 +#      _ ____                    _      
 +#   __| |___ \ __ _(_)_ __ _______| |__   
 +#  / _` | __) / _` | | '__|_  / __| '_ \  
 +# | (_| |/ __/ (_| | | | _ / /\__ \ | | | 
 +#  \__,_|_____\__,_|_|_|(_)___|___/_| |_| 
 +#                                        
 +#
 bindkey "${key[Up]}"    up-line-or-history bindkey "${key[Up]}"    up-line-or-history
 bindkey "${key[Down]}"  down-line-or-history bindkey "${key[Down]}"  down-line-or-history
 bindkey "${key[PageUp]}"        history-beginning-search-backward bindkey "${key[PageUp]}"        history-beginning-search-backward
 bindkey "${key[PageDown]}"      history-beginning-search-forward bindkey "${key[PageDown]}"      history-beginning-search-forward
-plugins=(git github common-aliases dirhistory sudo nmap web-search python pip urltools copyfile encode64 history) 
 # #
 +# Alias
 +#
 +alias cdiff='colordiff -u'
 +alias cdir='dir --color=always'
 alias weather="curl http://wttr.in/paris" alias weather="curl http://wttr.in/paris"
 alias meteo="curl http://wttr.in/paris" alias meteo="curl http://wttr.in/paris"
 alias meteoparis="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 -c8+alias code="< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32
-alias coda="apg -a 0 -M sncl -n -x 8 -m 8"+alias code8="apg -a 0 -M sncl -n -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 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; } 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 whoami | figlet -f smslant
Ligne 56: Ligne 90:
 echo "Adresse IP $ippub ($iplan)" echo "Adresse IP $ippub ($iplan)"
 unset 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 a>+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` nb_alias=`alias | wc -l`
-if [ $nb_alias -gt 1 ]; then echo "$nb_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+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 unset nb_alias
 +echo "L'entropie est de $(cat /proc/sys/kernel/random/entropy_avail)/$(cat /proc/sys/kernel/random/poolsize)"
 </file> </file>
 +Enfin, pour connaître les fonctionnalités d'un plugin la commande ''omz'' peut s'utiliser ainsi :
 +<code sh>
 +omz plugin info git
 +</code>
 ==== Thèmes ==== ==== 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''. 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'' :
 +<code bash>
 +omz plugin themes
 +</code>
 +Le thème se délare dans le fichier ''.zshrc'' juste avant le paramètre source ''$ZSH/oh-my-zsh.sh''.
 +<file sh .zshrc>
 +#!/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
 +#
 +</file>
 +Et pour obtenir la liste des thèmes disponibles avec la commande ''omz'' :
 +<code sh>
 +omz theme list
 +</code>
 +
 +===== Configuration de ZSH =====
 +Un exemple de fichier de configuration :
 +<file sh .zshrc>
 +#!/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<tab>
 +zstyle ':completion:*' use-cache on
 +zstyle ':completion:*' cache-path ~/.zsh_cache
 +# des couleurs pour la complétion
 +# faites un kill -9 <tab><tab> 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"
 +#
 +</file>
  
  • shell/zsh.1586799425.txt.gz
  • Dernière modification : 2020/04/13 13:37
  • de d2air