From a298aa21ad4b16eea42b37b7bbc317e1a9695e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Tue, 5 Apr 2022 12:30:25 +0200 Subject: Improve coloring of bash --- home-dots/dot-bashrc | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'home-dots') diff --git a/home-dots/dot-bashrc b/home-dots/dot-bashrc index ad6595f..c878c6a 100644 --- a/home-dots/dot-bashrc +++ b/home-dots/dot-bashrc @@ -5,11 +5,6 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return -# GPG agent with ssh -unset SSH_AGENT_PID -if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then - export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" -fi # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" @@ -22,6 +17,7 @@ if [ -x /usr/bin/dircolors ]; then alias egrep='egrep --color=auto' fi +# COLOR THEME # Git branch in prompt. git_current_branch() { local ref @@ -31,21 +27,49 @@ git_current_branch() { [[ $ret == 128 ]] && return # no git repo. ref=$(git rev-parse --short HEAD 2>/dev/null) || return fi - echo ${ref#refs/heads/} + echo "  ${ref#refs/heads/}" +} + +function __prompt_command { + # Must collect exit code very first thing + # Just calculating git_branch changes the exit code + local EXIT="$?" + + local red="\[\e[0;31m\]" + local green="\[\e[0;32m\]" + local yellow="\[\e[0;33m\]" + local orange="\[\e[0;91m\]" + local normal="\[\e[0m\]" + local blue="\[\e[0;34m\]" + + PS1="\u@\h ${green}\w${blue}$(git_current_branch)" + + if [[ "${EXIT}" -ne 0 ]]; then + PS1+=" ${red}✗ ${yellow}${EXIT}${orange}" + else + PS1+="${green}" + fi + PS1+=" ❯${normal} " } +PROMPT_COMMAND=__prompt_command -export PS1="\u@\h \W\[\033[32m\] \$(git_current_branch)\[\033[00m\] $ " +# GPG agent with ssh +unset SSH_AGENT_PID +if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then + export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" +fi export PATH="$HOME/.local/bin:$PATH" alias isrun='ps -ae | grep' alias gdimg='git difftool -t image_diff' alias G='grep -i' alias lar='ls -lahrt' +alias emacs='TERM=xterm-direct emacs' alias mykeys='setxkbmap -I$HOME/.config/xkb/ oscar -option caps:escape -print | xkbcomp -I$HOME/.config/xkb/ - $DISPLAY' # export PATH="$HOME/.cargo/bin:$PATH" -if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi # added by Nix installer -[ -f "$HOME/.ghcup/env" ] && source "$HOME/.ghcup/env" # ghcup-env +if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi # added by Nix installer +[ -f "$HOME/.ghcup/env" ] && source "$HOME/.ghcup/env" # ghcup-env GUIX_PROFILE="$HOME/.guix-profile" && [ -e "$GUIX_PROFILE" ] && . "$GUIX_PROFILE/etc/profile" && export GUIX_LOCPATH=$GUIX_PROFILE/lib/locale GUIX_PROFILE="$HOME/.config/guix/current" && [ -e "$GUIX_PROFILE" ] && . "$GUIX_PROFILE/etc/profile" # export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs" -- cgit v1.2.3