diff --git a/LICENSE b/LICENSE index 03c1daf..18d9835 100644 --- a/LICENSE +++ b/LICENSE @@ -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. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index c5945ce..9e3ab55 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + #### Batman > A [Oh My Fish][omf-link] theme inspired by Batman. @@ -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. @@ -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 diff --git a/fish_greeting.fish b/fish_greeting.fish index a611263..da92d24 100644 --- a/fish_greeting.fish +++ b/fish_greeting.fish @@ -1,3 +1,3 @@ function fish_greeting - echo (__batman_color_dim)(uname -mnprs)(__batman_color_off) + echo -n '' end diff --git a/fish_prompt.fish b/fish_prompt.fish index 57b7ed1..7387756 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -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 diff --git a/fish_right_prompt.fish b/fish_right_prompt.fish index 5b2b6bb..e605ac2 100644 --- a/fish_right_prompt.fish +++ b/fish_right_prompt.fish @@ -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 diff --git a/fish_title.fish b/fish_title.fish index 34e2c5d..04e97c5 100644 --- a/fish_title.fish +++ b/fish_title.fish @@ -1,3 +1,3 @@ function fish_title - echo "$PWD | $_" | sed "s|$HOME|~|g" -end \ No newline at end of file + echo "$PWD | $_" | sed "s|$HOME|~|g" +end diff --git a/functions/__batman_color_dim.fish b/functions/__batman_color_dim.fish deleted file mode 100644 index 53f5ab1..0000000 --- a/functions/__batman_color_dim.fish +++ /dev/null @@ -1 +0,0 @@ -function __batman_color_dim; set_color 666; end diff --git a/functions/__batman_color_fst.fish b/functions/__batman_color_fst.fish deleted file mode 100644 index f9556f1..0000000 --- a/functions/__batman_color_fst.fish +++ /dev/null @@ -1 +0,0 @@ -function __batman_color_fst; set_color -o fa0; end diff --git a/functions/__batman_color_off.fish b/functions/__batman_color_off.fish deleted file mode 100644 index 4b1e4c4..0000000 --- a/functions/__batman_color_off.fish +++ /dev/null @@ -1 +0,0 @@ -function __batman_color_off; set_color normal; end diff --git a/functions/__batman_color_snd.fish b/functions/__batman_color_snd.fish deleted file mode 100644 index 591cf80..0000000 --- a/functions/__batman_color_snd.fish +++ /dev/null @@ -1 +0,0 @@ -function __batman_color_snd; set_color -o 36f; end diff --git a/functions/__batman_color_trd.fish b/functions/__batman_color_trd.fish deleted file mode 100644 index e3c8d25..0000000 --- a/functions/__batman_color_trd.fish +++ /dev/null @@ -1 +0,0 @@ -function __batman_color_trd; set_color -o f06; end diff --git a/functions/__color_dim.fish b/functions/__color_dim.fish new file mode 100644 index 0000000..05b6d5a --- /dev/null +++ b/functions/__color_dim.fish @@ -0,0 +1 @@ +function __color_dim; set_color 666; end diff --git a/functions/__color_off.fish b/functions/__color_off.fish new file mode 100644 index 0000000..c82d6db --- /dev/null +++ b/functions/__color_off.fish @@ -0,0 +1 @@ +function __color_off; set_color normal; end diff --git a/functions/__color_primary.fish b/functions/__color_primary.fish new file mode 100644 index 0000000..a77ed40 --- /dev/null +++ b/functions/__color_primary.fish @@ -0,0 +1 @@ +function __color_primary; set_color -o fa0; end diff --git a/functions/__color_secondary.fish b/functions/__color_secondary.fish new file mode 100644 index 0000000..c34fe78 --- /dev/null +++ b/functions/__color_secondary.fish @@ -0,0 +1 @@ +function __color_secondary; set_color -o 36f; end diff --git a/functions/__color_tertiary.fish b/functions/__color_tertiary.fish new file mode 100644 index 0000000..0c1d9cf --- /dev/null +++ b/functions/__color_tertiary.fish @@ -0,0 +1 @@ +function __color_tertiary; set_color -o f06; end