mirror of
https://github.com/oh-my-fish/oh-my-fish
synced 2024-11-03 15:40:32 +00:00
Merge pull request #203 from syl20bnr/syl20bnr_theme_improvements
This commit is contained in:
commit
f73426c258
@ -1,6 +1,9 @@
|
||||
# syl20bnr theme
|
||||
|
||||
Sylvain Benner personal, compact (hmmm...) yet complete (almost :-)) oh-my-fish theme.
|
||||
A semi-compact oh-my-fish theme with [nice support for git](#git).
|
||||
|
||||
The theme has been tested on `Ubuntu 14.04 (Trusty)` and `Mac OS X 10.10 (Yosemite)`.
|
||||
It is also compatible with [Cygwin with the appropriate packages](#cygwin-compatibility).
|
||||
|
||||
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
|
||||
|
||||
@ -47,28 +50,44 @@ replaced by the `git` segment (I should know where I am).
|
||||
The `git` segment format is `X:YI@Z:P(N)` where:
|
||||
- `X` is `git`
|
||||
- `Y` is the current branch name
|
||||
- `I` is the information about the current repository state
|
||||
- `I` is some information about the current repository state
|
||||
- `Z` is the name of the repository
|
||||
- `P` is the current working path basename (name of the current directory)
|
||||
If `P` = `Z` then `P(N)` is not displayed
|
||||
- `N` is the depth of the path starting from base directory of the repository
|
||||
|
||||
The displayed information `I` is:
|
||||
- Dirtiness is indicated by a little dot after the branch name.
|
||||
- Unpushed commits are indicated with up arrows
|
||||
- The number of unpushed commits is indicated right after the up arrows
|
||||
- Unpushed commits are indicated with an up arrow like this `[↑1]`
|
||||
- Unmerged fetched commits are indicated with a down arrow like this `[↓1]`
|
||||
|
||||
**Note:** The dirtiness of the current branch is indicated by its color:
|
||||
- red: it is dirty
|
||||
- green: it is up to date
|
||||
|
||||
**Note:** The unmerged commits count appears only if the changes in the
|
||||
upstream branch as been fetched.
|
||||
|
||||
#### Examples
|
||||
|
||||
Dirty:
|
||||
![dirty](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-dirty.png)
|
||||
Dirty (changes not committed):
|
||||
|
||||
![dirty](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-dirty2.png)
|
||||
|
||||
Unpushed commits:
|
||||
![unpushed_commits](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-ucommit-count.png)
|
||||
|
||||
![unpushed_commits](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unpushed.png)
|
||||
|
||||
Unmerged commits:
|
||||
|
||||
![unmerged_commits](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unmerged.png)
|
||||
|
||||
Both unpushed and unmerged commits:
|
||||
|
||||
![unmerged_commits](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-unpushed_unmerged.png)
|
||||
|
||||
In a sub-directory of the repository:
|
||||
![repo_subdir](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-subdir.png)
|
||||
|
||||
![repo_subdir](http://raw2.github.com/syl20bnr/oh-my-fish-theme-syl20bnr/master/screenshots/prompt_fish-syl20bnr-git-subdir2.png)
|
||||
|
||||
### vi-mode
|
||||
|
||||
|
@ -28,31 +28,16 @@ function __syl20bnr_git_repo_base -d "Return the current repository name"
|
||||
echo (command git rev-parse --show-toplevel ^/dev/null)
|
||||
end
|
||||
|
||||
function __syl20bnr_is_git_dirty -d "Check if there is uncommited changes"
|
||||
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
|
||||
end
|
||||
|
||||
function __syl20bnr_is_git_ahead -d "Check if there is unpushed commits"
|
||||
echo (command git status -s -b ^/dev/null | grep ahead)
|
||||
function __syl20bnr_git_status -d "git status command"
|
||||
git status -b -s --ignore-submodules=dirty
|
||||
end
|
||||
|
||||
function __syl20bnr_unpushed_commit_count -d "Return the number of unpushed commits"
|
||||
git status -s -b ^/dev/null | grep -E -o "ahead\ [0-9]+" | awk '{print $2}'
|
||||
echo $argv[1] | grep -E -o "ahead\ [0-9]+" | awk '{print $2}'
|
||||
end
|
||||
|
||||
function fish_vi_prompt_cm --description "Displays the current mode"
|
||||
switch $fish_bind_mode
|
||||
case default
|
||||
set_color --bold --background red white
|
||||
echo "[N]"
|
||||
case insert
|
||||
set_color --bold --background green white
|
||||
echo "[I]"
|
||||
case visual
|
||||
set_color --bold --background magenta white
|
||||
echo "[V]"
|
||||
end
|
||||
set_color normal
|
||||
function __syl20bnr_unmerged_commit_count -d "Return the number of unmerged commits"
|
||||
echo $argv[1] | grep -E -o "behind\ [0-9]+" | awk '{print $2}'
|
||||
end
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
@ -94,27 +79,34 @@ function fish_prompt -d "Write out the left prompt of the syl20bnr theme"
|
||||
# P is the current working path basename (name of the current directory)
|
||||
# C is the depth of the path starting from base directory of the repo
|
||||
# The displayed information is:
|
||||
# Dirtiness is indicated by a little dot after the branch name.
|
||||
# Unpushed commits are indicated with up arrows
|
||||
# The number of unpushed commits is indicated right after the up arrows
|
||||
# Note:
|
||||
# Dirtiness is indicated by the color of the branch name, red is dirty,
|
||||
# green is up-to-date.
|
||||
# If P = Z then P(C) is not displayed
|
||||
set -l ps_git ""
|
||||
set -l git_branch_name (__syl20bnr_git_branch_name)
|
||||
if test -n "$git_branch_name"
|
||||
set -l git_repo_name (__syl20bnr_git_repo_name)
|
||||
set -l git_info ""
|
||||
if test -n (__syl20bnr_is_git_ahead)
|
||||
set git_info $colbgreen"↑↑↑"$colnormal"("(__syl20bnr_unpushed_commit_count)")"
|
||||
set -l git_status (__syl20bnr_git_status)
|
||||
if echo $git_status | grep ahead > /dev/null
|
||||
set git_info "["$colbgreen"↑"(__syl20bnr_unpushed_commit_count $git_status)$colnormal"]"
|
||||
end
|
||||
if test -n (__syl20bnr_is_git_dirty)
|
||||
set git_info $git_info$colbred"·"
|
||||
if echo $git_status | grep behind > /dev/null
|
||||
set git_info "$git_info""["$colbred"↓"(__syl20bnr_unmerged_commit_count $git_status)$colnormal"]"
|
||||
end
|
||||
set ps_git $colbwhite"git:"$colbcyan$git_branch_name$git_info$colnormal"@"$colbred$git_repo_name
|
||||
set -l colbranch $colbgreen
|
||||
if echo $git_status | grep -E "\s\?\?\s|\sM\s|\sD\s" > /dev/null
|
||||
set colbranch $colbred
|
||||
end
|
||||
set ps_git $colbwhite"git:"$colbcyan$git_branch_name$git_info$colnormal"@"$colbranch$git_repo_name
|
||||
if test "$basedir_name" != "$git_repo_name"
|
||||
set -l basedir_depth (echo (__syl20bnr_git_repo_base) | sed "s/\// /g" | wc -w)
|
||||
set -l depth (echo (pwd) | sed "s/\// /g" | wc -w)
|
||||
set depth (math $depth - $basedir_depth)
|
||||
set ps_git $ps_git$colbwhite":"$colbgreen$basedir_name$colnormal"("$depth")"
|
||||
set ps_git $ps_git$colnormal":"$colbwhite$basedir_name$colnormal"("$depth")"
|
||||
end
|
||||
end
|
||||
|
||||
@ -151,7 +143,14 @@ function fish_prompt -d "Write out the left prompt of the syl20bnr theme"
|
||||
set ps_vi $colnormal"["$vi_mode$colnormal"]"
|
||||
end
|
||||
if test "$fish_key_bindings" = "fish_vi_key_bindings" -o "$fish_key_bindings" = "my_fish_key_bindings"
|
||||
set ps_vi (fish_vi_prompt_cm)
|
||||
switch $fish_bind_mode
|
||||
case default
|
||||
set ps_vi $colnormal"("$colred"N"$colnormal")"
|
||||
case insert
|
||||
set ps_vi $colnormal"("$colgreen"I"$colnormal")"
|
||||
case visual
|
||||
set ps_vi $colnormal"("$colwhite"V"$colnormal")"
|
||||
end
|
||||
end
|
||||
|
||||
# end of prompt
|
||||
|
Loading…
Reference in New Issue
Block a user