Last active
November 5, 2015 15:23
-
-
Save korotin/e582f3e31367a2527624 to your computer and use it in GitHub Desktop.
My fish prompt with system load, bg jobs count and current git branch name
This file contains hidden or 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 get_git_branch | |
set -g git_branch (git rev-parse --abbrev-ref HEAD ^ /dev/null) | |
if [ $status -ne 0 ] | |
set -ge git_branch | |
end | |
end | |
function get_system_load | |
set -g system_load (uptime | grep -oE 'average\: [[:digit:]]+\.[[:digit:]]+' | cut -d' ' -f2) | |
end | |
function get_bg_jobs | |
set -g bg_jobs (jobs | wc -l) | |
end | |
function fish_prompt | |
# 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. -f1) | |
end | |
if not set -q __fish_prompt_normal | |
set -g __fish_prompt_normal (set_color normal) | |
end | |
get_system_load | |
get_bg_jobs | |
get_git_branch | |
if set -q git_branch | |
set prompt_git_branch (set_color red) ' (' $git_branch ') ' | |
else | |
set prompt_git_branch ' ' | |
end | |
switch $USER | |
case root | |
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 | |
echo -n -s (set_color red) "$USER" @ "$__fish_prompt_hostname" (set_color yellow) ' ' $bg_jobs ' ' $system_load ' ' "$__fish_prompt_cwd" (prompt_pwd) $prompt_git_branch "$__fish_prompt_normal" '# ' | |
case '*' | |
if not set -q __fish_prompt_cwd | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd) | |
end | |
echo -n -s (set_color red) "$USER" @ "$__fish_prompt_hostname" (set_color yellow) ' ' $bg_jobs ' ' $system_load ' ' "$__fish_prompt_cwd" (prompt_pwd) $prompt_git_branch "$__fish_prompt_normal" '> ' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment