From af463d0f77796a2c97b5046c30a44116df2803b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sat, 8 Aug 2020 11:33:43 +0200 Subject: [PATCH] powerline-no --- config/shell/bashrc | 36 +++++++++++++++++++-------------- config/shell/zshrc | 49 +++++++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/config/shell/bashrc b/config/shell/bashrc index 4459546..4c11b20 100644 --- a/config/shell/bashrc +++ b/config/shell/bashrc @@ -13,26 +13,32 @@ HISTCONTROL=ignoreboth:erasedups # Prompt customization -INTERACTIVE_BASHPID_TIMER="${HOME}/.cache/bash_timer_$$" +if command -v powerline-go > /dev/null +then + INTERACTIVE_BASHPID_TIMER="${HOME}/.cache/bash_timer_$$" -PS0='$(echo $SECONDS > "$INTERACTIVE_BASHPID_TIMER")' + PS0='$(echo $SECONDS > "$INTERACTIVE_BASHPID_TIMER")' -function _update_ps1() { - local __ERRCODE=$? + function _update_ps1() { + local __ERRCODE=$? - local __DURATION=0 - if [ -e "$INTERACTIVE_BASHPID_TIMER" ]; then - local __END=$SECONDS - local __START=$(cat "$INTERACTIVE_BASHPID_TIMER") - __DURATION="$(($__END - ${__START:-__END}))" - \rm -f "$INTERACTIVE_BASHPID_TIMER" - fi + local __DURATION=0 + if [ -e "$INTERACTIVE_BASHPID_TIMER" ]; then + local __END=$SECONDS + local __START=$(cat "$INTERACTIVE_BASHPID_TIMER") + __DURATION="$(($__END - ${__START:-__END}))" + \rm -f "$INTERACTIVE_BASHPID_TIMER" + fi - # echo -en "… $\r" - eval "$(powerline-go -shell bash -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")" -} + # echo -en "… $\r" + eval "$(powerline-go -shell bash -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")" + } -PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" + PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" + +else + export PS1="\[\e]2;\u@\H \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] " +fi # Completion trysource /usr/share/bash-completion/bash_completion diff --git a/config/shell/zshrc b/config/shell/zshrc index 0ea7c55..8843fb9 100644 --- a/config/shell/zshrc +++ b/config/shell/zshrc @@ -48,31 +48,36 @@ function preexec() { __TIMER=$EPOCHREALTIME } -function powerline_precmd() { - local __ERRCODE=$? - local __DURATION=0 +if command -v powerline-go > /dev/null +then + function powerline_precmd() { + local __ERRCODE=$? + local __DURATION=0 - if [ -n $__TIMER ]; then - local __ERT=$EPOCHREALTIME - __DURATION="$(($__ERT - ${__TIMER:-__ERT}))" - fi - - echo -en "\033]; ${USER}@${HOST} $PWD\007" - # echo -en "… $\r" - eval "$(powerline-go -shell zsh -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")" - unset __TIMER -} - -function install_powerline_precmd() { - for s in "${precmd_functions[@]}"; do - if [ "$s" = "powerline_precmd" ]; then - return + if [ -n $__TIMER ]; then + local __ERT=$EPOCHREALTIME + __DURATION="$(($__ERT - ${__TIMER:-__ERT}))" fi - done - precmd_functions+=(powerline_precmd) -} -install_powerline_precmd + echo -en "\033]; ${USER}@${HOST} $PWD\007" + # echo -en "… $\r" + eval "$(powerline-go -shell zsh -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")" + unset __TIMER + } + + function install_powerline_precmd() { + for s in "${precmd_functions[@]}"; do + if [ "$s" = "powerline_precmd" ]; then + return + fi + done + precmd_functions+=(powerline_precmd) + } + + install_powerline_precmd +else + export PS1="\[\e]2;\u@\H \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] " +fi # Cursor based on mode if [ $TERM = "linux" ]; then