if [ -n "$PS1" ]; then function term_colors(){ for i in {0..15}; do for j in {0..15}; do c=$((i*16+j)); printf " $(tput setab $c)%04d" $c; done; printf "$(tput sgr0)\n"; done for i in {0..15}; do for j in {0..15}; do c=$((i*16+j)); printf " $(tput setaf $c)%04d" $c; done; printf "$(tput sgr0)\n"; done } fi # # Prompt if interactive # if [ -n "$PS1" ]; then # # Number of colors and standard colors. # c_num=$(tput colors) # # Set better colors if available. # if [ $c_num -ge 256 ]; then c_reset="$(tput sgr0)" c_user="$(tput setaf 203)" #Some bright color c_host="$(tput setaf 112)" #Green c_cwd="$(tput setaf 99)" c_time="$(tput setaf 33)" #Light blue c_branch="$(tput setaf 138)" c_error="$(tput setaf 203)" #Red c_info="$(tput setaf 220)" #Yellow else c_reset="$(tput sgr0)" c_user="$(tput setaf 1)" # c_host="$(tput setaf 2)" #Green c_cwd="$(tput setaf 7)" #White c_time="$(tput setaf 6)" #Cyan c_branch="$(tput setaf 6)" #Cyan c_error="$(tput setaf 1)" #Red c_info="$(tput setaf 3)" #Yellow fi [ -n "$(which svn)" ] && prompt_check_svn=true [ -n "$(which git)" ] && prompt_check_git=true [ -n "$(which hg)" ] && prompt_check_hg=true if [ -n "$ZSH_VERSION" ]; then s_host="%m" s_user="%n" s_cwd="%/" s_time="%t" fi if [ -n "$BASH_VERSION" ]; then export PROMPT_COMMAND="__prompt_command" s_host="\h" s_user="\u" s_cwd="\w" s_time="\t" # Turn on checkwinsize shopt -s checkwinsize fi # zsh function precmd() { __prompt_command } function __prompt_command() { # # get exit code before any command is run. TODO: doesn't work on pi. # local exit_code="$?" prompt_extra="" PS1="" if [ "$USER" != "vahagnk" -a "$USER" != "vahagn" ]; then PS1+="${c_user}${s_user}@" # username@ fi PS1+="${c_host}${s_host}:" # hostname PS1+="${c_time}${s_time}" # time PS1+=" ${c_cwd}${s_cwd}" # working_dir # # git branch if exist # if [ -n "$prompt_check_git" ]; then local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ') if [ -n "$git_branch" ]; then PS1+="${c_branch}@${git_branch}" fi fi # # svn branch if exist # if [ -n "$prompt_check_svn" ]; then local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }') if [ -n "$svn_rev" ]; then PS1+="${c_branch}@${svn_rev}" # svn revision fi fi # # Python venv. # local jobs_bg=$(jobs -r | wc -l | tr -d ' ') if [ -n "$VIRTUAL_ENV" ]; then # PS1+=",\[${c_info}\]$(realpath --relative-to=$PWD $VIRTUAL_ENV)" PS1+=",${c_info}$(basename $VIRTUAL_ENV)" fi # # Info about jobs. # local jobs_bg=$(jobs -r | wc -l | tr -d ' ') if [ $jobs_bg -gt 0 ]; then PS1+=",${c_info}bg=${jobs_bg}" fi local jobs_stopped=$(jobs -s | wc -l | tr -d ' ') if [ $jobs_stopped -gt 0 ]; then PS1+=",${c_info}stp=${jobs_stopped}" fi # # exit code if not zero # if [ "$exit_code" -ne "0" ]; then PS1+=",${c_error}rc=${exit_code}" fi # # Colors should be set here and surrounded with \[\]otherwise bash fails to # calculate prompt length. The text is set through PROMPT_COMMAND PS1+="${c_reset}\$ " # reset colors and print $ } fi