dotfiles/dotfiles/lib/zsh/prompt.sh

139 lines
3.7 KiB
Bash
Raw Normal View History

##### COLOR SETUP
autoload -U colors && colors
# P.C. Shyamshankar <sykora@lucentbeing.com>
# Copied from
# http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
typeset -Ag FX FG BG
FX=(
reset "%{%}"
bold "%{%}" no-bold "%{%}"
italic "%{%}" no-italic "%{%}"
underline "%{%}" no-underline "%{%}"
blink "%{%}" no-blink "%{%}"
reverse "%{%}" no-reverse "%{%}"
)
for color in {000..255}; do
FG[$color]="%{[38;5;${color}m%}"
BG[$color]="%{[48;5;${color}m%}"
done
# Show all 256 colors with color number
2014-11-11 14:25:47 -08:00
function spectrum_ls {
for code in {000..255}; do
print -P -- "$code: %{$FG[$code]Test%f%}"
done
}
#####
2014-11-11 14:25:47 -08:00
function current_directory {
2014-04-08 04:25:57 -07:00
local PWD=$(pwd)
echo "${PWD/#$HOME/~}"
}
2014-11-11 14:25:47 -08:00
function git_prompt_info {
if test -z $(git branch-or-sha);
2014-04-08 04:25:57 -07:00
then
echo ""
else
2014-10-22 20:55:57 -07:00
local b="$(print_with_color $(git branch-or-sha) $SOURCE_CONTROL_COLOR)"
echo " $(separator "on") $b$(git_status_character)"
2014-04-08 04:25:57 -07:00
fi
}
2014-11-11 14:25:47 -08:00
function git_status_character {
if git dirty;
2014-04-08 11:00:25 -07:00
then
2014-10-22 20:55:57 -07:00
print_with_color "✘" "$fg[red]"
2014-04-08 11:00:25 -07:00
else
2014-10-22 20:55:57 -07:00
print_with_color "✔" "$fg[green]"
2014-04-08 11:00:25 -07:00
fi
}
2014-11-11 14:25:47 -08:00
function command_line_character {
if ! test -z $(git branch-or-sha);
then
echo "±"
else
echo "○"
fi
}
function job_count {
jobs -s | wc -l
}
function colored_job_count {
local job_count="$(job_count)"
if [ $job_count -gt 0 ]; then
print_with_color "($job_count) " $JOB_COUNT_COLOR
fi
}
2014-11-11 14:25:47 -08:00
export PROMPT_CHAR_ERROR="$fg[red]"
export PROMPT_CHAR_SUCCESS="$fg[green]"
function prompt_custom_colors {
export USERNAME_COLOR="$FG[040]"
export SEPARATOR_COLOR="$FG[239]"
export HOSTNAME_COLOR="$FG[033]"
export CURRENT_DIRECTORY_COLOR="$FG[226]"
2014-10-22 20:55:57 -07:00
export CURRENT_DIRECTORY_COLOR="$FG[255]"
}
2014-11-11 14:25:47 -08:00
function prompt_basic_colors {
export USERNAME_COLOR="$fg_no_bold[green]"
export SEPARATOR_COLOR="$fg_no_bold[black]"
export HOSTNAME_COLOR="$fg_no_bold[blue]"
export CURRENT_DIRECTORY_COLOR="$fg[yellow]"
2014-10-22 20:55:57 -07:00
export SOURCE_CONTROL_COLOR="$fg[white]"
}
2014-11-11 14:25:47 -08:00
function prompt_solarized_colors {
2014-10-22 20:55:57 -07:00
prompt_basic_colors
export HOSTNAME_COLOR="$fg[magenta]"
export USERNAME_COLOR="$fg[blue]"
export CURRENT_DIRECTORY_COLOR="$fg[red]"
export SOURCE_CONTROL_COLOR="$fg[white]"
}
2014-11-11 14:25:47 -08:00
function prompt_tomorrow_colors {
2014-10-22 22:15:30 -07:00
export SEPARATOR_COLOR="$fg[cyan]"
export HOSTNAME_COLOR="$fg[yellow]"
export USERNAME_COLOR="$fg[blue]"
export CURRENT_DIRECTORY_COLOR="$fg[red]"
export SOURCE_CONTROL_COLOR="$fg[white]"
}
2014-11-11 14:25:47 -08:00
function prompt_monokai_colors {
2014-10-24 05:04:38 -07:00
export SEPARATOR_COLOR="$fg[black]"
export HOSTNAME_COLOR="$fg[blue]"
export USERNAME_COLOR="$fg[red]"
export CURRENT_DIRECTORY_COLOR="$fg[magenta]"
export SOURCE_CONTROL_COLOR="$fg[white]"
}
2014-11-11 14:25:47 -08:00
function prompt_basic_colors_with_grey_separator {
prompt_basic_colors
export SEPARATOR_COLOR="$FG[239]"
}
2014-11-11 14:25:47 -08:00
function print_with_color {
echo "%{$2%}$1%{$reset_color%}"
}
2014-11-11 14:25:47 -08:00
function separator {
print_with_color "$1" "$SEPARATOR_COLOR"
}
export JOB_COUNT_COLOR="$fg[blue]"
prompt_tomorrow_colors
# For reasons which are currently beyond me, it is not possible to use
# $? in PROMPT which is why the second line is so strangely
# constructed.
export PROMPT='⚡ % $(print_with_color "%n" "$USERNAME_COLOR") $(separator "at") $(print_with_color "`hostname -s`" "$HOSTNAME_COLOR") $(separator "in") $(print_with_color "`current_directory`" "$CURRENT_DIRECTORY_COLOR")$(git_prompt_info)
$(colored_job_count)%(?.$(print_with_color "$(command_line_character) " $PROMPT_CHAR_SUCCESS).$(print_with_color "$(command_line_character) " $PROMPT_CHAR_ERROR)) '
2014-04-08 05:56:26 -07:00
PS2='(%_) '