mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
Merge pull request #255 from bobthecow/bobthefish-hg-tweaks
Add mercurial support for bobthefish
This commit is contained in:
commit
1b102c545a
@ -29,9 +29,9 @@ This theme is based loosely on [agnoster][agnoster].
|
|||||||
* You currently have superpowers ($)
|
* You currently have superpowers ($)
|
||||||
* User@Host (unless you're the default user)
|
* User@Host (unless you're the default user)
|
||||||
* Abbreviated parent directory
|
* Abbreviated parent directory
|
||||||
* Current directory or Git project name
|
* Current directory, or Git or Mercurial project name
|
||||||
* Current project's Git branch ( master) or detached head (➦ d0dfd9b)
|
* Current project's repo branch ( master) or detached head (➦ d0dfd9b)
|
||||||
* Git status, via colors and flags:
|
* Git or Mercurial status, via colors and flags:
|
||||||
* Dirty working directory (*)
|
* Dirty working directory (*)
|
||||||
* Untracked files (…)
|
* Untracked files (…)
|
||||||
* Staged changes (~)
|
* Staged changes (~)
|
||||||
@ -39,6 +39,7 @@ This theme is based loosely on [agnoster][agnoster].
|
|||||||
* Unpulled commits (-)
|
* Unpulled commits (-)
|
||||||
* Unpushed commits (+)
|
* Unpushed commits (+)
|
||||||
* Unpulled *and* unpushed commits (±)
|
* Unpulled *and* unpushed commits (±)
|
||||||
|
* _Note that not all of these have been implemented for hg yet :)_
|
||||||
* Abbreviated project-relative path
|
* Abbreviated project-relative path
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ set __bobthefish_detached_glyph \u27A6
|
|||||||
set __bobthefish_nonzero_exit_glyph '! '
|
set __bobthefish_nonzero_exit_glyph '! '
|
||||||
set __bobthefish_superuser_glyph '$ '
|
set __bobthefish_superuser_glyph '$ '
|
||||||
set __bobthefish_bg_job_glyph '% '
|
set __bobthefish_bg_job_glyph '% '
|
||||||
|
set __bobthefish_hg_glyph \u263F
|
||||||
|
|
||||||
# Python glyphs
|
# Python glyphs
|
||||||
set __bobthefish_superscript_glyph \u00B9 \u00B2 \u00B3
|
set __bobthefish_superscript_glyph \u00B9 \u00B2 \u00B3
|
||||||
@ -68,7 +69,11 @@ set __bobthefish_lt_blue 326D9E
|
|||||||
# ===========================
|
# ===========================
|
||||||
|
|
||||||
function __bobthefish_in_git -d 'Check whether pwd is inside a git repo'
|
function __bobthefish_in_git -d 'Check whether pwd is inside a git repo'
|
||||||
command git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
command which git > /dev/null 2>&1; and command git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||||
|
end
|
||||||
|
|
||||||
|
function __bobthefish_in_hg -d 'Check whether pwd is inside a hg repo'
|
||||||
|
command which hg > /dev/null 2>&1; and command hg stat > /dev/null 2>&1
|
||||||
end
|
end
|
||||||
|
|
||||||
function __bobthefish_git_branch -d 'Get the current git branch (or commitish)'
|
function __bobthefish_git_branch -d 'Get the current git branch (or commitish)'
|
||||||
@ -80,17 +85,26 @@ function __bobthefish_git_branch -d 'Get the current git branch (or commitish)'
|
|||||||
echo $ref | sed "s-refs/heads/-$__bobthefish_branch_glyph -"
|
echo $ref | sed "s-refs/heads/-$__bobthefish_branch_glyph -"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function __bobthefish_hg_branch -d 'Get the current hg branch'
|
||||||
|
set -l branch (hg branch ^/dev/null)
|
||||||
|
set -l book " @ "(hg book | grep \* | cut -d\ -f3)
|
||||||
|
echo "$__bobthefish_branch_glyph $branch$book"
|
||||||
|
end
|
||||||
|
|
||||||
function __bobthefish_pretty_parent -d 'Print a parent directory, shortened to fit the prompt'
|
function __bobthefish_pretty_parent -d 'Print a parent directory, shortened to fit the prompt'
|
||||||
echo -n (dirname $argv[1]) | sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g' -e 's|/$||'
|
echo -n (dirname $argv[1]) | sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g' -e 's|/$||'
|
||||||
end
|
end
|
||||||
|
|
||||||
function __bobthefish_project_dir -d 'Print the current git project base directory'
|
function __bobthefish_git_project_dir -d 'Print the current git project base directory'
|
||||||
command git rev-parse --show-toplevel 2>/dev/null
|
command git rev-parse --show-toplevel 2>/dev/null
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function __bobthefish_hg_project_dir -d 'Print the current hg project base directory'
|
||||||
|
command hg root 2>/dev/null
|
||||||
|
end
|
||||||
|
|
||||||
function __bobthefish_project_pwd -d 'Print the working directory relative to project root'
|
function __bobthefish_project_pwd -d 'Print the working directory relative to project root'
|
||||||
set -l base_dir (__bobthefish_project_dir)
|
echo "$PWD" | sed -e "s*$argv[1]**g" -e 's*^/**'
|
||||||
echo "$PWD" | sed -e "s*$base_dir**g" -e 's*^/**'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -167,7 +181,7 @@ function __bobthefish_prompt_status -d 'Display symbols for a non zero exit stat
|
|||||||
set -l bg_jobs
|
set -l bg_jobs
|
||||||
|
|
||||||
# Last exit was nonzero
|
# Last exit was nonzero
|
||||||
if [ $RETVAL -ne 0 ]
|
if [ $status -ne 0 ]
|
||||||
set nonzero $__bobthefish_nonzero_exit_glyph
|
set nonzero $__bobthefish_nonzero_exit_glyph
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -214,6 +228,41 @@ function __bobthefish_prompt_user -d 'Display actual user if different from $def
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function __bobthefish_prompt_hg -d 'Display the actual hg state'
|
||||||
|
set -l dirty (command hg stat; or echo -n '*')
|
||||||
|
|
||||||
|
set -l flags "$dirty"
|
||||||
|
test "$flags"; and set flags ""
|
||||||
|
|
||||||
|
set -l flag_bg $__bobthefish_lt_green
|
||||||
|
set -l flag_fg $__bobthefish_dk_green
|
||||||
|
if test "$dirty"
|
||||||
|
set flag_bg $__bobthefish_med_red
|
||||||
|
set flag_fg fff
|
||||||
|
end
|
||||||
|
|
||||||
|
__bobthefish_path_segment (__bobthefish_hg_project_dir)
|
||||||
|
|
||||||
|
__bobthefish_start_segment $flag_bg $flag_fg
|
||||||
|
echo -n -s $__bobthefish_hg_glyph ' '
|
||||||
|
|
||||||
|
__bobthefish_start_segment $flag_bg $flag_fg
|
||||||
|
set_color $flag_fg --bold
|
||||||
|
echo -n -s (__bobthefish_hg_branch) $flags ' '
|
||||||
|
set_color normal
|
||||||
|
|
||||||
|
set -l project_pwd (__bobthefish_project_pwd (__bobthefish_hg_project_dir))
|
||||||
|
if test "$project_pwd"
|
||||||
|
if test -w "$PWD"
|
||||||
|
__bobthefish_start_segment 333 999
|
||||||
|
else
|
||||||
|
__bobthefish_start_segment $__bobthefish_med_red $__bobthefish_lt_red
|
||||||
|
end
|
||||||
|
|
||||||
|
echo -n -s $project_pwd ' '
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: clean up the fugly $ahead business
|
# TODO: clean up the fugly $ahead business
|
||||||
function __bobthefish_prompt_git -d 'Display the actual git state'
|
function __bobthefish_prompt_git -d 'Display the actual git state'
|
||||||
set -l dirty (command git diff --no-ext-diff --quiet --exit-code; or echo -n '*')
|
set -l dirty (command git diff --no-ext-diff --quiet --exit-code; or echo -n '*')
|
||||||
@ -239,14 +288,14 @@ function __bobthefish_prompt_git -d 'Display the actual git state'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
__bobthefish_path_segment (__bobthefish_project_dir)
|
__bobthefish_path_segment (__bobthefish_git_project_dir)
|
||||||
|
|
||||||
__bobthefish_start_segment $flag_bg $flag_fg
|
__bobthefish_start_segment $flag_bg $flag_fg
|
||||||
set_color $flag_fg --bold
|
set_color $flag_fg --bold
|
||||||
echo -n -s (__bobthefish_git_branch) $flags ' '
|
echo -n -s (__bobthefish_git_branch) $flags ' '
|
||||||
set_color normal
|
set_color normal
|
||||||
|
|
||||||
set -l project_pwd (__bobthefish_project_pwd)
|
set -l project_pwd (__bobthefish_project_pwd (__bobthefish_git_project_dir))
|
||||||
if test "$project_pwd"
|
if test "$project_pwd"
|
||||||
if test -w "$PWD"
|
if test -w "$PWD"
|
||||||
__bobthefish_start_segment 333 999
|
__bobthefish_start_segment 333 999
|
||||||
@ -296,14 +345,15 @@ end
|
|||||||
# ===========================
|
# ===========================
|
||||||
|
|
||||||
function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
|
function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
|
||||||
set -g RETVAL $status
|
|
||||||
__bobthefish_prompt_status
|
__bobthefish_prompt_status
|
||||||
__bobthefish_prompt_user
|
__bobthefish_prompt_user
|
||||||
if __bobthefish_in_virtualfish_virtualenv
|
if __bobthefish_in_virtualfish_virtualenv
|
||||||
__bobthefish_prompt_virtualfish
|
__bobthefish_prompt_virtualfish
|
||||||
end
|
end
|
||||||
if __bobthefish_in_git
|
if __bobthefish_in_git # TODO: do this right.
|
||||||
__bobthefish_prompt_git
|
__bobthefish_prompt_git # if something is in both git and hg, check the length of
|
||||||
|
else if __bobthefish_in_hg # __bobthefish_git_project_dir vs __bobthefish_hg_project_dir
|
||||||
|
__bobthefish_prompt_hg # and pick the longer of the two.
|
||||||
else
|
else
|
||||||
__bobthefish_prompt_dir
|
__bobthefish_prompt_dir
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user