diff --git a/_bashrc b/_bashrc index fa00585..0281301 100644 --- a/_bashrc +++ b/_bashrc @@ -1,7 +1,5 @@ #!/bin/bash -. ~/.shrc - export HISTCONTROL=erasedups export HISTSIZE=10000 @@ -12,10 +10,8 @@ shopt -s globstar prompt_escape() { echo "\[$1\]" } - prompt_date='\D{%H:%M:%S}' - -. ~/bin/bash-prompt +. ~/.shrc PROMPT_COMMAND=my_prompt diff --git a/_shrc b/_shrc index eb3ee4b..5f65665 100644 --- a/_shrc +++ b/_shrc @@ -58,4 +58,58 @@ local_config="$HOME/.shrc-local" test -f "$local_config" && . "$local_config" + +# Le prompt + + +date_color="$(prompt_escape $(tput setaf 248))" +cwd_color="$(prompt_escape $(tput setaf 38))" +jobs_color="$(prompt_escape "$(tput setab 221)$(tput setaf 16)")" +end_jobs_color="$(prompt_escape $(tput setab 0))" +code_color="$(prompt_escape "$(tput setab 203)$(tput setaf 16)")" +end_code_color="$(prompt_escape $(tput setab 0))" +bold="$(prompt_escape $(tput bold))" +end_bold="$(prompt_escape $(tput sgr0))" + + +if test "$EUID" = 0 +then + host_color="$(prompt_escape $(tput setaf 203))" +elif test -n "$SSH_TTY" || test -n "$SUDO_USER" +then + host_color="$(prompt_escape $(tput setaf 221))" +else + host_color="$(prompt_escape $(tput setaf 47))" +fi +host_piece="$host_color$(whoami)@$(hostname)" + +date_piece="$date_color$prompt_date" + + +my_prompt() { + + previous_code=$? + + pieces="$date_piece $host_piece" + + working_dir="$PWD" + slashes="${working_dir//[^\/]}" + if ((${#slashes} > 3)) + then + for i in $(seq 3 ${#slashes}) + do + working_dir="${working_dir#*/}" + done + fi + pieces="$pieces $cwd_color$working_dir" + + number_of_jobs=$(jobs | grep '^\[' | wc -l) + (($number_of_jobs > 0)) && pieces="$pieces $jobs_color$number_of_jobs$end_jobs_color" + + (($previous_code > 0)) && pieces="$pieces $code_color$previous_code$end_code_color" + + PS1="$bold$pieces$end_bold " +} + + true diff --git a/_zshrc b/_zshrc index f1f5014..40a199a 100644 --- a/_zshrc +++ b/_zshrc @@ -1,7 +1,5 @@ #!/bin/zsh -. ~/.shrc - export HISTSIZE=10000 export SAVEHIST=$HISTSIZE @@ -17,10 +15,8 @@ setopt EXTENDED_GLOB prompt_escape() { echo "%{$1%}" } - prompt_date='%D{%H:%M:%S}' - -. ~/bin/bash-prompt +. ~/.shrc precmd_functions=(my_prompt) diff --git a/bin/bash-prompt b/bin/bash-prompt deleted file mode 100644 index 30ca3df..0000000 --- a/bin/bash-prompt +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -date_color="$(prompt_escape $(tput setaf 248))" -cwd_color="$(prompt_escape $(tput setaf 38))" -jobs_color="$(prompt_escape "$(tput setab 221)$(tput setaf 16)")" -end_jobs_color="$(prompt_escape $(tput setab 0))" -code_color="$(prompt_escape "$(tput setab 203)$(tput setaf 16)")" -end_code_color="$(prompt_escape $(tput setab 0))" -bold="$(prompt_escape $(tput bold))" -end_bold="$(prompt_escape $(tput sgr0))" - - -if test "$EUID" = 0 -then - host_color="$(prompt_escape $(tput setaf 203))" -elif test -n "$SSH_TTY" || test -n "$SUDO_USER" -then - host_color="$(prompt_escape $(tput setaf 221))" -else - host_color="$(prompt_escape $(tput setaf 47))" -fi -host_piece="$host_color$(whoami)@$(hostname)" - -date_piece="$date_color$prompt_date" - - -my_prompt() { - - previous_code=$? - - pieces="$date_piece $host_piece" - - working_dir="$PWD" - slashes="${working_dir//[^\/]}" - if ((${#slashes} > 3)) - then - for i in $(seq 3 ${#slashes}) - do - working_dir="${working_dir#*/}" - done - fi - pieces="$pieces $cwd_color$working_dir" - - number_of_jobs=$(jobs | grep '^\[' | wc -l) - (($number_of_jobs > 0)) && pieces="$pieces $jobs_color$number_of_jobs$end_jobs_color" - - (($previous_code > 0)) && pieces="$pieces $code_color$previous_code$end_code_color" - - PS1="$bold$pieces$end_bold " -}