2013-09-17 23:17:15 -07:00
# name: bobthefish
#
# bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome.
#
2015-10-27 22:05:01 +04:00
# You will need a Powerline-patched font for this to work:
2013-09-17 23:17:15 -07:00
#
2016-02-20 02:10:06 -05:00
# https://powerline.readthedocs.org/en/master/installation.html#patched-fonts
2013-09-17 23:17:15 -07:00
#
# I recommend picking one of these:
#
# https://github.com/Lokaltog/powerline-fonts
#
2016-02-18 22:00:31 -08:00
# For more advanced awesome, install a nerd fonts patched font (and be sure to
# enable nerd fonts support with `set -g theme_nerd_fonts yes`):
#
# https://github.com/ryanoasis/nerd-fonts
#
2024-03-05 17:57:16 -05:00
# See README.md for setup and configuration options.
2013-09-17 23:17:15 -07:00
#
2017-12-19 08:32:59 -08:00
# ==============================
# Helper methods
# ==============================
2014-11-16 17:47:15 +07:00
2017-12-23 18:26:29 -08:00
function __bobthefish_basename -d 'basically basename, but faster'
2019-01-13 09:56:20 -08:00
string replace -r '^.*/' '' -- $argv
2017-12-23 18:26:29 -08:00
end
function __bobthefish_dirname -d 'basically dirname, but faster'
2019-01-13 09:56:20 -08:00
string replace -r '/[^/]+/?$' '' -- $argv
2017-12-23 18:26:29 -08:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_pwd -d 'Get a normalized $PWD'
# The pwd builtin accepts `-P` on at least Fish 3.x, but fall back to $PWD if that doesn't work
builtin pwd -P 2 > /dev/null
or echo $PWD
end
2020-03-17 20:53:48 -07:00
# Note that for fish < 3.0 this falls back to unescaped, rather than trying to do something clever /shrug
# After we drop support for older fishies, we can inline this without the fallback.
function __bobthefish_escape_regex -a str -d 'A backwards-compatible `string escape --style=regex` implementation'
string escape --style = regex " $str " 2 > /dev/null
or echo " $str "
end
2026-05-14 23:27:16 -04:00
function __bobthefish_version_at_least -S -a required -a actual -d 'Compare dotted numeric versions'
set -l required_parts ( string split . -- " $required " )
set -l actual_parts ( string split . -- " $actual " )
for i in 1 2 3
set -l required_part $required_parts [ $i ]
set -l actual_part $actual_parts [ $i ]
[ - n " $required_part " ]
or set required_part 0
[ - n " $actual_part " ]
or set actual_part 0
if [ $actual_part - gt $required_part ]
return 0
else if [ $actual_part - lt $required_part ]
return 1
end
end
return 0
end
2026-05-15 02:33:01 -04:00
__bobthefish_git_async_init
2013-09-17 23:17:15 -07:00
2024-04-18 22:44:45 -04:00
function __bobthefish_fossil_branch -S -d 'Get the current fossil branch'
2024-04-20 19:28:26 -04:00
set -l branch ( command fossil branch 2 > /dev/null | string trim --left --chars = ' *' )
2024-04-18 22:44:45 -04:00
echo " $branch_glyph $branch "
end
2016-01-25 07:06:48 -08:00
function __bobthefish_hg_branch -S -d 'Get the current hg branch'
2019-01-13 09:56:20 -08:00
set -l branch ( command hg branch 2 > /dev/null)
2026-05-14 23:27:16 -04:00
set -l book ( command hg book 2 > /dev/null | string replace --filter -r '^\s*\*\s+(\S+).*' '$1' )
2019-01-13 09:56:20 -08:00
echo " $branch_glyph $branch @ $book "
2014-11-16 17:47:15 +07:00
end
2019-01-13 10:02:32 -08:00
function __bobthefish_pretty_parent -S -a child_dir -d 'Print a parent directory, shortened to fit the prompt'
2019-01-13 09:56:20 -08:00
set -q fish_prompt_pwd_dir_length
2016-12-29 16:12:55 -08:00
or set -l fish_prompt_pwd_dir_length 1
2019-01-13 09:56:20 -08:00
# Replace $HOME with ~
set -l real_home ~
2020-03-17 21:09:15 -07:00
set -l parent_dir ( string replace -r '^' ( __bobthefish_escape_regex " $real_home " ) '($|/)' '~$1' ( __bobthefish_dirname $child_dir ) )
2016-12-29 16:12:55 -08:00
2019-01-13 09:56:20 -08:00
# Must check whether `$parent_dir = /` if using native dirname
if [ - z " $parent_dir " ]
echo -n /
return
end
2016-12-29 16:12:55 -08:00
2019-01-13 09:56:20 -08:00
if [ $fish_prompt_pwd_dir_length - eq 0 ]
echo -n " $parent_dir / "
return
end
2016-12-29 16:12:55 -08:00
2019-01-13 09:56:20 -08:00
string replace -ar '(\.?[^/]{' " $fish_prompt_pwd_dir_length " '})[^/]*/' '$1/' " $parent_dir / "
2013-09-17 23:17:15 -07:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_ignore_vcs_dir -a real_pwd -d 'Check whether the current directory should be ignored as a VCS segment'
2019-01-13 09:56:20 -08:00
for p in $theme_vcs_ignore_paths
set ignore_path ( realpath $p 2 > /dev/null)
2019-01-13 10:46:50 -08:00
switch $real_pwd /
2019-01-13 09:56:20 -08:00
case $ignore_path /\*
echo 1
return
end
2017-12-23 19:52:07 -08:00
end
2017-10-26 14:27:08 +02:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_git_project_dir -S -a real_pwd -d 'Print the current git project base directory'
2026-05-14 23:21:23 -04:00
[ " $theme_display_git " = no ]
2019-01-13 09:56:20 -08:00
and return
2017-12-19 06:52:08 -08:00
2024-04-20 23:58:40 -04:00
command -q git
or return
2019-01-13 09:56:20 -08:00
set -q theme_vcs_ignore_paths
2019-03-18 07:43:13 -07:00
and [ ( __bobthefish_ignore_vcs_dir $real_pwd ) ]
2017-12-19 06:52:08 -08:00
and return
2017-10-26 14:27:08 +02:00
2026-05-14 23:21:23 -04:00
if [ " $theme_git_worktree_support " != yes ]
2019-01-13 11:24:41 -08:00
set -l git_toplevel ( command git rev-parse --show-toplevel 2 > /dev/null)
[ - z " $git_toplevel " ]
and return
2024-04-01 22:34:48 -04:00
## Support Git under WSL (see #336)
# command -q wslpath
# and set git_toplevel (command wslpath $git_toplevel)
2019-01-13 11:24:41 -08:00
# If there are no symlinks, just use git toplevel
2019-03-18 07:43:13 -07:00
switch $real_pwd /
2019-01-13 11:24:41 -08:00
case $git_toplevel /\*
echo $git_toplevel
return
end
# Otherwise, we need to find the equivalent directory in the $PWD
2019-03-18 07:43:13 -07:00
set -l d $real_pwd
2019-01-13 11:24:41 -08:00
while not [ - z " $d " ]
if [ ( realpath " $d " ) = " $git_toplevel " ]
echo $d
return
end
2026-05-14 23:21:23 -04:00
[ " $d " = / ]
2019-01-13 11:24:41 -08:00
and return
set d ( __bobthefish_dirname $d )
end
2019-01-13 09:56:20 -08:00
return
end
2016-03-30 16:57:34 -07:00
2019-01-13 09:56:20 -08:00
set -l git_dir ( command git rev-parse --git-dir 2 > /dev/null)
or return
2016-03-30 16:57:34 -07:00
2019-01-13 09:56:20 -08:00
pushd $git_dir
2023-06-16 09:40:21 +02:00
set git_dir ( __bobthefish_pwd )
2019-01-13 09:56:20 -08:00
popd
2016-03-30 16:57:34 -07:00
2019-03-18 07:43:13 -07:00
switch $real_pwd /
2019-01-13 09:56:20 -08:00
case $git_dir /\*
# Nothing works quite right if we're inside the git dir
# TODO: fix the underlying issues then re-enable the stuff below
# # if we're inside the git dir, sweet. just return that.
# set -l toplevel (command git rev-parse --show-toplevel 2>/dev/null)
# if [ "$toplevel" ]
# switch $git_dir/
# case $toplevel/\*
# echo $git_dir
# end
# end
return
end
2016-03-30 16:57:34 -07:00
2019-01-13 09:56:20 -08:00
set -l project_dir ( __bobthefish_dirname $git_dir )
2016-03-30 16:57:34 -07:00
2019-03-18 07:43:13 -07:00
switch $real_pwd /
2019-01-13 09:56:20 -08:00
case $project_dir /\*
echo $project_dir
return
end
2016-03-30 16:57:34 -07:00
2019-01-13 09:56:20 -08:00
set project_dir ( command git rev-parse --show-toplevel 2 > /dev/null)
2019-03-18 07:43:13 -07:00
switch $real_pwd /
2019-01-13 09:56:20 -08:00
case $project_dir /\*
echo $project_dir
end
2013-09-17 23:17:15 -07:00
end
2024-04-18 22:44:45 -04:00
function __bobthefish_fossil_project_dir -S -a real_pwd -d 'Print the current fossil project base directory'
2026-05-14 23:21:23 -04:00
[ " $theme_display_fossil " = yes ]
2024-04-20 23:54:33 -04:00
and command -q fossil
2026-05-14 23:27:16 -04:00
and set -f dir ( command fossil json status 2 > /dev/null | string replace --filter -r '^\s*"localRoot"\s*:\s*"([^"]*)".*' '$1' | string trim --chars = /)
2024-04-18 22:44:45 -04:00
or return
set -q theme_vcs_ignore_paths
and [ ( __bobthefish_ignore_vcs_dir $real_pwd ) ]
and return
2024-04-20 20:59:55 -04:00
echo " / $dir "
2024-04-18 22:44:45 -04:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_hg_project_dir -S -a real_pwd -d 'Print the current hg project base directory'
2026-05-14 23:21:23 -04:00
[ " $theme_display_hg " = yes ]
2024-04-20 23:54:33 -04:00
and command -q hg
2019-01-13 09:56:20 -08:00
or return
2017-12-19 06:52:08 -08:00
2019-01-13 09:56:20 -08:00
set -q theme_vcs_ignore_paths
2019-03-18 07:43:13 -07:00
and [ ( __bobthefish_ignore_vcs_dir $real_pwd ) ]
2017-12-19 06:52:08 -08:00
and return
2017-10-26 14:27:08 +02:00
2019-03-18 07:43:13 -07:00
set -l d $real_pwd
2019-01-13 09:56:20 -08:00
while not [ - z " $d " ]
if [ - e $d /.hg ]
command hg root --cwd " $d " 2 > /dev/null
return
end
2026-05-14 23:21:23 -04:00
[ " $d " = / ]
2019-01-13 09:56:20 -08:00
and return
set d ( __bobthefish_dirname $d )
2014-11-23 11:36:12 -08:00
end
2014-11-16 17:47:15 +07:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_project_pwd -S -a project_root_dir -a real_pwd -d 'Print the working directory relative to project root'
2019-01-13 09:56:20 -08:00
set -q theme_project_dir_length
2016-12-29 16:12:55 -08:00
or set -l theme_project_dir_length 0
2020-03-17 20:53:48 -07:00
set -l project_dir ( string replace -r '^' ( __bobthefish_escape_regex " $project_root_dir " ) '($|/)' '' $real_pwd )
2016-12-29 16:12:55 -08:00
2019-01-13 09:56:20 -08:00
if [ $theme_project_dir_length - eq 0 ]
echo -n $project_dir
return
end
2016-12-29 16:12:55 -08:00
2019-01-13 09:56:20 -08:00
string replace -ar '(\.?[^/]{' " $theme_project_dir_length " '})[^/]*/' '$1/' $project_dir
2013-09-17 23:17:15 -07:00
end
2017-12-19 08:32:59 -08:00
# ==============================
2013-09-17 23:17:15 -07:00
# Segment functions
2017-12-19 08:32:59 -08:00
# ==============================
2013-09-17 23:17:15 -07:00
2016-01-25 07:06:48 -08:00
function __bobthefish_start_segment -S -d 'Start a prompt segment'
2019-01-13 09:56:20 -08:00
set -l bg $argv [ 1 ]
set -e argv [ 1 ]
set -l fg $argv [ 1 ]
set -e argv [ 1 ]
set_color normal # clear out anything bold or underline...
set_color -b $bg $fg $argv
switch " $__bobthefish_current_bg "
case ''
# If there's no background, just start one
echo -n ' '
case " $bg "
# If the background is already the same color, draw a separator
echo -ns $right_arrow_glyph ' '
case '*'
# otherwise, draw the end of the previous segment and the start of the next
set_color $__bobthefish_current_bg
echo -ns $right_black_arrow_glyph ' '
set_color $fg $argv
end
set __bobthefish_current_bg $bg
2013-09-17 23:17:15 -07:00
end
2024-03-05 15:20:50 -05:00
function __bobthefish_path_segment -S -a segment_dir -a path_type -d 'Display a shortened form of a directory'
2019-01-13 09:56:20 -08:00
set -l segment_color $color_path
set -l segment_basename_color $color_path_basename
2016-03-30 13:24:51 -07:00
2019-01-13 10:02:32 -08:00
if not [ - w " $segment_dir " ]
2019-01-13 09:56:20 -08:00
set segment_color $color_path_nowrite
set segment_basename_color $color_path_nowrite_basename
end
2013-09-17 23:17:15 -07:00
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $segment_color
2016-03-30 13:24:51 -07:00
2019-01-13 09:56:20 -08:00
set -l directory
set -l parent
2013-09-17 23:17:15 -07:00
2019-01-13 10:02:32 -08:00
switch " $segment_dir "
2019-01-13 09:56:20 -08:00
case /
2026-05-14 23:21:23 -04:00
set directory /
2019-01-13 09:56:20 -08:00
case " $HOME "
set directory '~'
case '*'
2019-01-13 10:02:32 -08:00
set parent ( __bobthefish_pretty_parent " $segment_dir " )
set directory ( __bobthefish_basename " $segment_dir " )
2019-01-13 09:56:20 -08:00
end
2013-09-17 23:17:15 -07:00
2026-05-14 23:21:23 -04:00
[ " $theme_show_project_parent " != no - o " $path_type " != project ]
2024-03-05 15:20:50 -05:00
and echo -n $parent
2019-01-13 09:56:20 -08:00
set_color -b $segment_basename_color
echo -ns $directory ' '
2013-09-17 23:17:15 -07:00
end
2016-01-25 07:06:48 -08:00
function __bobthefish_finish_segments -S -d 'Close open prompt segments'
2019-01-13 09:56:20 -08:00
if [ - n " $__bobthefish_current_bg " ]
set_color normal
set_color $__bobthefish_current_bg
echo -ns $right_black_arrow_glyph ' '
2017-06-10 22:51:14 -04:00
end
2016-02-03 23:10:57 -08:00
2026-05-14 23:21:23 -04:00
if [ " $theme_newline_cursor " = yes ]
2019-01-13 09:56:20 -08:00
echo -ens "\n"
set_color $fish_color_autosuggestion
2019-03-26 08:13:33 -07:00
if set -q theme_newline_prompt
echo -ens " $theme_newline_prompt "
2026-05-14 23:21:23 -04:00
else if [ " $theme_powerline_fonts " = no - a " $theme_nerd_fonts " != yes ]
2019-03-26 08:13:33 -07:00
echo -ns '> '
2019-01-13 09:56:20 -08:00
else
2019-03-26 08:13:33 -07:00
echo -ns " $right_arrow_glyph "
2019-01-13 09:56:20 -08:00
end
2026-05-14 23:21:23 -04:00
else if [ " $theme_newline_cursor " = clean ]
2019-01-13 09:56:20 -08:00
echo -ens "\n"
end
set_color normal
set __bobthefish_current_bg
2013-09-17 23:17:15 -07:00
end
2017-12-19 08:32:59 -08:00
# ==============================
2020-04-20 09:57:15 -07:00
# Status segment
2017-12-19 08:32:59 -08:00
# ==============================
2020-08-28 07:00:15 -07:00
function __bobthefish_prompt_status -S -a last_status -d 'Display flags for a non-zero exit status, private mode, root user, and background jobs'
2019-01-13 09:56:20 -08:00
set -l nonzero
set -l superuser
set -l bg_jobs
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
# Last exit was nonzero
[ $last_status - ne 0 ]
2018-02-20 22:20:50 -08:00
and set nonzero 1
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
# If superuser (uid == 0)
#
# Note that iff the current user is root and '/' is not writeable by root this
# will be wrong. But I can't think of a single reason that would happen, and
# it is literally 99.5% faster to check it this way, so that's a tradeoff I'm
# willing to make.
2019-10-26 21:01:54 -07:00
[ - w / - o - w /private/ ]
2017-12-23 15:15:59 -08:00
and [ ( id - u) - eq 0 ]
2018-02-20 22:20:50 -08:00
and set superuser 1
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
# Jobs display
2019-11-02 15:48:16 -07:00
if set -q AUTOJUMP_SOURCED
# Autojump special case: check if there are jobs besides the `autojump`
# job, since that one is (briefly) backgrounded every time we `cd`
2026-05-14 23:27:16 -04:00
set bg_jobs ( count ( jobs -c | string match -v --regex '(Command|autojump)' ) )
2019-10-11 16:56:47 +02:00
[ " $bg_jobs " - eq 0 ]
and set bg_jobs # clear it out so it doesn't show when `0`
else
2026-05-14 23:21:23 -04:00
if [ " $theme_display_jobs_verbose " = yes ]
2026-05-14 23:27:16 -04:00
set bg_jobs ( count ( jobs -p ) )
2019-11-02 15:48:16 -07:00
[ " $bg_jobs " - eq 0 ]
and set bg_jobs # clear it out so it doesn't show when `0`
else
# `jobs -p` is faster if we redirect to /dev/null, because it exits
# after the first match. We'll use that unless the user wants to
# display the actual job count
jobs -p > /dev/null
and set bg_jobs 1
end
2019-10-11 16:56:47 +02:00
end
2017-12-19 08:32:59 -08:00
2020-08-28 07:00:15 -07:00
if [ " $nonzero " - o " $fish_private_mode " - o " $superuser " - o " $bg_jobs " ]
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $color_initial_segment_exit
if [ " $nonzero " ]
set_color normal
set_color -b $color_initial_segment_exit
2026-05-14 23:21:23 -04:00
if [ " $theme_show_exit_status " = yes ]
2019-01-13 09:56:20 -08:00
echo -ns $last_status ' '
else
echo -n $nonzero_exit_glyph
end
end
2017-12-19 08:32:59 -08:00
2020-08-28 07:00:15 -07:00
if [ " $fish_private_mode " ]
set_color normal
set_color -b $color_initial_segment_private
echo -n $private_glyph
end
2019-01-13 09:56:20 -08:00
if [ " $superuser " ]
set_color normal
if [ - z " $FAKEROOTKEY " ]
set_color -b $color_initial_segment_su
else
set_color -b $color_initial_segment_exit
end
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
echo -n $superuser_glyph
end
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
if [ " $bg_jobs " ]
set_color normal
set_color -b $color_initial_segment_jobs
2026-05-14 23:21:23 -04:00
if [ " $theme_display_jobs_verbose " = yes ]
2019-10-10 22:12:47 +02:00
echo -ns $bg_job_glyph $bg_jobs ' '
else
echo -n $bg_job_glyph
end
2019-01-13 09:56:20 -08:00
end
2017-12-19 08:32:59 -08:00
end
end
# ==============================
# Container and VM segments
# ==============================
2013-09-17 23:17:15 -07:00
2016-01-25 07:06:48 -08:00
function __bobthefish_prompt_vagrant -S -d 'Display Vagrant status'
2026-05-14 23:21:23 -04:00
[ " $theme_display_vagrant " = yes - a - f Vagrantfile ]
2019-01-13 09:56:20 -08:00
or return
2016-08-25 12:18:10 -07:00
2019-01-13 09:56:20 -08:00
# .vagrant/machines/$machine/$provider/id
for file in .vagrant/machines/*/*/id
read -l id < " $file "
if [ - n " $id " ]
switch " $file "
case '*/virtualbox/id'
__bobthefish_prompt_vagrant_vbox $id
case '*/vmware_fusion/id'
__bobthefish_prompt_vagrant_vmware $id
case '*/parallels/id'
__bobthefish_prompt_vagrant_parallels $id
end
end
2016-08-22 21:35:20 +02:00
end
2016-02-18 23:14:13 -08:00
end
2016-08-22 21:35:20 +02:00
function __bobthefish_prompt_vagrant_vbox -S -a id -d 'Display VirtualBox Vagrant status'
2019-01-13 09:56:20 -08:00
set -l vagrant_status
2026-05-14 23:27:16 -04:00
set -l vm_status ( VBoxManage showvminfo --machinereadable $id 2 > /dev/null | string replace --filter -r '^VMState="(.*)"$' '$1' )
2019-01-13 09:56:20 -08:00
switch " $vm_status "
2026-05-14 23:21:23 -04:00
case running
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_running_glyph "
2026-05-14 23:21:23 -04:00
case poweroff
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_poweroff_glyph "
2026-05-14 23:21:23 -04:00
case aborted
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_aborted_glyph "
2026-05-14 23:21:23 -04:00
case saved
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_saved_glyph "
2026-05-14 23:21:23 -04:00
case stopping
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_stopping_glyph "
case ''
set vagrant_status " $vagrant_status $vagrant_unknown_glyph "
end
[ - z " $vagrant_status " ]
and return
__bobthefish_start_segment $color_vagrant
echo -ns $vagrant_status ' '
2016-02-18 23:14:13 -08:00
end
2016-08-22 21:35:20 +02:00
function __bobthefish_prompt_vagrant_vmware -S -a id -d 'Display VMWare Vagrant status'
2019-01-13 09:56:20 -08:00
set -l vagrant_status
if [ ( pgrep - f " $id " ) ]
set vagrant_status " $vagrant_status $vagrant_running_glyph "
else
set vagrant_status " $vagrant_status $vagrant_poweroff_glyph "
end
[ - z " $vagrant_status " ]
and return
2016-02-18 23:14:13 -08:00
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $color_vagrant
echo -ns $vagrant_status ' '
2016-08-21 21:11:35 +02:00
end
function __bobthefish_prompt_vagrant_parallels -S -d 'Display Parallels Vagrant status'
2019-01-13 09:56:20 -08:00
set -l vagrant_status
2026-05-14 23:27:16 -04:00
set -l vm_status ( prlctl list $id -o status 2 > /dev/null)
set vm_status $vm_status [ - 1 ]
2019-01-13 09:56:20 -08:00
switch " $vm_status "
2026-05-14 23:21:23 -04:00
case running
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_running_glyph "
2026-05-14 23:21:23 -04:00
case stopped
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_poweroff_glyph "
2026-05-14 23:21:23 -04:00
case paused
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_saved_glyph "
2026-05-14 23:21:23 -04:00
case suspended
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_saved_glyph "
2026-05-14 23:21:23 -04:00
case stopping
2019-01-13 09:56:20 -08:00
set vagrant_status " $vagrant_status $vagrant_stopping_glyph "
case ''
set vagrant_status " $vagrant_status $vagrant_unknown_glyph "
end
[ - z " $vagrant_status " ]
and return
__bobthefish_start_segment $color_vagrant
echo -ns $vagrant_status ' '
2015-12-16 22:12:21 +04:00
end
2017-12-19 08:32:59 -08:00
function __bobthefish_prompt_docker -S -d 'Display Docker machine name'
2026-05-14 23:21:23 -04:00
[ " $theme_display_docker_machine " = no - o - z " $DOCKER_MACHINE_NAME " ]
2019-01-13 09:56:20 -08:00
and return
__bobthefish_start_segment $color_vagrant
echo -ns $DOCKER_MACHINE_NAME ' '
2016-06-01 14:50:14 +01:00
end
2019-07-01 12:21:31 -07:00
function __bobthefish_k8s_context -S -d 'Get the current k8s context'
2019-01-13 09:56:20 -08:00
set -l config_paths " $HOME /.kube/config "
[ - n " $KUBECONFIG " ]
2017-12-23 05:06:32 -08:00
and set config_paths ( string split ':' " $KUBECONFIG " ) $config_paths
2019-01-13 09:56:20 -08:00
for file in $config_paths
[ - f " $file " ]
or continue
while read -l key val
if [ " $key " = 'current-context:' ]
set -l context ( string trim -c '"\' ' -- $val )
[ - z " $context " ]
2019-07-01 12:21:31 -07:00
and return 1
2019-01-13 09:56:20 -08:00
2019-07-01 12:21:31 -07:00
echo $context
2019-01-13 09:56:20 -08:00
return
end
end < $file
end
2019-07-01 12:21:31 -07:00
return 1
end
function __bobthefish_k8s_namespace -S -d 'Get the current k8s namespace'
kubectl config view --minify --output "jsonpath={..namespace}"
end
function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context'
2026-05-14 23:21:23 -04:00
[ " $theme_display_k8s_context " = yes ]
2019-07-01 12:21:31 -07:00
or return
set -l context ( __bobthefish_k8s_context )
or return
2026-05-14 23:21:23 -04:00
[ " $theme_display_k8s_namespace " = yes ]
2020-02-29 18:39:32 +01:00
and set -l namespace ( __bobthefish_k8s_namespace )
2019-07-01 12:21:31 -07:00
2026-05-14 23:21:23 -04:00
[ - z " $context " - o " $context " = default ]
and [ - z " $namespace " - o " $namespace " = default ]
2020-05-04 15:48:01 +02:00
and return
2023-03-16 03:12:26 +10:00
set -l segment $k8s_glyph ' '
2026-05-14 23:21:23 -04:00
[ " $context " != default ]
2023-03-16 03:12:26 +10:00
and set segment $segment $context
2026-05-14 23:21:23 -04:00
[ " $namespace " != default ]
2021-01-24 14:25:02 -08:00
and set segment $segment ':' $namespace
2019-07-01 12:21:31 -07:00
__bobthefish_start_segment $color_k8s
2021-01-24 14:25:02 -08:00
echo -ns $segment ' '
2017-08-08 10:46:20 +03:00
end
2020-09-08 15:06:39 +12:00
# ==============================
# Cloud Tools
# ==============================
function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile'
2026-05-14 23:21:23 -04:00
[ " $theme_display_aws_vault_profile " = yes ]
2020-09-08 15:06:39 +12:00
or return
2023-10-18 10:43:03 +02:00
[ - n " $AWS_VAULT " - a - n " $AWS_CREDENTIAL_EXPIRATION " ]
2020-09-08 15:06:39 +12:00
or return
set -l profile $AWS_VAULT
set -l now ( date --utc +%s)
2023-10-18 10:43:03 +02:00
set -l expiry ( date -d " $AWS_CREDENTIAL_EXPIRATION " +%s)
2020-09-08 15:06:39 +12:00
set -l diff_mins ( math " floor(( $expiry - $now ) / 60) " )
2020-09-09 15:57:13 +12:00
set -l diff_time $diff_mins "m"
[ $diff_mins - le 0 ]
2026-05-14 23:21:23 -04:00
and set -l diff_time 0m
2020-09-09 15:57:13 +12:00
[ $diff_mins - ge 60 ]
and set -l diff_time ( math " floor( $diff_mins / 60) " ) "h" ( math " $diff_mins % 60 " ) "m"
2021-01-24 14:25:02 -08:00
set -l segment $profile ' (' $diff_time ')'
2020-09-09 16:18:53 +12:00
set -l status_color $color_aws_vault
[ $diff_mins - le 0 ]
and set -l status_color $color_aws_vault_expired
2020-09-08 15:06:39 +12:00
2020-09-09 16:18:53 +12:00
__bobthefish_start_segment $status_color
2021-01-24 14:25:02 -08:00
echo -ns $segment ' '
2017-08-08 10:46:20 +03:00
end
2017-12-19 08:32:59 -08:00
# ==============================
# User / hostname info segments
# ==============================
2013-09-17 23:17:15 -07:00
2018-05-05 05:13:59 -07:00
# Polyfill for fish < 2.5.0
if not type -q prompt_hostname
2019-01-13 09:56:20 -08:00
if not set -q __bobthefish_prompt_hostname
2021-11-05 10:16:55 -04:00
set -g __bobthefish_prompt_hostname ( uname -n | string replace -r '\..*' '' )
2019-01-13 09:56:20 -08:00
end
2018-05-05 05:13:59 -07:00
2019-01-13 09:56:20 -08:00
function prompt_hostname
echo $__bobthefish_prompt_hostname
end
2018-05-05 05:13:59 -07:00
end
2017-12-19 08:32:59 -08:00
function __bobthefish_prompt_user -S -d 'Display current user and hostname'
2026-05-14 23:21:23 -04:00
[ " $theme_display_user " = yes - o \( " $theme_display_user " != no - a - n " $SSH_CLIENT " \) - o \( - n " $default_user " - a " $USER " != " $default_user " \) ]
2017-12-19 08:08:05 -08:00
and set -l display_user
2026-05-14 23:21:23 -04:00
[ " $theme_display_sudo_user " = yes - a - n " $SUDO_USER " ]
2019-10-21 18:51:56 +02:00
and set -l display_sudo_user
2026-05-14 23:21:23 -04:00
[ " $theme_display_hostname " = yes - o \( " $theme_display_hostname " != no - a - n " $SSH_CLIENT " \) ]
2019-01-13 09:56:20 -08:00
and set -l display_hostname
2017-12-20 02:38:15 +11:00
2017-12-19 08:08:05 -08:00
if set -q display_user
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $color_username
2026-05-14 23:27:16 -04:00
[ - n " $USER " ]
and echo -ns $USER
or echo -ns ( whoami )
2019-01-13 09:56:20 -08:00
end
2019-10-21 18:51:56 +02:00
if set -q display_sudo_user
2019-01-13 09:56:20 -08:00
if set -q display_user
2019-10-21 18:51:56 +02:00
echo -ns ' '
else
__bobthefish_start_segment $color_username
end
echo -ns " ( $SUDO_USER ) "
end
2019-01-13 09:56:20 -08:00
if set -q display_hostname
2019-11-02 15:48:16 -07:00
if set -q display_user
or set -q display_sudo_user
2019-01-13 09:56:20 -08:00
# reset colors without starting a new segment...
# (so we can have a bold username and non-bold hostname)
set_color normal
set_color -b $color_hostname [ 1 ] $color_hostname [ 2 .. - 1 ]
echo -ns '@' ( prompt_hostname )
else
__bobthefish_start_segment $color_hostname
echo -ns ( prompt_hostname )
end
2017-12-19 08:08:05 -08:00
end
2017-12-20 02:38:15 +11:00
2019-01-13 09:56:20 -08:00
set -q display_user
2019-10-27 10:20:59 +01:00
or set -q display_sudo_user
2018-01-03 13:23:57 -08:00
or set -q display_hostname
2017-12-19 08:08:05 -08:00
and echo -ns ' '
2013-09-17 23:17:15 -07:00
end
2017-12-19 08:32:59 -08:00
# ==============================
# Virtual environment segments
# ==============================
2019-03-18 07:43:38 -07:00
function __bobthefish_rvm_parse_ruby -S -a ruby_string -a scope -d 'Parse RVM Ruby string'
2019-01-13 09:56:20 -08:00
# Function arguments:
# - 'ruby-2.2.3@rails', 'jruby-1.7.19'...
# - 'default' or 'current'
2026-05-14 23:27:16 -04:00
set -l ruby_parts ( string split @ -- " $ruby_string " )
set __rvm_ { $scope } _ruby_gemset $ruby_parts [ 2 ]
set -l ruby_version_parts ( string split - -- $ruby_parts [ 1 ] )
set __rvm_ { $scope } _ruby_interpreter $ruby_version_parts [ 1 ]
set __rvm_ { $scope } _ruby_version $ruby_version_parts [ 2 ]
2017-12-19 08:32:59 -08:00
end
function __bobthefish_rvm_info -S -d 'Current Ruby information from RVM'
2019-01-13 09:56:20 -08:00
# look for rvm install path
set -q rvm_path
2018-03-23 07:01:39 +01:00
or set -l rvm_path ~/.rvm /usr/local/rvm
2018-03-22 23:02:51 -07:00
2026-05-14 23:27:16 -04:00
set -l __rvm_default_ruby
for env_file in $rvm_path /environments/default
[ - e " $env_file " ]
or continue
set -l gem_home ( string replace --filter -r "^.*GEM_HOME='?([^']*)'?.*" '$1' < " $env_file " )
[ " $gem_home " ]
and set __rvm_default_ruby ( __bobthefish_basename " $gem_home " )
and break
end
2019-01-13 09:56:20 -08:00
set -l __rvm_current_ruby ( rvm-prompt i v g)
[ " $__rvm_default_ruby " = " $__rvm_current_ruby " ]
and return
set -l __rvm_default_ruby_gemset
set -l __rvm_default_ruby_interpreter
set -l __rvm_default_ruby_version
set -l __rvm_current_ruby_gemset
set -l __rvm_current_ruby_interpreter
set -l __rvm_current_ruby_version
# Parse default and current Rubies to global variables
__bobthefish_rvm_parse_ruby $__rvm_default_ruby default
__bobthefish_rvm_parse_ruby $__rvm_current_ruby current
# Show unobtrusive RVM prompt
# If interpreter differs form default interpreter, show everything:
if [ " $__rvm_default_ruby_interpreter " != " $__rvm_current_ruby_interpreter " ]
2026-05-14 23:21:23 -04:00
if [ " $__rvm_current_ruby_gemset " = global ]
2019-01-13 09:56:20 -08:00
rvm-prompt i v
else
rvm-prompt i v g
end
# If version differs form default version
else if [ " $__rvm_default_ruby_version " != " $__rvm_current_ruby_version " ]
2026-05-14 23:21:23 -04:00
if [ " $__rvm_current_ruby_gemset " = global ]
2019-01-13 09:56:20 -08:00
rvm-prompt v
else
rvm-prompt v g
end
# If gemset differs form default or 'global' gemset, just show it
else if [ " $__rvm_default_ruby_gemset " != " $__rvm_current_ruby_gemset " ]
rvm-prompt g
2017-12-19 08:32:59 -08:00
end
end
function __bobthefish_prompt_rubies -S -d 'Display current Ruby information'
2026-05-14 23:21:23 -04:00
[ " $theme_display_ruby " = no ]
2019-01-13 09:56:20 -08:00
and return
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
set -l ruby_version
2024-04-20 23:58:40 -04:00
if command -q rvm-prompt
2019-01-13 09:56:20 -08:00
set ruby_version ( __bobthefish_rvm_info )
2024-04-20 23:58:40 -04:00
else if command -q rbenv
2019-01-13 09:56:20 -08:00
set ruby_version ( rbenv version-name)
# Don't show global ruby version...
set -q RBENV_ROOT
or set -l RBENV_ROOT $HOME /.rbenv
[ - e " $RBENV_ROOT /version " ]
and read -l global_ruby_version < " $RBENV_ROOT /version "
[ " $global_ruby_version " ]
or set -l global_ruby_version system
[ " $ruby_version " = " $global_ruby_version " ]
and return
2024-04-20 23:58:40 -04:00
else if type -q chruby # chruby is implemented as a function, so using type -q is intentional
2019-01-13 09:56:20 -08:00
set ruby_version $RUBY_VERSION
2024-04-20 23:58:40 -04:00
else if command -q asdf
2020-05-02 08:34:23 -07:00
set -l asdf_current_ruby ( asdf current ruby 2 > /dev/null)
2019-01-13 09:56:20 -08:00
or return
2022-04-05 12:16:16 -05:00
echo " $asdf_current_ruby " | read -l _asdf_plugin asdf_ruby_version asdf_provenance
2020-05-02 08:34:23 -07:00
2019-01-13 09:56:20 -08:00
# If asdf changes their ruby version provenance format, update this to match
2022-04-05 12:16:16 -05:00
[ ( string trim - - " $asdf_provenance " ) = " $HOME /.tool-versions " ]
2019-01-13 09:56:20 -08:00
and return
set ruby_version $asdf_ruby_version
end
2017-12-21 14:06:06 -05:00
2019-01-13 09:56:20 -08:00
[ - z " $ruby_version " ]
and return
2017-12-24 11:28:38 -08:00
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $color_rvm
echo -ns $ruby_glyph $ruby_version ' '
2017-12-19 08:32:59 -08:00
end
2022-06-18 14:08:52 -07:00
function __bobthefish_prompt_golang -S -a real_pwd -d 'Display current Go information'
# setting is 'no', don't display the prompt
2026-05-14 23:21:23 -04:00
[ " $theme_display_go " = no ]
2022-06-17 11:24:14 -07:00
and return
2022-06-17 11:54:52 -07:00
# find the closest go.mod
2026-05-14 23:21:23 -04:00
set -l gomod_version 0
2022-06-17 12:48:58 -07:00
set -l d $real_pwd
2022-06-17 12:41:49 -07:00
while not [ - z " $d " ]
if [ - e $d /go.mod ]
2026-05-14 23:21:23 -04:00
string match -rq '^go\s(?<gomod_version>\S+)' < " $d /go.mod "
2022-06-17 12:48:58 -07:00
break
2022-06-17 11:24:14 -07:00
end
2026-05-14 23:21:23 -04:00
[ " $d " = / ]
2022-06-17 12:41:49 -07:00
and return
2022-06-17 12:58:52 -07:00
set d ( __bobthefish_dirname $d )
2022-06-17 11:54:52 -07:00
end
2022-06-17 12:21:52 -07:00
# no go.mod, not in a go project, don't display the prompt
2026-05-14 23:21:23 -04:00
if [ " $gomod_version " = 0 ]
2022-06-17 11:54:52 -07:00
return
2022-06-17 12:21:52 -07:00
end
2022-06-17 11:54:52 -07:00
2022-06-17 12:21:52 -07:00
# check if there's a Go executable
2026-05-14 23:21:23 -04:00
set -l no_go_installed 0
set -l actual_go_version 0
set -l high_enough_version 0
2024-04-20 23:58:40 -04:00
if command -q go
2024-09-24 09:25:17 -04:00
set actual_go_version ( go version | string replace --filter -r 'go version go(\\d+\\.\\d+(?:\\.\\d+)?).*' '$1' )
2026-05-14 23:27:16 -04:00
if __bobthefish_version_at_least " $gomod_version " " $actual_go_version "
2026-05-14 23:21:23 -04:00
set high_enough_version 1
2022-06-17 12:21:52 -07:00
end
2022-06-17 13:01:51 -07:00
else
2026-05-14 23:21:23 -04:00
set no_go_installed 1
2022-06-18 14:08:52 -07:00
end
2026-05-14 23:21:23 -04:00
if [ " $high_enough_version " = 1 ]
2022-06-17 13:01:51 -07:00
__bobthefish_start_segment $color_virtualgo
2022-06-18 14:08:52 -07:00
else
__bobthefish_start_segment $color_rvm
2022-06-17 12:21:52 -07:00
end
2022-06-18 14:08:52 -07:00
echo -ns $go_glyph
echo -ns " $gomod_version "
# showing the prompt -- but plain ( for 'yes' ) or verbose?
2026-05-14 23:21:23 -04:00
if [ " $theme_display_go " = verbose ]
if [ " $actual_go_version " != 0 ]
2022-06-18 14:08:52 -07:00
# show the prompt with the required version AND the currently available
# version; same color rules as above
echo -ns " ( $actual_go_version ) "
2022-06-17 12:21:52 -07:00
end
end
2022-06-17 11:24:14 -07:00
end
2017-12-19 08:32:59 -08:00
function __bobthefish_virtualenv_python_version -S -d 'Get current Python version'
2026-05-14 23:27:16 -04:00
switch ( python --version 2 > & 1 | string join ' ' )
2019-01-13 09:56:20 -08:00
case 'Python 2*PyPy*'
echo $pypy_glyph
case 'Python 3*PyPy*'
echo -s $pypy_glyph $superscript_glyph [ 3 ]
case 'Python 2*'
echo $superscript_glyph [ 2 ]
case 'Python 3*'
echo $superscript_glyph [ 3 ]
end
2017-12-19 08:32:59 -08:00
end
2018-06-02 18:27:26 +10:00
function __bobthefish_prompt_virtualfish -S -d "Display current Python virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself) or conda environment."
2024-04-20 23:58:40 -04:00
command -q python
2024-03-05 18:21:39 -05:00
or return
2026-05-14 23:21:23 -04:00
[ " $theme_display_virtualenv " = no - o - z " $VIRTUAL_ENV " - a - z " $CONDA_DEFAULT_ENV " ]
2019-01-13 09:56:20 -08:00
and return
set -l version_glyph ( __bobthefish_virtualenv_python_version )
2026-05-14 23:21:23 -04:00
set -l prompt_style default
2019-01-13 09:56:20 -08:00
if [ " $version_glyph " ]
__bobthefish_start_segment $color_virtualfish
2024-02-12 10:42:09 +01:00
if string match -q "Python 2*" ( python --version 2 > & 1 | string trim)
2026-05-14 23:21:23 -04:00
set prompt_style verbose
else if [ " $theme_display_virtualenv " = verbose ]
set prompt_style verbose
2024-02-12 10:42:09 +01:00
end
2026-05-14 23:21:23 -04:00
if [ " $prompt_style " = verbose ]
2024-02-09 12:54:58 +01:00
echo -ns $virtualenv_glyph $version_glyph ' '
2024-02-12 10:42:09 +01:00
else
echo -ns $virtualenv_glyph
2024-02-09 12:54:58 +01:00
end
2024-02-12 10:42:09 +01:00
2019-01-13 09:56:20 -08:00
end
if [ " $VIRTUAL_ENV " ]
2026-05-14 23:27:16 -04:00
echo -ns ( __bobthefish_basename " $VIRTUAL_ENV " ) ' '
2019-01-13 09:56:20 -08:00
else if [ " $CONDA_DEFAULT_ENV " ]
2026-05-14 23:27:16 -04:00
echo -ns ( __bobthefish_basename " $CONDA_DEFAULT_ENV " ) ' '
2019-01-13 09:56:20 -08:00
end
2017-12-19 08:32:59 -08:00
end
function __bobthefish_prompt_virtualgo -S -d 'Display current Go virtual environment'
2026-05-14 23:21:23 -04:00
[ " $theme_display_virtualgo " = no - o - z " $VIRTUALGO " ]
2019-01-13 09:56:20 -08:00
and return
__bobthefish_start_segment $color_virtualgo
2026-05-14 23:27:16 -04:00
echo -ns $go_glyph ' ' ( __bobthefish_basename " $VIRTUALGO " ) ' '
2019-01-13 09:56:20 -08:00
set_color normal
2017-12-19 08:32:59 -08:00
end
2018-02-16 15:18:48 +01:00
function __bobthefish_prompt_desk -S -d 'Display current desk environment'
2026-05-14 23:21:23 -04:00
[ " $theme_display_desk " = no - o - z " $DESK_ENV " ]
2019-01-13 09:56:20 -08:00
and return
__bobthefish_start_segment $color_desk
2026-05-14 23:27:16 -04:00
echo -ns $desk_glyph ' ' ( string replace -r '\.fish$' '' ( __bobthefish_basename " $DESK_ENV " ) ) ' '
2019-01-13 09:56:20 -08:00
set_color normal
2018-02-16 15:18:48 +01:00
end
2022-02-02 23:15:51 -08:00
function __bobthefish_prompt_find_file_up -S -d 'Find file(s), going up the parent directories'
set -l dir " $argv [1] "
2022-08-01 21:41:04 -06:00
set -l files $argv [ 2 .. - 1 ]
2022-02-02 23:15:51 -08:00
if test -z " $dir "
or test -z " $files "
return 1
end
while [ " $dir " ]
for f in $files
if [ - e " $dir / $f " ]
return
end
end
2026-05-14 23:21:23 -04:00
[ " $dir " = / ]
2022-02-02 23:15:51 -08:00
and return 1
set dir ( __bobthefish_dirname " $dir " )
end
return 1
end
2021-01-24 17:14:30 -05:00
function __bobthefish_prompt_node -S -d 'Display current node version'
2022-02-02 23:15:51 -08:00
set -l should_show
2026-05-14 23:21:23 -04:00
if [ " $theme_display_node " = always - o " $theme_display_nvm " = yes ]
2022-02-02 23:15:51 -08:00
set should_show 1
2026-05-14 23:21:23 -04:00
else if [ " $theme_display_node " = yes ]
2022-02-02 23:15:51 -08:00
__bobthefish_prompt_find_file_up " $PWD " package.json .nvmrc .node-version
and set should_show 1
end
[ - z " $should_show " ]
and return
2019-07-01 16:40:53 +02:00
2021-01-24 17:14:30 -05:00
set -l node_manager
set -l node_manager_dir
2021-01-27 17:59:31 -07:00
if type -q nvm
2026-05-14 23:21:23 -04:00
set node_manager nvm
2024-04-20 23:58:40 -04:00
set node_manager_dir $NVM_DIR
else if command -q fnm
2026-05-14 23:21:23 -04:00
set node_manager fnm
2024-04-20 23:58:40 -04:00
set node_manager_dir $FNM_DIR
2021-01-24 17:14:30 -05:00
end
[ - n " $node_manager_dir " ]
or return
set -l node_version ( " $node_manager " current 2 > /dev/null)
2019-07-01 16:40:53 +02:00
2026-05-14 23:21:23 -04:00
[ - z $node_version - o " $node_version " = none - o " $node_version " = system ]
2019-07-01 16:40:53 +02:00
and return
2021-01-24 17:14:30 -05:00
[ - n " $color_nvm " ]
2021-01-24 14:25:02 -08:00
and set -x color_node $color_nvm
2021-01-24 17:14:30 -05:00
__bobthefish_start_segment $color_node
2019-07-01 16:40:53 +02:00
echo -ns $node_glyph $node_version ' '
set_color normal
end
2019-11-06 09:41:03 -08:00
function __bobthefish_prompt_nix -S -d 'Display current nix environment'
2026-05-14 23:21:23 -04:00
[ " $theme_display_nix " = no - o - z " $IN_NIX_SHELL " ]
2019-11-06 09:41:03 -08:00
and return
__bobthefish_start_segment $color_nix
echo -ns $nix_glyph $IN_NIX_SHELL ' '
set_color normal
end
2017-12-19 08:32:59 -08:00
# ==============================
# VCS segments
# ==============================
2024-04-18 22:44:45 -04:00
function __bobthefish_prompt_fossil -S -a fossil_root_dir -a real_pwd -d 'Display the actual fossil state'
2026-05-14 23:27:16 -04:00
set -f fossil_statuses ( command fossil changes --differ 2 > /dev/null | string replace --filter -r '^(\S+).*' '$1' )
2024-04-18 22:44:45 -04:00
# Fossil doesn't really stage changes; untracked files are ignored, tracked files are committed by default
# It also syncs by default when you commit, and monitors for conflicts (which will be reported here)
for line in $fossil_statuses
switch $line
case ADDED UPDATED EDITED DELETED RENAMED
# These can really just all be dirty, then
2024-04-20 19:55:06 -04:00
set -f dirty $git_dirty_glyph
2024-04-18 22:44:45 -04:00
case EXTRA
2024-04-20 19:55:06 -04:00
set -f new $git_untracked_glyph
2024-04-18 22:44:45 -04:00
case CONFLICT
2024-04-20 19:55:06 -04:00
set -f conflict '!'
2024-04-18 22:44:45 -04:00
end
end
2024-04-20 19:28:26 -04:00
set -f flags " $dirty $new $conflict "
2024-04-18 22:44:45 -04:00
[ " $flags " ]
and set flags " $flags "
set -l flag_colors $color_repo
if [ " $dirty " ]
set flag_colors $color_repo_dirty
end
__bobthefish_path_segment $fossil_root_dir project
__bobthefish_start_segment $flag_colors
echo -ns $fossil_glyph ' '
echo -ns ( __bobthefish_fossil_branch ) $flags ' '
set_color normal
set -l project_pwd ( __bobthefish_project_pwd $fossil_root_dir $real_pwd )
if [ " $project_pwd " ]
if [ - w " $real_pwd " ]
__bobthefish_start_segment $color_path
else
__bobthefish_start_segment $color_path_nowrite
end
echo -ns $project_pwd ' '
end
end
2019-03-18 07:43:13 -07:00
function __bobthefish_prompt_hg -S -a hg_root_dir -a real_pwd -d 'Display the actual hg state'
2019-01-13 09:56:20 -08:00
set -l dirty ( command hg stat; or echo -n '*' )
2014-11-16 17:47:15 +07:00
2019-01-13 09:56:20 -08:00
set -l flags " $dirty "
[ " $flags " ]
2021-01-24 14:25:02 -08:00
and set flags ''
2014-11-16 17:47:15 +07:00
2019-01-13 09:56:20 -08:00
set -l flag_colors $color_repo
if [ " $dirty " ]
set flag_colors $color_repo_dirty
end
2014-11-16 17:47:15 +07:00
2024-03-05 15:20:50 -05:00
__bobthefish_path_segment $hg_root_dir project
2014-11-16 17:47:15 +07:00
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $flag_colors
echo -ns $hg_glyph ' '
2014-11-17 18:40:30 -08:00
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $flag_colors
echo -ns ( __bobthefish_hg_branch ) $flags ' '
set_color normal
2014-11-16 17:47:15 +07:00
2019-03-18 07:43:13 -07:00
set -l project_pwd ( __bobthefish_project_pwd $hg_root_dir $real_pwd )
2019-01-13 09:56:20 -08:00
if [ " $project_pwd " ]
2019-03-18 07:43:13 -07:00
if [ - w " $real_pwd " ]
2019-01-13 09:56:20 -08:00
__bobthefish_start_segment $color_path
else
__bobthefish_start_segment $color_path_nowrite
end
2014-11-16 17:47:15 +07:00
2019-01-13 09:56:20 -08:00
echo -ns $project_pwd ' '
end
2014-11-16 17:47:15 +07:00
end
2020-08-30 08:43:38 -03:00
function __bobthefish_prompt_screen -S -d 'Display the screen name'
2026-05-14 23:21:23 -04:00
[ " $theme_display_screen " = no - o - z " $STY " ]
2020-08-30 08:43:38 -03:00
and return
__bobthefish_start_segment $color_screen
2024-03-09 14:47:36 -05:00
echo -ns ( string split "." -- $STY ) [ 2 ] ' '
2020-08-30 08:43:38 -03:00
set_color normal
end
2026-05-15 02:33:01 -04:00
function __bobthefish_prompt_git -S -a git_root_dir -a real_pwd -a repaint -d 'Display the actual git state'
if __bobthefish_git_async_enabled
__bobthefish_prompt_git_async $git_root_dir $real_pwd $repaint
2019-01-13 09:56:20 -08:00
else
2026-05-15 02:58:23 -04:00
__bobthefish_git_async_stop_poller
2026-05-15 02:33:01 -04:00
__bobthefish_prompt_git_sync $git_root_dir $real_pwd
2016-03-30 16:57:34 -07:00
end
2013-09-17 23:17:15 -07:00
end
2019-03-18 07:43:13 -07:00
function __bobthefish_prompt_dir -S -a real_pwd -d 'Display a shortened form of the current directory'
2024-03-05 15:20:50 -05:00
__bobthefish_path_segment " $real_pwd " pwd
2013-09-17 23:17:15 -07:00
end
2024-04-24 14:56:28 -04:00
# Polyfill for fish < 3.5.0
function __bobthefish_closest_parent -S
if builtin -q path
2024-07-19 18:32:08 +09:00
echo ( path sort -r $argv ) [ 1 ]
2024-04-24 14:56:28 -04:00
else
2026-05-14 23:27:16 -04:00
set -l closest
for candidate in $argv
[ - z " $candidate " ]
and continue
if [ - z " $closest " - o ( string length - - " $candidate " ) - gt ( string length - - " $closest " ) ]
set closest $candidate
end
end
echo $closest
2024-04-24 14:56:28 -04:00
end
end
2017-12-19 08:32:59 -08:00
# ==============================
2013-09-17 23:17:15 -07:00
# Apply theme
2017-12-19 08:32:59 -08:00
# ==============================
2013-09-17 23:17:15 -07:00
2013-10-15 21:41:19 -04:00
function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
2019-03-29 05:13:12 +01:00
# Save the last status for later (do this before anything else)
set -l last_status $status
2026-05-15 02:33:01 -04:00
set -l git_async_repaint
set -e __bobthefish_git_async_repaint_pending
and set git_async_repaint 1
2019-03-29 05:13:12 +01:00
2019-03-26 14:51:09 +00:00
# Use a simple prompt on dumb terminals.
2026-05-14 23:21:23 -04:00
if [ " $TERM " = dumb ]
2026-05-15 02:58:23 -04:00
__bobthefish_git_async_stop_poller
2021-01-24 14:25:02 -08:00
echo '> '
2019-03-26 14:51:09 +00:00
return
end
2019-01-13 09:56:20 -08:00
__bobthefish_glyphs
__bobthefish_colors $theme_color_scheme
2017-12-19 08:32:59 -08:00
2019-01-13 09:56:20 -08:00
type -q bobthefish_colors
and bobthefish_colors
2016-03-30 16:13:39 -07:00
2019-01-13 09:56:20 -08:00
# Start each line with a blank slate
set -l __bobthefish_current_bg
2022-06-17 12:48:58 -07:00
set -l real_pwd ( __bobthefish_pwd )
2019-01-13 09:56:20 -08:00
# Status flags and input mode
__bobthefish_prompt_status $last_status
2020-01-17 14:33:42 -08:00
# User / hostname info
__bobthefish_prompt_user
2020-09-03 06:27:41 -03:00
# Screen
2020-08-30 08:43:38 -03:00
__bobthefish_prompt_screen
2020-01-17 14:33:42 -08:00
2019-01-13 09:56:20 -08:00
# Containers and VMs
__bobthefish_prompt_vagrant
__bobthefish_prompt_docker
__bobthefish_prompt_k8s_context
2020-09-08 15:06:39 +12:00
# Cloud Tools
__bobthefish_prompt_aws_vault_profile
2019-01-13 09:56:20 -08:00
# Virtual environments
2019-11-06 09:41:03 -08:00
__bobthefish_prompt_nix
2019-01-13 09:56:20 -08:00
__bobthefish_prompt_desk
__bobthefish_prompt_rubies
2022-06-18 14:08:52 -07:00
__bobthefish_prompt_golang $real_pwd
2019-01-13 09:56:20 -08:00
__bobthefish_prompt_virtualfish
__bobthefish_prompt_virtualgo
2021-01-24 17:14:30 -05:00
__bobthefish_prompt_node
2019-01-13 09:56:20 -08:00
# VCS
2019-03-18 07:43:13 -07:00
set -l git_root_dir ( __bobthefish_git_project_dir $real_pwd )
set -l hg_root_dir ( __bobthefish_hg_project_dir $real_pwd )
2024-04-18 22:44:45 -04:00
set -l fossil_root_dir ( __bobthefish_fossil_project_dir $real_pwd )
2019-01-13 09:56:20 -08:00
2024-04-20 19:28:26 -04:00
# only show the closest parent
2024-04-24 14:56:28 -04:00
switch ( __bobthefish_closest_parent " $git_root_dir " " $hg_root_dir " " $fossil_root_dir " )
2024-04-20 19:28:26 -04:00
case ''
2026-05-15 02:58:23 -04:00
__bobthefish_git_async_stop_poller
2024-04-20 19:28:26 -04:00
__bobthefish_prompt_dir $real_pwd
case " $git_root_dir "
2026-05-15 02:33:01 -04:00
__bobthefish_prompt_git $git_root_dir $real_pwd $git_async_repaint
2024-04-20 19:28:26 -04:00
case " $hg_root_dir "
2026-05-15 02:58:23 -04:00
__bobthefish_git_async_stop_poller
2024-04-20 19:28:26 -04:00
__bobthefish_prompt_hg $hg_root_dir $real_pwd
case " $fossil_root_dir "
2026-05-15 02:58:23 -04:00
__bobthefish_git_async_stop_poller
2024-04-20 19:28:26 -04:00
__bobthefish_prompt_fossil $fossil_root_dir $real_pwd
2016-03-30 16:13:39 -07:00
end
2019-01-13 09:56:20 -08:00
__bobthefish_finish_segments
2013-09-17 23:17:15 -07:00
end