From af46655855c8a1e91500f0db7face27d1b9eafd2 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 13 Feb 2020 14:15:23 -0500 Subject: [PATCH] Change fish theme --- fish/.config/fish/fishfile | 1 + fish/.config/fish/functions/bass.fish | 8 +- .../.config/fish/functions/fish_greeting.fish | 8 + fish/.config/fish/functions/fish_prompt.fish | 140 ++++++++++++++---- .../fish/functions/fish_right_prompt.fish | 3 + fish/.config/fish/functions/fish_title.fish | 4 + 6 files changed, 136 insertions(+), 28 deletions(-) create mode 100644 fish/.config/fish/functions/fish_greeting.fish create mode 100644 fish/.config/fish/functions/fish_right_prompt.fish create mode 100644 fish/.config/fish/functions/fish_title.fish diff --git a/fish/.config/fish/fishfile b/fish/.config/fish/fishfile index b9ab372..f1f8ac3 100644 --- a/fish/.config/fish/fishfile +++ b/fish/.config/fish/fishfile @@ -5,3 +5,4 @@ oh-my-fish/plugin-direnv joseluisq/gitnow fishpkg/fish-git-util oh-my-fish/theme-krisleech +lfiolhais/theme-simple-ass-prompt diff --git a/fish/.config/fish/functions/bass.fish b/fish/.config/fish/functions/bass.fish index 56e1c39..7ce2ac3 100644 --- a/fish/.config/fish/functions/bass.fish +++ b/fish/.config/fish/functions/bass.fish @@ -7,7 +7,11 @@ function bass end set -l script_file (mktemp) - python (dirname (status -f))/__bass.py $bash_args 3>$script_file + if command -v python3 >/dev/null 2>&1 + command python3 (dirname (status -f))/__bass.py $bash_args 3>$script_file + else + command python (dirname (status -f))/__bass.py $bash_args 3>$script_file + end set -l bass_status $status if test $bass_status -ne 0 return $bass_status @@ -17,7 +21,7 @@ function bass cat $script_file end source $script_file - /bin/rm $script_file + command rm $script_file end function __bass_usage diff --git a/fish/.config/fish/functions/fish_greeting.fish b/fish/.config/fish/functions/fish_greeting.fish new file mode 100644 index 0000000..cc89aed --- /dev/null +++ b/fish/.config/fish/functions/fish_greeting.fish @@ -0,0 +1,8 @@ +# Configure greeting with: +# -> set -g simple_ass_prompt_greeting MyGreeting + +function fish_greeting + set -q simple_ass_prompt_greeting; or set -l simple_ass_prompt_greeting 'Where the hell is Science?!' + + echo $simple_ass_prompt_greeting +end diff --git a/fish/.config/fish/functions/fish_prompt.fish b/fish/.config/fish/functions/fish_prompt.fish index ce2b1bc..acbd82c 100644 --- a/fish/.config/fish/functions/fish_prompt.fish +++ b/fish/.config/fish/functions/fish_prompt.fish @@ -1,31 +1,119 @@ -# name: Krisleech -function _git_branch_name - echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||') -end +# Status Chars +set __fish_git_prompt_char_dirtystate '!' +set __fish_git_prompt_char_untrackedfiles '☡' +set __fish_git_prompt_char_stashstate '↩' +set __fish_git_prompt_char_cleanstate '✓' -function _is_git_dirty - echo (command git status -s --ignore-submodules=dirty 2> /dev/null) -end +# Display the state of the branch when inside of a git repo +function __simple_ass_prompt_parse_git_branch_state -d "Display the state of the branch" + git update-index --really-refresh -q 1> /dev/null -function fish_prompt - set -l cyan (set_color -o cyan) - set -l yellow (set_color -o yellow) - set -l red (set_color -o red) - set -l blue (set_color -o blue) - set -l green (set_color -o green) - set -l normal (set_color normal) - - set -l cwd $cyan(basename (prompt_pwd)) - - if [ (_git_branch_name) ] - set -l git_branch (_git_branch_name) - set git_info "$green$git_branch " - - if [ (_is_git_dirty) ] - set -l dirty "$yellow✗" - set git_info "$git_info$dirty" - end + # Check for changes to be commited + if git_is_touched + echo -n "$__fish_git_prompt_char_dirtystate" + else + echo -n "$__fish_git_prompt_char_cleanstate" end - echo -n -s $cwd $red '|' $git_info $normal ⇒ ' ' $normal + # Check for untracked files + set -l git_untracked (command git ls-files --others --exclude-standard 2> /dev/null) + if [ -n "$git_untracked" ] + echo -n "$__fish_git_prompt_char_untrackedfiles" + end + + # Check for stashed files + if git_is_stashed + echo -n "$__fish_git_prompt_char_stashstate" + end + + # Check if branch is ahead, behind or diverged of remote + git_ahead +end + +# Display current git branch +function __simple_ass_prompt_git -d "Display the actual git branch" + set -l ref + set -l std_prompt (prompt_pwd) + set -l is_dot_git (string match '*/.git' $std_prompt) + + if git_is_repo; and test -z $is_dot_git + printf 'on ' + set_color purple + + set -l git_branch (command git symbolic-ref --quiet --short HEAD 2> /dev/null; or git rev-parse --short HEAD 2> /dev/null; or echo -n '(unknown)') + + printf '%s ' $git_branch + + set state (__simple_ass_prompt_parse_git_branch_state) + set_color 0087ff + printf '[%s]' $state + + set_color normal + end +end + +# Print current user +function __simple_ass_prompt_get_user -d "Print the user" + if test $USER = 'root' + set_color red + else + set_color d75f00 + end + printf '%s' (whoami) +end + +# Get Machines Hostname +function __simple_ass_prompt_get_host -d "Get Hostname" + if test $SSH_TTY + tput bold + set_color red + else + set_color af8700 + end + printf '%s' (hostname|cut -d . -f 1) +end + +# Get Project Working Directory +function __simple_ass_prompt_pwd -d "Get PWD" + set_color $fish_color_cwd + printf '%s ' (prompt_pwd) +end + +# Simple-ass-prompt +function fish_prompt + set -l code $status + + # Logged in user + __simple_ass_prompt_get_user + set_color normal + printf ' at ' + + # Machine logged in to + __simple_ass_prompt_get_host + set_color normal + printf ' in ' + + # Path + __simple_ass_prompt_pwd + set_color normal + + # Git info + __simple_ass_prompt_git + + # Line 2 + echo + if test -e "Cargo.toml" + printf "(rust:%s) " (set_color red)(rustup show | tail -n 3 | head -n 1 | cut -d '-' -f 1)(set_color normal) + end + + if test $VIRTUAL_ENV + printf "(python:%s) " (set_color blue)(basename $VIRTUAL_ENV)(set_color normal) + end + + if test $code -eq 127 + set_color red + end + + printf '↪ ' + set_color normal end diff --git a/fish/.config/fish/functions/fish_right_prompt.fish b/fish/.config/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..a8df57c --- /dev/null +++ b/fish/.config/fish/functions/fish_right_prompt.fish @@ -0,0 +1,3 @@ +function fish_right_prompt + +end diff --git a/fish/.config/fish/functions/fish_title.fish b/fish/.config/fish/functions/fish_title.fish new file mode 100644 index 0000000..7212ca6 --- /dev/null +++ b/fish/.config/fish/functions/fish_title.fish @@ -0,0 +1,4 @@ +function fish_title + # Customize the title bar of the terminal window. + printf '%s' (prompt_pwd) +end