Created
March 25, 2014 09:57
-
-
Save ingmar/9758394 to your computer and use it in GitHub Desktop.
Ingmar's fish_prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fish_prompt --description 'Ingmar\'s fish_prompt' | |
set -l last_status $status | |
# If previous command had a non-zero exit status, display it. | |
set -l last_status_string "" | |
if [ $last_status -ne 0 ] | |
printf "🔴 %s%d%s\n" (set_color red --bold) $last_status (set_color normal) | |
end | |
# If previous command ran for a non-negligible amount of time, show how long. | |
if set -q CMD_DURATION | |
printf "%s⌚️ %s%s\n" (set_color 777) $CMD_DURATION (set_color normal) | |
end | |
# Show number of background jobs. | |
set -l num_jobs (jobs|wc -l) | |
set jobs_prompt "" | |
if [ $num_jobs -ne 0 ] | |
set jobs_prompt (printf "%s🔷 %d%s " (set_color 28F) $num_jobs (set_color normal)) | |
end | |
# Just calculate these once, to save a few cycles when displaying the prompt | |
if not set -q __fish_prompt_hostname | |
set -g __fish_prompt_hostname (hostname|cut -d . -f 1) | |
# tell virtualenv not to mess with the prompt (do it here so it only gets run once) | |
set -gx VIRTUAL_ENV_DISABLE_PROMPT "yes" | |
end | |
if not set -q __fish_prompt_normal | |
set -g __fish_prompt_normal (set_color normal) | |
end | |
set -l user_prompt "\$" | |
switch $USER | |
# Set our root colors, if we're root :) | |
case root | |
set user_prompt '#' | |
if not set -q __fish_prompt_cwd | |
if set -q fish_color_cwd_root | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd_root) | |
else | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd) | |
end | |
end | |
case '*' | |
if not set -q __fish_prompt_cwd | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd) | |
end | |
end | |
if set -q VIRTUAL_ENV | |
printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) | |
end | |
printf '%s@%s ' $USER $__fish_prompt_hostname | |
printf '%s%s%s%s%s%s ' $jobs_prompt "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $user_prompt | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment