Created
July 16, 2019 18:59
-
-
Save byurhannurula/c34e5cd4c1d208e2f2b6d4eb8a740cfa to your computer and use it in GitHub Desktop.
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
# name: simply | |
# Colors | |
set cyan (set_color cyan) | |
set yellow (set_color yellow) | |
set red (set_color red) | |
set blue (set_color blue) | |
set green (set_color green) | |
set orange (set_color ff8300) | |
set gray (set_color 666666) | |
set white (set_color white) | |
# Git Characters | |
set git_prompt_dirtystate '*' | |
set git_prompt_up_down '⇡⇣' | |
set git_prompt_up_arrow '⇡' | |
set git_prompt_down_arrow '⇣' | |
function _git_branch_name | |
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') | |
end | |
function _git_is_dirty --description "Check if directory is dirty" | |
echo (command git status -s --ignore-submodules=dirty ^/dev/null) | |
end | |
function _prompt_pwd --description "Print the current working directory, shortened to fit the prompt" | |
# This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it | |
set -q fish_prompt_pwd_dir_length | |
or set -l fish_prompt_pwd_dir_length 1 | |
# Replace $HOME with "~" | |
set realhome ~ | |
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) | |
# Uncoment if/else statement to shorten path | |
if [ $fish_prompt_pwd_dir_length -eq 0 ] | |
echo $tmp | |
else | |
# Shorten to at most $fish_prompt_pwd_dir_length characters per directory | |
string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp | |
end | |
end | |
function fish_prompt | |
set -l last_status $status | |
# Output the prompt, left to right | |
# Display [venvname] if in a virtualenv | |
if set -q VIRTUAL_ENV | |
echo -n -s (set_color -b cyan black) '[' (basename "$VIRTUAL_ENV") ']' $white ' ' | |
end | |
# Set and Print pwd or full path | |
set -l cwd $yellow(_prompt_pwd) | |
echo -n -s $cwd $white | |
# Show git branch and status | |
if [ (_git_branch_name) ] | |
set -l git_branch (_git_branch_name) | |
if [ (_git_is_dirty) ] | |
set git_info $gray 'git:(' $red $git_branch ' ' $red $git_prompt_dirtystate $gray ')' | |
# set git_info $red '(' $red $git_branch $red ')' | |
else | |
set git_info $gray 'git:(' $gray $git_branch $gray ')' | |
# set git_info $green '(' $green $git_branch $green ')' | |
end | |
# echo -n -s ' ' $git_info $white | |
echo -n -s ' on ' $git_info $white | |
end | |
set -l prompt_color $red | |
if test $last_status = 0 | |
set prompt_color $white | |
end | |
# Terminate with a nice prompt char ❯ | |
echo -n -s $prompt_color ' $ ' $white | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment