Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix right prompt git commit count #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://dl.dropboxusercontent.com/u/56336/omf/omf-logo-optimised.svg" align="left" width="144px" height="144px"/>
<img src="https://cloud.githubusercontent.com/assets/8317250/7785620/0059f784-01d3-11e5-8a01-8edf6c4e2af7.png" align="left" width="144px" height="144px"/>

#### Batman
> A [Oh My Fish][omf-link] theme inspired by Batman.
Expand All @@ -20,7 +20,7 @@ _From left to right:_
+ `^` character denotes the current repository has [_stashed_](https://git-scm.com/book/no-nb/v1/Git-Tools-Stashing) changes.
+ `*` character denotes the current repository is dirty.
+ Display current branch.
+ Display number of commits in relation to the current branch.
+ Display number of commits in relation to the origin of current branch.
+ Display current time.
+ _Batman_ inspired colors.

Expand All @@ -36,7 +36,6 @@ _From left to right:_

> __Disclaimer:__ This work is not intended to infringe on any rights by and of the companies and/or individuals involved in the production of any series mentioned here. I don't own Batman.


[mit]: http://opensource.org/licenses/MIT
[author]: http://about.bucaran.me
[omf-link]: https://www.github.com/oh-my-fish/oh-my-fish
Expand Down
2 changes: 1 addition & 1 deletion fish_greeting.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function fish_greeting
echo (__batman_color_dim)(uname -mnprs)(__batman_color_off)
echo -n ''
end
26 changes: 13 additions & 13 deletions fish_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function fish_prompt
test $status -ne 0;
and set -l colors 600 900 c00
or set -l colors 333 666 aaa
test $status -ne 0
and set -l colors 600 900 c00
or set -l colors 333 666 aaa

set -l pwd (prompt_pwd)
set -l base (basename "$pwd")
set -l pwd (prompt_pwd)
set -l base (basename "$pwd")

set -l expr "s|~|"(__batman_color_fst)"^^"(__batman_color_off)"|g; \
s|/|"(__batman_color_snd)"/"(__batman_color_off)"|g; \
s|"$base"|"(__batman_color_fst)$base(__batman_color_off)" |g"
set -l expr "s|~|"(__color_primary)"^^"(__color_off)"|g; \
s|/|"(__color_secondary)"/"(__color_off)"|g; \
s|"$base"|"(__color_primary)$base(__color_off)" |g"

echo -n (echo "$pwd" | sed -e $expr)(__batman_color_off)
echo -n (echo "$pwd" | sed -e $expr)(__color_off)

for color in $colors
echo -n (set_color $color)">"
end
for color in $colors
echo -n (set_color $color)">"
end

echo -n " "
echo -n " "
end
130 changes: 101 additions & 29 deletions fish_right_prompt.fish
Original file line number Diff line number Diff line change
@@ -1,43 +1,115 @@
function git::is_stashed
command git rev-parse --verify --quiet refs/stash >/dev/null
command git rev-parse --verify --quiet refs/stash >/dev/null
end

function git::get_ahead_count
echo (command git log 2> /dev/null | grep '^commit' | wc -l | tr -d " ")
function git::print::is_stashed
if git::is_stashed
echo (__color_tertiary)"^"(__color_off)
else
echo ""
end
end

function git::branch_name
command git symbolic-ref --short HEAD
if git symbolic-ref --short HEAD >/dev/null 2>&1
echo (command git symbolic-ref --short HEAD 2> /dev/null)
else
echo (command git rev-parse --short HEAD)
end
end

function git::print::branch_name
echo (__color_primary)(git::branch_name)
end

function git::is_touched
test -n (echo (command git status --porcelain))
test -n (echo (command git status --porcelain))
end

function fish_right_prompt
set -l code $status
test $code -ne 0; and echo (__batman_color_dim)"("(__batman_color_trd)"$code"(__batman_color_dim)") "(__batman_color_off)

if test -n "$SSH_CONNECTION"
printf (__batman_color_trd)":"(__batman_color_dim)"$HOSTNAME "(__batman_color_off)
end

if git rev-parse 2> /dev/null
git::is_stashed; and echo (__batman_color_trd)"^"(__batman_color_off)
printf (__batman_color_snd)"("(begin
if git::is_touched
echo (__batman_color_trd)"*"(__batman_color_off)
else
function git::print::is_touched
if git::is_touched
echo (__color_tertiary)"*"(__color_off)
else
echo ""
end
end)(__batman_color_fst)(git::branch_name)(__batman_color_snd)(begin
set -l count (git::get_ahead_count)
if test $count -eq 0
echo ""
else
echo (__batman_color_trd)"+"(__batman_color_fst)$count
end
end

function git::remote_info

set -l branch $argv[1]
set -l remote_name (git config branch.$branch.remote)

if test -n "$remote_name"
set merge_name (git config branch.$branch.merge)
set merge_name_short (echo $merge_name | cut -c 12-)
else
set remote_name "origin"
set merge_name "refs/heads/$branch"
set merge_name_short $branch
end

if test $remote_name = '.' # local
set remote_ref $merge_name
else
set remote_ref "refs/remotes/$remote_name/$merge_name_short"
end

set -l rev_git (eval "git rev-list --left-right $remote_ref...HEAD" 2> /dev/null)
if test $status != "0"
set rev_git (eval "git rev-list --left-right $merge_name...HEAD")
end

for i in $rev_git
if echo $i | grep '>' >/dev/null
set isAhead $isAhead ">"
end
end)(__batman_color_snd)") "(__batman_color_off)
end
printf (__batman_color_dim)(date +%H(__batman_color_fst):(__batman_color_dim)%M(__batman_color_fst):(__batman_color_dim)%S)(__batman_color_off)" "
end

set -l remote_diff (count $rev_git)
set -l ahead (count $isAhead)
set -l behind (math $remote_diff - $ahead)

echo $ahead
echo $behind

end

function git::print::remote_info

set -l remote (git::remote_info (git::branch_name))
set -l ahead $remote[1]
set -l behind $remote[2]

if test $ahead != "0"
echo (__color_tertiary)" +"(__color_primary)$ahead
end

if test $behind != "0"
echo (__color_tertiary)" -"(__color_primary)$behind
end
end

function git::print
if git rev-parse 2>/dev/null
echo (git::print::is_stashed)
echo (__color_secondary)"("
echo (git::print::is_touched)
echo (git::print::branch_name)
echo (git::print::remote_info)
echo (__color_secondary)") "
echo (__color_off)
end
end

function fish_right_prompt
set -l code $status
test $code -ne 0; and echo (__color_dim)"("(__color_tertiary)"$code"(__color_dim)") "(__color_off)

if test -n "$SSH_CONNECTION"
printf (__color_tertiary)":"(__color_dim)"$HOSTNAME "(__color_off)
end

git::print

printf (__color_dim)(date +%H(__color_primary):(__color_dim)%M(__color_primary):(__color_dim)%S)(__color_off)" "
end
4 changes: 2 additions & 2 deletions fish_title.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function fish_title
echo "$PWD | $_" | sed "s|$HOME|~|g"
end
echo "$PWD | $_" | sed "s|$HOME|~|g"
end
1 change: 0 additions & 1 deletion functions/__batman_color_dim.fish

This file was deleted.

1 change: 0 additions & 1 deletion functions/__batman_color_fst.fish

This file was deleted.

1 change: 0 additions & 1 deletion functions/__batman_color_off.fish

This file was deleted.

1 change: 0 additions & 1 deletion functions/__batman_color_snd.fish

This file was deleted.

1 change: 0 additions & 1 deletion functions/__batman_color_trd.fish

This file was deleted.

1 change: 1 addition & 0 deletions functions/__color_dim.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function __color_dim; set_color 666; end
1 change: 1 addition & 0 deletions functions/__color_off.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function __color_off; set_color normal; end
1 change: 1 addition & 0 deletions functions/__color_primary.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function __color_primary; set_color -o fa0; end
1 change: 1 addition & 0 deletions functions/__color_secondary.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function __color_secondary; set_color -o 36f; end
1 change: 1 addition & 0 deletions functions/__color_tertiary.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function __color_tertiary; set_color -o f06; end