From 8b0ff070a037b063e739aeffe6ba645375dc08c4 Mon Sep 17 00:00:00 2001 From: Denis Kolesnikov Date: Sun, 16 Nov 2014 17:13:09 +0700 Subject: [PATCH 01/12] Gitignore changes --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 25f3b49..a45f8f3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ custom/* *.pyc *~ *.sw? +*.sublime* From 548008b67b68e6b5d1de794087e51b887b89b68d Mon Sep 17 00:00:00 2001 From: Denis Kolesnikov Date: Sun, 16 Nov 2014 17:47:15 +0700 Subject: [PATCH 02/12] Added simple mercurial pormpt to bobthefish theme --- themes/bobthefish/fish_prompt.fish | 55 +++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 1aeebf9..8f1bd34 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -71,6 +71,10 @@ 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 end +function __bobthefish_in_hg -d 'Check whether pwd is inside a hg repo' + command hg stat > /dev/null 2>&1 +end + function __bobthefish_git_branch -d 'Get the current git branch (or commitish)' set -l ref (command git symbolic-ref HEAD 2> /dev/null) if [ $status -gt 0 ] @@ -80,6 +84,11 @@ function __bobthefish_git_branch -d 'Get the current git branch (or commitish)' echo $ref | sed "s-refs/heads/-$__bobthefish_branch_glyph -" end +function __bobthefish_hg_branch -d 'Get the current hg branch' + set -g branch (hg branch ^/dev/null) + echo "$__bobthefish_branch_glyph $branch" +end + 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|/$||' end @@ -88,11 +97,21 @@ function __bobthefish_project_dir -d 'Print the current git project base directo command git rev-parse --show-toplevel 2>/dev/null end +function __bobthefish_project_dir_hg -d 'Print the current git project base directory' + command hg root 2>/dev/null +end + 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*$base_dir**g" -e 's*^/**' end +function __bobthefish_project_pwd_hg -d 'Print the working directory relative to project root' + set -l base_dir (__bobthefish_project_dir_hg) + echo "$PWD" | sed -e "s*$base_dir**g" -e 's*^/**' +end + + # =========================== # Segment functions @@ -214,6 +233,38 @@ function __bobthefish_prompt_user -d 'Display actual user if different from $def 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_project_dir_hg) + + __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_hg) + 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 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 '*') @@ -302,7 +353,9 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' if __bobthefish_in_virtualfish_virtualenv __bobthefish_prompt_virtualfish end - if __bobthefish_in_git + if __bobthefish_in_hg + __bobthefish_prompt_hg + else if __bobthefish_in_git __bobthefish_prompt_git else __bobthefish_prompt_dir From 212626b7bd10113bfdc0e1b41df07004b667a133 Mon Sep 17 00:00:00 2001 From: Denis Kolesnikov Date: Sun, 16 Nov 2014 17:54:58 +0700 Subject: [PATCH 03/12] Added bookmark support to bobthefish theme mercurial prompt --- themes/bobthefish/fish_prompt.fish | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 8f1bd34..23c9f0d 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -85,8 +85,9 @@ function __bobthefish_git_branch -d 'Get the current git branch (or commitish)' end function __bobthefish_hg_branch -d 'Get the current hg branch' - set -g branch (hg branch ^/dev/null) - echo "$__bobthefish_branch_glyph $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' From 30ac04ceda13b8c426fa43f8f273ebc732348b21 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 18:39:26 -0800 Subject: [PATCH 04/12] [bobthefish] Use `hg root` instead of `hg stat` for in_hg --- themes/bobthefish/fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 23c9f0d..85bbaf1 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -72,7 +72,7 @@ function __bobthefish_in_git -d 'Check whether pwd is inside a git repo' end function __bobthefish_in_hg -d 'Check whether pwd is inside a hg repo' - command hg stat > /dev/null 2>&1 + command hg root > /dev/null 2>&1 end function __bobthefish_git_branch -d 'Get the current git branch (or commitish)' From 5104ef35f43eaabbf03e0f7d9895f0674a362fc0 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 20:17:49 -0800 Subject: [PATCH 05/12] [bobthefish] Don't break when hg/git not found --- themes/bobthefish/fish_prompt.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 85bbaf1..76a88e0 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -68,11 +68,11 @@ set __bobthefish_lt_blue 326D9E # =========================== 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 hg root > /dev/null 2>&1 + command which hg > /dev/null 2>&1; and command hg stat > /dev/null 2>&1 end function __bobthefish_git_branch -d 'Get the current git branch (or commitish)' From f046c9c5422a83f0fa72c4adc84aed52d14fb624 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 18:40:30 -0800 Subject: [PATCH 06/12] =?UTF-8?q?[bobthefish]=20Add=20=E2=98=BF=20(mercury?= =?UTF-8?q?)=20glyph=20to=20hg=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it easier (possible?) to distinguish between hg and git repos at a glance. --- themes/bobthefish/fish_prompt.fish | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 76a88e0..4619006 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -31,6 +31,7 @@ set __bobthefish_detached_glyph \u27A6 set __bobthefish_nonzero_exit_glyph '! ' set __bobthefish_superuser_glyph '$ ' set __bobthefish_bg_job_glyph '% ' +set __bobthefish_hg_glyph \u263F # Python glyphs set __bobthefish_superscript_glyph \u00B9 \u00B2 \u00B3 @@ -249,6 +250,9 @@ function __bobthefish_prompt_hg -d 'Display the actual hg state' __bobthefish_path_segment (__bobthefish_project_dir_hg) + __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 ' ' From c61a13465ac984eb0293b7aacf7a2d7c900a17b6 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 18:43:32 -0800 Subject: [PATCH 07/12] [bobthefish] Switch git/hg priority in prompt Add TODO to do this right :P --- themes/bobthefish/fish_prompt.fish | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 4619006..95f174e 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -358,10 +358,10 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' if __bobthefish_in_virtualfish_virtualenv __bobthefish_prompt_virtualfish end - if __bobthefish_in_hg - __bobthefish_prompt_hg - else if __bobthefish_in_git - __bobthefish_prompt_git + if __bobthefish_in_git # TODO: do this right. + __bobthefish_prompt_git # if something is in both git and hg, check the length of + else if __bobthefish_in_hg # __bobthefish_project_dir vs __bobthefish_project_dir_hg + __bobthefish_prompt_hg # and pick the longer of the two. else __bobthefish_prompt_dir end From eecb144e1ee9bef774a292b28b1d91e4a6a698a3 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 20:21:28 -0800 Subject: [PATCH 08/12] Revert "Gitignore changes" This reverts commit 8b94f572f170510f8fb0e2f51a657e267dc86241. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index a45f8f3..25f3b49 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ custom/* *.pyc *~ *.sw? -*.sublime* From c84ae81a12aecf900b6300dc7704315f357816b3 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 20:33:45 -0800 Subject: [PATCH 09/12] [bobthefish] DRY: we don't need two pwd-relative-to-project funcs --- themes/bobthefish/fish_prompt.fish | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 95f174e..5ce300b 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -104,16 +104,9 @@ function __bobthefish_project_dir_hg -d 'Print the current git project base dire end 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*$base_dir**g" -e 's*^/**' + echo "$PWD" | sed -e "s*$argv[1]**g" -e 's*^/**' end -function __bobthefish_project_pwd_hg -d 'Print the working directory relative to project root' - set -l base_dir (__bobthefish_project_dir_hg) - echo "$PWD" | sed -e "s*$base_dir**g" -e 's*^/**' -end - - # =========================== # Segment functions @@ -258,7 +251,7 @@ function __bobthefish_prompt_hg -d 'Display the actual hg state' echo -n -s (__bobthefish_hg_branch) $flags ' ' set_color normal - set -l project_pwd (__bobthefish_project_pwd_hg) + set -l project_pwd (__bobthefish_project_pwd (__bobthefish_project_dir_hg)) if test "$project_pwd" if test -w "$PWD" __bobthefish_start_segment 333 999 @@ -302,7 +295,7 @@ function __bobthefish_prompt_git -d 'Display the actual git state' echo -n -s (__bobthefish_git_branch) $flags ' ' set_color normal - set -l project_pwd (__bobthefish_project_pwd) + set -l project_pwd (__bobthefish_project_pwd (__bobthefish_project_dir)) if test "$project_pwd" if test -w "$PWD" __bobthefish_start_segment 333 999 From 5662032b8741aeea697bb2e76a6b744ae8aeb797 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 20:35:51 -0800 Subject: [PATCH 10/12] [bobthefish] More consistent project dir func names --- themes/bobthefish/fish_prompt.fish | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 5ce300b..841ae8b 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -95,11 +95,11 @@ function __bobthefish_pretty_parent -d 'Print a parent directory, shortened to f echo -n (dirname $argv[1]) | sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g' -e 's|/$||' 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 end -function __bobthefish_project_dir_hg -d 'Print the current git project base directory' +function __bobthefish_hg_project_dir -d 'Print the current hg project base directory' command hg root 2>/dev/null end @@ -241,7 +241,7 @@ function __bobthefish_prompt_hg -d 'Display the actual hg state' set flag_fg fff end - __bobthefish_path_segment (__bobthefish_project_dir_hg) + __bobthefish_path_segment (__bobthefish_hg_project_dir) __bobthefish_start_segment $flag_bg $flag_fg echo -n -s $__bobthefish_hg_glyph ' ' @@ -251,7 +251,7 @@ function __bobthefish_prompt_hg -d 'Display the actual hg state' echo -n -s (__bobthefish_hg_branch) $flags ' ' set_color normal - set -l project_pwd (__bobthefish_project_pwd (__bobthefish_project_dir_hg)) + set -l project_pwd (__bobthefish_project_pwd (__bobthefish_hg_project_dir)) if test "$project_pwd" if test -w "$PWD" __bobthefish_start_segment 333 999 @@ -288,14 +288,14 @@ function __bobthefish_prompt_git -d 'Display the actual git state' end end - __bobthefish_path_segment (__bobthefish_project_dir) + __bobthefish_path_segment (__bobthefish_git_project_dir) __bobthefish_start_segment $flag_bg $flag_fg set_color $flag_fg --bold echo -n -s (__bobthefish_git_branch) $flags ' ' set_color normal - set -l project_pwd (__bobthefish_project_pwd (__bobthefish_project_dir)) + set -l project_pwd (__bobthefish_project_pwd (__bobthefish_git_project_dir)) if test "$project_pwd" if test -w "$PWD" __bobthefish_start_segment 333 999 @@ -353,7 +353,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' end if __bobthefish_in_git # TODO: do this right. __bobthefish_prompt_git # if something is in both git and hg, check the length of - else if __bobthefish_in_hg # __bobthefish_project_dir vs __bobthefish_project_dir_hg + 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 __bobthefish_prompt_dir From c839fafda30d232bb39493662c1ac2cd0ce080d5 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 20:45:13 -0800 Subject: [PATCH 11/12] [bobthefish] Mention hg in README :) --- themes/bobthefish/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/themes/bobthefish/README.md b/themes/bobthefish/README.md index 3f30f0e..07861ee 100644 --- a/themes/bobthefish/README.md +++ b/themes/bobthefish/README.md @@ -29,9 +29,9 @@ This theme is based loosely on [agnoster][agnoster]. * You currently have superpowers ($) * User@Host (unless you're the default user) * Abbreviated parent directory - * Current directory or Git project name - * Current project's Git branch ( master) or detached head (➦ d0dfd9b) - * Git status, via colors and flags: + * Current directory, or Git or Mercurial project name + * Current project's repo branch ( master) or detached head (➦ d0dfd9b) + * Git or Mercurial status, via colors and flags: * Dirty working directory (*) * Untracked files (…) * Staged changes (~) @@ -39,6 +39,7 @@ This theme is based loosely on [agnoster][agnoster]. * Unpulled commits (-) * Unpushed commits (+) * Unpulled *and* unpushed commits (±) + * _Note that not all of these have been implemented for hg yet :)_ * Abbreviated project-relative path From 1bb40b401963a4c3b7b7fc0c2bc51e3b33bd9ec4 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 17 Nov 2014 21:03:12 -0800 Subject: [PATCH 12/12] No need to save $RETVAL, $status works just fine --- themes/bobthefish/fish_prompt.fish | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/themes/bobthefish/fish_prompt.fish b/themes/bobthefish/fish_prompt.fish index 841ae8b..32efc56 100644 --- a/themes/bobthefish/fish_prompt.fish +++ b/themes/bobthefish/fish_prompt.fish @@ -181,7 +181,7 @@ function __bobthefish_prompt_status -d 'Display symbols for a non zero exit stat set -l bg_jobs # Last exit was nonzero - if [ $RETVAL -ne 0 ] + if [ $status -ne 0 ] set nonzero $__bobthefish_nonzero_exit_glyph end @@ -345,7 +345,6 @@ end # =========================== function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' - set -g RETVAL $status __bobthefish_prompt_status __bobthefish_prompt_user if __bobthefish_in_virtualfish_virtualenv