Browse Source

Amélioration prompt

master
Manfraid 3 years ago
parent
commit
4d991f2f46
5 changed files with 85 additions and 32 deletions
  1. 1
    1
      plugins/vcs.plugin.zsh
  2. 3
    0
      rc/00-helpers.zsh
  3. 28
    2
      rc/alias.zsh
  4. 43
    21
      rc/prompt.zsh
  5. 10
    8
      zshrc

+ 1
- 1
plugins/vcs.plugin.zsh View File

@@ -34,6 +34,6 @@
}
add-zsh-hook precmd _vbe_vcs_precmd
_vbe_add_prompt_vcs () {
_vbe_prompt_segment cyan default ${(e)vcs_info_msg_0_}
_vbe_prompt_segment 051 234 ${(e)vcs_info_msg_0_}
}
}

+ 3
- 0
rc/00-helpers.zsh View File

@@ -26,3 +26,6 @@ _vbe_can_do_unicode () {
fi
return 0
}




+ 28
- 2
rc/alias.zsh View File

@@ -6,6 +6,9 @@ alias du='du -h'
alias rm='rm -i'
alias ll='ls -l'
alias s='cd ..'

alias tmux='tmux -2'

__() {
local dmesg_version=${${${:-"$(dmesg --version 2> /dev/null)"}##* }:-0.0}
if is-at-least 2.23 $dmesg_version; then
@@ -31,7 +34,8 @@ alias la='ls -a'
alias lla='ls -la'
# ls pour voir que les fichiers par .
alias lsa='ls -ld .*'

alias lsd='ls -ld *(-/DN)'
alias lsdr='ls -ld **/*(-/DN)'
alias sl=ls # pour les ceussent qui pensent à la fin avant le début ;-)

alias grep='grep --color=always'
@@ -72,7 +76,14 @@ __() {

# smv like scp
alias smv='rsync -P --remove-source-files'
alias ccp='rsync -P'
alias zcp='noglob zmv -C'
alias zln='noglob zmv -L'
alias zmv='noglob zmv'


(( $+functions[compdef] )) && compdef _ssh smv=scp
(( $+functions[compdef] )) && compdef _ssh ccp=scp

# Less generic aliases
susu() {
@@ -85,6 +96,20 @@ susu() {
}
alias please='sudo $(fc -ln -1)'

# Pas de correction
alias man='nocorrect man'
alias mysql='nocorrect mysql'
alias mysqlshow='nocorrect mysqlshow'
alias mkdir='nocorrect mkdir'
alias mv='nocorrect mv --interactive'
alias cp='nocorrect cp --interactive'
alias rm='nocorrect rm --interactive'
alias rj='nocorrect rj'
alias cd='nocorrect cd'
alias ln='nocorrect ln -i'



# Aliases as a function
evince() { command evince ${*:-*.(djvu|dvi|pdf)(om[1])} }
md() { command mkdir -p $1 && cd $1 }
@@ -356,7 +381,8 @@ colortest() {
for green in {0..5}; do
for blue in {0..5}; do
bg=$((16 + red * 36 + green * 6 + blue))
printf "\e[48;5;%dm " bg
fg=$((16 + (5-red) * 36 + (5-green) * 6 + 5 - blue))
printf "\e[48;5;%dm\e[38;5;%dm%3d " bg fg bg
done
printf "\e[0m "
done

+ 43
- 21
rc/prompt.zsh View File

@@ -19,6 +19,27 @@ else
}
fi

typeset -AHg FX FG BG

FX=(
reset "\e[00m"
bold "\e[01m"
no-bold "\e[22m"
italic "\e[02m"
no-italic "\e[23m"
underline "\e[04m"
no-underline "\e[24m"
blink "\e[05m"
no-blink "\e[25m"
reverse "\e[07m"
no-reverse "\e[27m"
)

for color in {000..255}; do
FG[$color]="\e[38;5;${color}m"
BG[$color]="\e[48;5;${color}m"
done

# Stolen from https://github.com/sindresorhus/pure/blob/master/pure.zsh
_vbe_human_time () {
local tmp=$1
@@ -34,14 +55,14 @@ _vbe_human_time () {
print -n "${result[1,2]}"
}

CURRENT_BG=NONE
CURRENT_BG=0
_vbe_prompt_segment() {
local b f
[[ -n $1 ]] && b="$bg[$1]" || b="$bg[default]"
[[ -n $2 ]] && f="$fg[$2]" || f="$fg[default]"
[[ -n $1 ]] && b=$BG[$1] || b=$BG[000]
[[ -n $2 ]] && f=$FG[$2] || f=$FG[011]
[[ -n $3 ]] || return
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
print -n " %{%b$b$fg[$CURRENT_BG]%}${PRCH[end]}%{$f%} "
if [[ $CURRENT_BG != 0 && $1 != $CURRENT_BG ]]; then
print -n " %{%b$b$FG[$CURRENT_BG]%}${PRCH[end]}%{$f%} "
elif [[ $1 == $CURRENT_BG ]]; then
print -n " %{%b$b$f%}${PRCH[sep]} "
else
@@ -52,21 +73,22 @@ _vbe_prompt_segment() {
}
_vbe_prompt_end() {
if [[ -n $CURRENT_BG ]]; then
print -n " %{%b$fg[$CURRENT_BG]%}${PRCH[end]}"
print -n " %{%b$FG[$CURRENT_BG]%}${PRCH[end]}"
else
print -n "%{%b%}"
fi
print -n "%{${reset_color}%}"
CURRENT_BG=''
print -n "%{$FX[reset]%}"
CURRENT_BG=0
}

_vbe_prompt () {
local retval=$?
local fond="ligh_blue"
local fond=196
# user@host
local f=${(%):-%(!.red.${${SSH_TTY:+magenta}:-green})}
_vbe_prompt_segment black $f \
%B%n%b%{${fg[cyan]}%}${${(%):-%n}:+@}%B%{${bg[black]}${fg[$f]}%}%M
local f=${(%):-%(!.196.${${SSH_TTY:+028}:-046})}
_vbe_prompt_segment 234 $f \
$FX[bold]%n$FX[no-bold]%{${FG[051]}%}${${(%):-%n}:+@}%{${BG[234]}${FG[$f]}%}$FX[bold]%M$FX[no-bold]

# Directory
local -a segs
@@ -74,20 +96,20 @@ _vbe_prompt () {
segs=(${(s./.)${(%):-%${len}<${PRCH[ellipsis]}<%~}})
[[ ${#segs} == 0 ]] && segs=(/)
if [[ -w $PWD ]]; then
fond="cyan"
fond=034
else
fond="red"
fond=196
fi

for seg in ${segs[1,-2]}; do
_vbe_prompt_segment $fond black $seg
for seg in ${segs[1,-1]}; do
_vbe_prompt_segment $fond 234 $seg
done
_vbe_prompt_segment $fond black ${segs[-1]}
#_vbe_prompt_segment $fond 88 ${segs[-1]}
_vbe_prompt_end

# New line
print
CURRENT_BG=NONE
CURRENT_BG=0

# Additional info
_vbe_add_prompt
@@ -96,12 +118,12 @@ _vbe_prompt () {
local now=$EPOCHSECONDS
local elapsed=$(($now - ${_vbe_cmd_timestamp:-$now}))
(($elapsed >= 5)) && \
_vbe_prompt_segment white black "$(_vbe_human_time $elapsed)"
_vbe_prompt_segment 255 008 "$(_vbe_human_time $elapsed)"

# Error code
(( $retval )) && \
_vbe_prompt_segment red default %B${PRCH[retb]}'%?'${PRCH[reta]} || \
_vbe_prompt_segment green white %B${PRCH[ok]}
_vbe_prompt_segment 196 010 %B${PRCH[retb]}'%?'${PRCH[reta]} || \
_vbe_prompt_segment 034 234 %B${PRCH[ok]}

_vbe_prompt_end
}

+ 10
- 8
zshrc View File

@@ -5,14 +5,14 @@
[ -t 1 ] || exec /bin/sh

# Execute tmux if available and if we have some configuration for it
(( $+commands[tmux] )) && \
[[ -f ~/.tmux.conf && \
$PPID != 1 && \
$$ != 1 && \
$TERM != linux && \
$TERM != screen* && \
-z $TMUX ]] && \
exec tmux
#(( $+commands[tmux] )) && \
# [[ -f ~/.tmux.conf && \
# $PPID != 1 && \
# $$ != 1 && \
# $TERM != linux && \
# $TERM != screen* && \
# -z $TMUX ]] && \
# exec tmux

ZSH=${ZSH:-${ZDOTDIR:-$HOME}/.zsh}
fpath=($ZSH/functions $ZSH/completions $fpath)
@@ -27,6 +27,8 @@ autoload -U is-at-least
{ autoload -U +X add-zsh-hook || unset -f add-zsh-hook } 2> /dev/null

__() {
local -a plugins
plugins=(vcs)
for config_file ($ZSH/rc/*.zsh) source $config_file
for plugin ($plugins) source $ZSH/plugins/$plugin.plugin.zsh
[ ! -e $ZSH/env ] || . $ZSH/env

Loading…
Cancel
Save