Created
December 30, 2017 23:01
-
-
Save ToniRib/3950b672a3f616f7c96e5bd8a41d6577 to your computer and use it in GitHub Desktop.
Current terminal prompt & informative git 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
LOOKS LIKE: 04:01:13PM photo-viewer on master ↑2✓ | |
function fish_prompt --description 'Write out the prompt' | |
set -l last_status $status | |
set_color e22265 | |
printf (date "+%I:%M:%S%p ") | |
set_color normal | |
set_color -o f18f1b | |
echo -n (basename $PWD) | |
set_color normal | |
echo -n ' ' | |
__informative_git_prompt | |
if not test $last_status -eq 0 | |
set_color $fish_color_error | |
end | |
echo ' ' | |
set_color -o yellow | |
echo -n ' ➾ ' | |
set_color normal | |
end | |
function fish_right_prompt -d "Right side fish prompt" | |
set_color ffbf00 | |
echo -n (~/.rvm/bin/rvm-prompt) | |
end | |
# | |
# Written by Mariusz Smykula <mariuszs at gmail.com> | |
# | |
# This is fish port of Informative git prompt for bash (https://github.com/magicmonty/bash-git-prompt) | |
# | |
set -g fish_color_git_clean 9ecc24 | |
set -g fish_color_git_branch 9ecc24 | |
set -g fish_color_git_remote 9ecc24 | |
set -g fish_color_git_staged yellow | |
set -g fish_color_git_conflicted red | |
set -g fish_color_git_changed 62D5D3 | |
set -g fish_color_git_untracked $fish_color_normal | |
set -g fish_prompt_git_remote_ahead_of "↑" | |
set -g fish_prompt_git_remote_behind "↓" | |
set -g fish_prompt_git_status_staged "•" | |
set -g fish_prompt_git_status_conflicted '✘' | |
set -g fish_prompt_git_status_changed '+' | |
set -g fish_prompt_git_status_untracked "…" | |
set -g fish_prompt_git_status_clean "✓" | |
set -g fish_prompt_git_show_count_staged "true" | |
set -g fish_prompt_git_show_count_conflicted "true" | |
set -g fish_prompt_git_show_count_changed "true" | |
set -g fish_prompt_git_show_count_untracked "false" | |
set -g fish_prompt_git_show_count_clean "true" | |
set -g fish_prompt_git_status_git_dir "*" | |
set -g fish_prompt_git_remote_space "" | |
set -g fish_prompt_git_status_order staged conflicted changed untracked | |
function __informative_git_prompt --description 'Write out the git prompt' | |
set -l is_inside_work_tree (git rev-parse --is-inside-work-tree ^/dev/null ) | |
if test -z $is_inside_work_tree | |
return | |
end | |
if test "true" = $is_inside_work_tree | |
set git_status_info (___fish_git_print_status_info) | |
else | |
set git_status_info (set_color -o $fish_color_git_clean)$fish_prompt_git_status_git_dir(set_color $fish_color_normal) | |
end | |
set_color d4decf | |
echo -n 'on ' | |
set_color normal | |
printf "%s%s" (___fish_git_print_branch_info) $git_status_info | |
end | |
function ___fish_git_print_branch_info | |
set -l color_branch (set_color -o $fish_color_git_branch) | |
set -l color_normal (set_color $fish_color_normal) | |
set -l branch (git symbolic-ref -q HEAD | cut -c 12-) | |
set -l remote_info | |
if test -z $branch | |
set -l hash (git rev-parse --short HEAD | cut -c 2-) | |
set branch ":"$hash | |
else | |
set remote_info (___fish_git_print_remote_info $branch) | |
end | |
echo "$color_branch$branch $color_normal$remote_info" | |
end | |
function ___fish_git_print_status_info | |
set -l color_normal (set_color $fish_color_normal) | |
set -l color_git_clean (set_color -o $fish_color_git_clean) | |
set -l changedFiles (git diff --name-status | cut -c 1-2) | |
set -l stagedFiles (git diff --staged --name-status | cut -c 1-2) | |
set -l changed (math (count $changedFiles) - (count (echo $changedFiles | grep "U"))) | |
set -l conflicted (count (echo $stagedFiles | grep "U")) | |
set -l staged (math (count $stagedFiles) - $conflicted) | |
set -l untracked (count (git ls-files --others --exclude-standard)) | |
if [ (math $changed + $conflicted + $staged + $untracked) = 0 ] | |
set git_status $color_git_clean$fish_prompt_git_status_clean$color_normal | |
else | |
for i in $fish_prompt_git_status_order | |
if [ $$i != "0" ] | |
set -l color_name fish_color_git_$i | |
set -l status_name fish_prompt_git_status_$i | |
set -l color (set_color $$color_name) | |
set -l visible fish_prompt_git_show_count_$i | |
set -l info | |
if [ "true" = $$visible ] | |
set info $$status_name$$i | |
else | |
set info $$status_name | |
end | |
set git_status "$git_status$color$info" | |
end | |
end | |
end | |
echo $git_status$color_normal | |
end | |
function ___fish_git_print_remote_info | |
set color_remote (set_color -o $fish_color_git_remote) | |
set color_normal (set_color $fish_color_normal) | |
set -l branch $argv[1] | |
set -l remote (____fish_git_remote_info $branch) | |
set -l ahead $remote[1] | |
set -l behind $remote[2] | |
set -l remote_info | |
if [ $ahead != "0" ] | |
set remote_info $color_remote$fish_prompt_git_remote_ahead_of$color_normal$ahead | |
end | |
if [ $behind != "0" ] | |
set remote_info $remote_info$color_remote$fish_prompt_git_remote_behind$color_normal$behind | |
end | |
if test -n "$remote_info" | |
echo "$fish_prompt_git_remote_space$remote_info" | |
end | |
end | |
function ____fish_git_remote_info | |
set -l branch $argv[1] | |
set -l remote_name (git config branch.$branch.remote) | |
if test -n "$remote_name" | |
set merge_name (git config branch.$branch.merge) | |
set merge_name_short (echo $merge_name | cut -c 12-) | |
else | |
set remote_name "origin" | |
set merge_name "refs/heads/$branch" | |
set merge_name_short $branch | |
end | |
if [ $remote_name = '.' ] # local | |
set remote_ref $merge_name | |
else | |
set remote_ref "refs/remotes/$remote_name/$merge_name_short" | |
end | |
set -l rev_git (eval "git rev-list --left-right $remote_ref...HEAD" ^/dev/null) | |
if test $status != "0" | |
set rev_git (eval "git rev-list --left-right $merge_name...HEAD" ^/dev/null) | |
end | |
for i in $rev_git | |
if echo $i | grep '>' >/dev/null | |
set isAhead $isAhead ">" | |
end | |
end | |
set -l remote_diff (count $rev_git) | |
set -l ahead (count $isAhead) | |
set -l behind (math $remote_diff - $ahead) | |
echo $ahead | |
echo $behind | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment