mirror of
https://github.com/oh-my-fish/theme-bobthefish.git
synced 2024-10-27 20:34:23 +00:00
Consistency++
* Only use if/end blocks for things longer than one line. * Only use inline `[ foo ]; and bar` style when `bar` is `return`. Break the `and`/`or` onto a second line for anything that actually has a side effect. * More consistent use of `echo` flags. * Don't use `pwd` when `$PWD` will do.
This commit is contained in:
parent
4356159ca3
commit
088a0f44e0
@ -37,11 +37,13 @@
|
|||||||
# ===========================
|
# ===========================
|
||||||
|
|
||||||
# function __bobthefish_in_git -S -d 'Check whether pwd is inside a git repo'
|
# function __bobthefish_in_git -S -d 'Check whether pwd is inside a git repo'
|
||||||
# command which git > /dev/null ^&1; and command git rev-parse --is-inside-work-tree >/dev/null ^&1
|
# command which git > /dev/null ^&1
|
||||||
|
# and command git rev-parse --is-inside-work-tree >/dev/null ^&1
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# function __bobthefish_in_hg -S -d 'Check whether pwd is inside a hg repo'
|
# function __bobthefish_in_hg -S -d 'Check whether pwd is inside a hg repo'
|
||||||
# command which hg > /dev/null ^&1; and command hg stat > /dev/null ^&1
|
# command which hg > /dev/null ^&1
|
||||||
|
# and command hg stat > /dev/null ^&1
|
||||||
# end
|
# end
|
||||||
|
|
||||||
function __bobthefish_git_branch -S -d 'Get the current git branch (or commitish)'
|
function __bobthefish_git_branch -S -d 'Get the current git branch (or commitish)'
|
||||||
@ -70,7 +72,7 @@ end
|
|||||||
|
|
||||||
function __bobthefish_hg_project_dir -S -d 'Print the current hg project base directory'
|
function __bobthefish_hg_project_dir -S -d 'Print the current hg project base directory'
|
||||||
[ "$theme_display_hg" = 'yes' ]; or return
|
[ "$theme_display_hg" = 'yes' ]; or return
|
||||||
set -l d (pwd)
|
set -l d $PWD
|
||||||
while not [ $d = / ]
|
while not [ $d = / ]
|
||||||
if [ -e $d/.hg ]
|
if [ -e $d/.hg ]
|
||||||
command hg root --cwd "$d" ^/dev/null
|
command hg root --cwd "$d" ^/dev/null
|
||||||
@ -95,9 +97,7 @@ end
|
|||||||
|
|
||||||
function __bobthefish_git_ahead_verbose -S -d 'Print a more verbose ahead/behind state for the current branch'
|
function __bobthefish_git_ahead_verbose -S -d 'Print a more verbose ahead/behind state for the current branch'
|
||||||
set -l commits (command git rev-list --left-right '@{upstream}...HEAD' ^/dev/null)
|
set -l commits (command git rev-list --left-right '@{upstream}...HEAD' ^/dev/null)
|
||||||
if [ $status != 0 ]
|
[ $status != 0 ]; and return
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l behind (count (for arg in $commits; echo $arg; end | grep '^<'))
|
set -l behind (count (for arg in $commits; echo $arg; end | grep '^<'))
|
||||||
set -l ahead (count (for arg in $commits; echo $arg; end | grep -v '^<'))
|
set -l ahead (count (for arg in $commits; echo $arg; end | grep -v '^<'))
|
||||||
@ -135,11 +135,11 @@ function __bobthefish_start_segment -S -d 'Start a prompt segment'
|
|||||||
echo -n ' '
|
echo -n ' '
|
||||||
case "$bg"
|
case "$bg"
|
||||||
# If the background is already the same color, draw a separator
|
# If the background is already the same color, draw a separator
|
||||||
echo -n "$__bobthefish_right_arrow_glyph "
|
echo -ns $__bobthefish_right_arrow_glyph ' '
|
||||||
case '*'
|
case '*'
|
||||||
# otherwise, draw the end of the previous segment and the start of the next
|
# otherwise, draw the end of the previous segment and the start of the next
|
||||||
set_color $__bobthefish_current_bg
|
set_color $__bobthefish_current_bg
|
||||||
echo -n "$__bobthefish_right_black_arrow_glyph "
|
echo -ns $__bobthefish_right_black_arrow_glyph ' '
|
||||||
set_color $fg $argv
|
set_color $fg $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,9 +167,9 @@ function __bobthefish_path_segment -S -a current_dir -d 'Display a shortened for
|
|||||||
set directory (basename "$current_dir")
|
set directory (basename "$current_dir")
|
||||||
end
|
end
|
||||||
|
|
||||||
[ "$parent" ]; and echo -n -s "$parent"
|
echo -n $parent
|
||||||
set_color fff --bold
|
set_color fff --bold
|
||||||
echo -n "$directory "
|
echo -ns $directory ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ function __bobthefish_finish_segments -S -d 'Close open prompt segments'
|
|||||||
if [ "$__bobthefish_current_bg" != '' ]
|
if [ "$__bobthefish_current_bg" != '' ]
|
||||||
set_color -b normal
|
set_color -b normal
|
||||||
set_color $__bobthefish_current_bg
|
set_color $__bobthefish_current_bg
|
||||||
echo -n "$__bobthefish_right_black_arrow_glyph "
|
echo -ns $__bobthefish_right_black_arrow_glyph ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ function __bobthefish_prompt_vagrant_vbox -S -d 'Display VirtualBox Vagrant stat
|
|||||||
[ -z "$vagrant_status" ]; and return
|
[ -z "$vagrant_status" ]; and return
|
||||||
|
|
||||||
__bobthefish_start_segment $__bobthefish_vagrant fff --bold
|
__bobthefish_start_segment $__bobthefish_vagrant fff --bold
|
||||||
echo -n -s "$vagrant_status "
|
echo -ns $vagrant_status ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ function __bobthefish_prompt_vagrant_vmware -S -d 'Display VMWare Vagrant status
|
|||||||
[ -z "$vagrant_status" ]; and return
|
[ -z "$vagrant_status" ]; and return
|
||||||
|
|
||||||
__bobthefish_start_segment $__bobthefish_vagrant fff --bold
|
__bobthefish_start_segment $__bobthefish_vagrant fff --bold
|
||||||
echo -n -s "$vagrant_status "
|
echo -ns $vagrant_status ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -253,26 +253,23 @@ function __bobthefish_prompt_status -S -a last_status -d 'Display symbols for a
|
|||||||
set -l bg_jobs
|
set -l bg_jobs
|
||||||
|
|
||||||
# Last exit was nonzero
|
# Last exit was nonzero
|
||||||
if [ $last_status -ne 0 ]
|
[ $last_status -ne 0 ]
|
||||||
set nonzero $__bobthefish_nonzero_exit_glyph
|
and set nonzero $__bobthefish_nonzero_exit_glyph
|
||||||
end
|
|
||||||
|
|
||||||
# if superuser (uid == 0)
|
# if superuser (uid == 0)
|
||||||
if [ (id -u $USER) -eq 0 ]
|
[ (id -u $USER) -eq 0 ]
|
||||||
set superuser $__bobthefish_superuser_glyph
|
and set superuser $__bobthefish_superuser_glyph
|
||||||
end
|
|
||||||
|
|
||||||
# Jobs display
|
# Jobs display
|
||||||
if [ (jobs -l | wc -l) -gt 0 ]
|
[ (jobs -l | wc -l) -gt 0 ]
|
||||||
set bg_jobs $__bobthefish_bg_job_glyph
|
and set bg_jobs $__bobthefish_bg_job_glyph
|
||||||
end
|
|
||||||
|
|
||||||
if [ "$nonzero" -o "$superuser" -o "$bg_jobs" ]
|
if [ "$nonzero" -o "$superuser" -o "$bg_jobs" ]
|
||||||
__bobthefish_start_segment fff 000
|
__bobthefish_start_segment fff 000
|
||||||
if [ "$nonzero" ]
|
if [ "$nonzero" ]
|
||||||
set_color $__bobthefish_med_red --bold
|
set_color $__bobthefish_med_red --bold
|
||||||
if [ "$theme_show_exit_status" = 'yes' ]
|
if [ "$theme_show_exit_status" = 'yes' ]
|
||||||
echo -n $last_status' '
|
echo -ns $last_status ' '
|
||||||
else
|
else
|
||||||
echo -n $__bobthefish_nonzero_exit_glyph
|
echo -n $__bobthefish_nonzero_exit_glyph
|
||||||
end
|
end
|
||||||
@ -298,7 +295,7 @@ function __bobthefish_prompt_user -S -d 'Display actual user if different from $
|
|||||||
__bobthefish_start_segment $__bobthefish_lt_grey $__bobthefish_slate_blue
|
__bobthefish_start_segment $__bobthefish_lt_grey $__bobthefish_slate_blue
|
||||||
set -l IFS .
|
set -l IFS .
|
||||||
hostname | read -l hostname __
|
hostname | read -l hostname __
|
||||||
echo -n -s (whoami) "@$hostname "
|
echo -ns (whoami) '@' $hostname ' '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -307,7 +304,8 @@ function __bobthefish_prompt_hg -S -a current_dir -d 'Display the actual hg stat
|
|||||||
set -l dirty (command hg stat; or echo -n '*')
|
set -l dirty (command hg stat; or echo -n '*')
|
||||||
|
|
||||||
set -l flags "$dirty"
|
set -l flags "$dirty"
|
||||||
[ "$flags" ]; and set flags ""
|
[ "$flags" ]
|
||||||
|
and set flags ""
|
||||||
|
|
||||||
set -l flag_bg $__bobthefish_lt_green
|
set -l flag_bg $__bobthefish_lt_green
|
||||||
set -l flag_fg $__bobthefish_dk_green
|
set -l flag_fg $__bobthefish_dk_green
|
||||||
@ -319,10 +317,10 @@ function __bobthefish_prompt_hg -S -a current_dir -d 'Display the actual hg stat
|
|||||||
__bobthefish_path_segment $current_dir
|
__bobthefish_path_segment $current_dir
|
||||||
|
|
||||||
__bobthefish_start_segment $flag_bg $flag_fg
|
__bobthefish_start_segment $flag_bg $flag_fg
|
||||||
echo -n -s $__bobthefish_hg_glyph ' '
|
echo -ns $__bobthefish_hg_glyph ' '
|
||||||
|
|
||||||
__bobthefish_start_segment $flag_bg $flag_fg --bold
|
__bobthefish_start_segment $flag_bg $flag_fg --bold
|
||||||
echo -n -s (__bobthefish_hg_branch) $flags ' '
|
echo -ns (__bobthefish_hg_branch) $flags ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
|
|
||||||
set -l project_pwd (__bobthefish_project_pwd $current_dir)
|
set -l project_pwd (__bobthefish_project_pwd $current_dir)
|
||||||
@ -333,7 +331,7 @@ function __bobthefish_prompt_hg -S -a current_dir -d 'Display the actual hg stat
|
|||||||
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
|
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
|
||||||
end
|
end
|
||||||
|
|
||||||
echo -n -s $project_pwd ' '
|
echo -ns $project_pwd ' '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -357,7 +355,8 @@ function __bobthefish_prompt_git -S -a current_dir -d 'Display the actual git st
|
|||||||
end
|
end
|
||||||
|
|
||||||
set -l flags "$dirty$staged$stashed$ahead$new"
|
set -l flags "$dirty$staged$stashed$ahead$new"
|
||||||
[ "$flags" ]; and set flags " $flags"
|
[ "$flags" ]
|
||||||
|
and set flags " $flags"
|
||||||
|
|
||||||
set -l flag_bg $__bobthefish_lt_green
|
set -l flag_bg $__bobthefish_lt_green
|
||||||
set -l flag_fg $__bobthefish_dk_green
|
set -l flag_fg $__bobthefish_dk_green
|
||||||
@ -372,7 +371,7 @@ function __bobthefish_prompt_git -S -a current_dir -d 'Display the actual git st
|
|||||||
__bobthefish_path_segment $current_dir
|
__bobthefish_path_segment $current_dir
|
||||||
|
|
||||||
__bobthefish_start_segment $flag_bg $flag_fg --bold
|
__bobthefish_start_segment $flag_bg $flag_fg --bold
|
||||||
echo -n -s (__bobthefish_git_branch) $flags ' '
|
echo -ns (__bobthefish_git_branch) $flags ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
|
|
||||||
set -l project_pwd (__bobthefish_project_pwd $current_dir)
|
set -l project_pwd (__bobthefish_project_pwd $current_dir)
|
||||||
@ -383,7 +382,7 @@ function __bobthefish_prompt_git -S -a current_dir -d 'Display the actual git st
|
|||||||
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
|
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
|
||||||
end
|
end
|
||||||
|
|
||||||
echo -n -s $project_pwd ' '
|
echo -ns $project_pwd ' '
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -396,20 +395,21 @@ function __bobthefish_prompt_vi -S -d 'Display vi mode'
|
|||||||
switch $fish_bind_mode
|
switch $fish_bind_mode
|
||||||
case default
|
case default
|
||||||
__bobthefish_start_segment $__bobthefish_med_grey $__bobthefish_dk_grey --bold
|
__bobthefish_start_segment $__bobthefish_med_grey $__bobthefish_dk_grey --bold
|
||||||
echo -n -s 'N '
|
echo -n 'N '
|
||||||
case insert
|
case insert
|
||||||
__bobthefish_start_segment $__bobthefish_lt_green $__bobthefish_dk_grey --bold
|
__bobthefish_start_segment $__bobthefish_lt_green $__bobthefish_dk_grey --bold
|
||||||
echo -n -s 'I '
|
echo -n 'I '
|
||||||
case visual
|
case visual
|
||||||
__bobthefish_start_segment $__bobthefish_lt_orange $__bobthefish_dk_grey --bold
|
__bobthefish_start_segment $__bobthefish_lt_orange $__bobthefish_dk_grey --bold
|
||||||
echo -n -s 'V '
|
echo -n 'V '
|
||||||
end
|
end
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
function __bobthefish_virtualenv_python_version -S -d 'Get current python version'
|
function __bobthefish_virtualenv_python_version -S -d 'Get current python version'
|
||||||
set -l python_version (readlink (which python))
|
set -l python_version (readlink (which python))
|
||||||
[ -z "$python_version" ]; and set python_version (which python)
|
[ -z "$python_version" ]
|
||||||
|
and set python_version (which python)
|
||||||
switch (basename "$python_version")
|
switch (basename "$python_version")
|
||||||
case 'python' 'python2*'
|
case 'python' 'python2*'
|
||||||
echo $__bobthefish_superscript_glyph[2]
|
echo $__bobthefish_superscript_glyph[2]
|
||||||
@ -425,9 +425,9 @@ function __bobthefish_prompt_virtualfish -S -d "Display activated virtual enviro
|
|||||||
set -l version_glyph (__bobthefish_virtualenv_python_version)
|
set -l version_glyph (__bobthefish_virtualenv_python_version)
|
||||||
if [ "$version_glyph" ]
|
if [ "$version_glyph" ]
|
||||||
__bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey
|
__bobthefish_start_segment $__bobthefish_med_blue $__bobthefish_lt_grey
|
||||||
echo -n -s $__bobthefish_virtualenv_glyph $version_glyph ' '
|
echo -ns $__bobthefish_virtualenv_glyph $version_glyph ' '
|
||||||
end
|
end
|
||||||
echo -n -s (basename "$VIRTUAL_ENV") ' '
|
echo -ns (basename "$VIRTUAL_ENV") ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -488,14 +488,19 @@ function __bobthefish_show_ruby -S -d 'Current Ruby (rvm/rbenv)'
|
|||||||
else if type -q rbenv
|
else if type -q rbenv
|
||||||
set ruby_version (rbenv version-name)
|
set ruby_version (rbenv version-name)
|
||||||
# Don't show global ruby version...
|
# Don't show global ruby version...
|
||||||
set -q RBENV_ROOT; or set -l RBENV_ROOT $HOME/.rbenv
|
set -q RBENV_ROOT
|
||||||
|
or set -l RBENV_ROOT $HOME/.rbenv
|
||||||
|
|
||||||
read -l global_ruby_version <$RBENV_ROOT/version
|
read -l global_ruby_version <$RBENV_ROOT/version
|
||||||
[ "$global_ruby_version" ]; or set global_ruby_version system
|
|
||||||
|
[ "$global_ruby_version" ]
|
||||||
|
or set global_ruby_version system
|
||||||
|
|
||||||
[ "$ruby_version" = "$global_ruby_version" ]; and return
|
[ "$ruby_version" = "$global_ruby_version" ]; and return
|
||||||
end
|
end
|
||||||
[ -z "$ruby_version" ]; and return
|
[ -z "$ruby_version" ]; and return
|
||||||
__bobthefish_start_segment $__bobthefish_ruby_red $__bobthefish_lt_grey --bold
|
__bobthefish_start_segment $__bobthefish_ruby_red $__bobthefish_lt_grey --bold
|
||||||
echo -n -s $__bobthefish_ruby_glyph $ruby_version ' '
|
echo -ns $__bobthefish_ruby_glyph $ruby_version ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,15 +8,15 @@ function __bobthefish_cmd_duration -S -d 'Show command duration'
|
|||||||
echo -ns $CMD_DURATION 'ms '
|
echo -ns $CMD_DURATION 'ms '
|
||||||
else if [ "$CMD_DURATION" -lt 60000 ]
|
else if [ "$CMD_DURATION" -lt 60000 ]
|
||||||
math "scale=1;$CMD_DURATION/1000" | sed 's/\\.0$//'
|
math "scale=1;$CMD_DURATION/1000" | sed 's/\\.0$//'
|
||||||
echo -ns 's '
|
echo -n 's '
|
||||||
else if [ "$CMD_DURATION" -lt 3600000 ]
|
else if [ "$CMD_DURATION" -lt 3600000 ]
|
||||||
set_color $fish_color_error
|
set_color $fish_color_error
|
||||||
math "scale=1;$CMD_DURATION/60000" | sed 's/\\.0$//'
|
math "scale=1;$CMD_DURATION/60000" | sed 's/\\.0$//'
|
||||||
echo -ns 'm '
|
echo -n 'm '
|
||||||
else
|
else
|
||||||
set_color $fish_color_error
|
set_color $fish_color_error
|
||||||
math "scale=2;$CMD_DURATION/3600000" | sed 's/\\.0$//'
|
math "scale=2;$CMD_DURATION/3600000" | sed 's/\\.0$//'
|
||||||
echo -ns 'h '
|
echo -n 'h '
|
||||||
end
|
end
|
||||||
|
|
||||||
set_color $fish_color_normal
|
set_color $fish_color_normal
|
||||||
@ -25,7 +25,9 @@ function __bobthefish_cmd_duration -S -d 'Show command duration'
|
|||||||
end
|
end
|
||||||
|
|
||||||
function __bobthefish_timestamp -S -d 'Show the current timestamp'
|
function __bobthefish_timestamp -S -d 'Show the current timestamp'
|
||||||
set -q theme_date_format; or set -l theme_date_format "+%c"
|
set -q theme_date_format
|
||||||
|
or set -l theme_date_format "+%c"
|
||||||
|
|
||||||
echo -n ' '
|
echo -n ' '
|
||||||
date $theme_date_format
|
date $theme_date_format
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
function fish_title
|
function fish_title
|
||||||
if [ "$theme_title_display_process" = 'yes' ]
|
if [ "$theme_title_display_process" = 'yes' ]
|
||||||
echo $_
|
echo $_
|
||||||
[ "$theme_title_display_path" != 'no' ]; and echo ' '
|
|
||||||
|
[ "$theme_title_display_path" != 'no' ]
|
||||||
|
and echo ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
if [ "$theme_title_display_path" != 'no' ]
|
if [ "$theme_title_display_path" != 'no' ]
|
||||||
|
Loading…
Reference in New Issue
Block a user