├── .gitignore ├── test ├── untracked.fish ├── add.fish ├── renamed.fish ├── deleted.fish └── modified.fish ├── .travis.yml ├── LICENSE ├── README.md └── functions └── git_porcelain.fish /.gitignore: -------------------------------------------------------------------------------- 1 | /README.html 2 | -------------------------------------------------------------------------------- /test/untracked.fish: -------------------------------------------------------------------------------- 1 | set path $DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path 5 | pushd $path 6 | git init . > /dev/null 7 | end 8 | 9 | function teardown 10 | popd 11 | rm -rf $path 12 | end 13 | 14 | test "uu-1" 15 | "1U" = (touch a;and git_porcelain -C) 16 | end 17 | 18 | test "uu-2" 19 | "2U" = (touch a b;and git_porcelain -C) 20 | end 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | before_install: 3 | - sudo add-apt-repository -y ppa:fish-shell/release-2 4 | - sudo add-apt-repository ppa:git-core/ppa -y 5 | - sudo apt-get update 6 | - sudo apt-get -y install fish git 7 | script: 8 | - curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs git.io/fisherman 9 | - fish -c "fisher i fishtape .; fishtape test/*.fish" -------------------------------------------------------------------------------- /test/add.fish: -------------------------------------------------------------------------------- 1 | set path $DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path 5 | pushd $path 6 | git init . > /dev/null 7 | end 8 | 9 | function teardown 10 | popd 11 | rm -rf $path 12 | end 13 | 14 | test "sa-1" 15 | "1A" = (touch a; and git add a; and git_porcelain -C) 16 | end 17 | 18 | test "sa-2" 19 | "2A" = (touch a b; and git add a b;and git_porcelain -C) 20 | end 21 | -------------------------------------------------------------------------------- /test/renamed.fish: -------------------------------------------------------------------------------- 1 | set path $DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path 5 | pushd $path 6 | git init . > /dev/null 7 | touch a b c 8 | git add a b c 9 | git config user.email "foo@bar.com" 10 | git config user.name "foobar" 11 | git commit -m "Added a" > /dev/null 12 | end 13 | 14 | function teardown 15 | popd 16 | rm -rf $path 17 | end 18 | 19 | test "sr-1" 20 | "1R" = (mv a d; git add -A; git_porcelain -C) 21 | end 22 | 23 | test "sr-2" 24 | "2R" = (mv a d; mv b e; git add -A; git_porcelain -C) 25 | end 26 | -------------------------------------------------------------------------------- /test/deleted.fish: -------------------------------------------------------------------------------- 1 | set path $DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path 5 | pushd $path 6 | git init . > /dev/null 7 | touch a b c 8 | git add a b c 9 | git config user.email "foo@bar.com" 10 | git config user.name "foobar" 11 | git commit -m "Added a b c" > /dev/null 12 | end 13 | 14 | function teardown 15 | popd 16 | rm -rf $path 17 | end 18 | 19 | test "sd-1" 20 | "1D" = (rm c;git add -A;and git_porcelain -C) 21 | end 22 | 23 | test "sd-2" 24 | "2D" = (rm b c;git add -A;and git_porcelain -C) 25 | end 26 | 27 | test "ud-1" 28 | "1D" = (rm c;and git_porcelain -C) 29 | end 30 | 31 | test "ud-2" 32 | "2D" = (rm b c;and git_porcelain -C) 33 | end 34 | 35 | test "sd-1 ud-2" 36 | "1D 2D" = (rm a b c; git add a;and git_porcelain -C) 37 | end 38 | 39 | test "sd-2 ud-2" 40 | "2D 1D" = (rm a b c; git add a b;and git_porcelain -C) 41 | end 42 | -------------------------------------------------------------------------------- /test/modified.fish: -------------------------------------------------------------------------------- 1 | set path $DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path 5 | pushd $path 6 | git init . > /dev/null 7 | touch a b c 8 | git add a b c 9 | git config user.email "foo@bar.com" 10 | git config user.name "foobar" 11 | git commit -m "Added a b c" > /dev/null 12 | end 13 | 14 | function teardown 15 | popd 16 | rm -rf $path 17 | end 18 | 19 | test "sm-1" 20 | "1M" = (echo a > a; and git add a; and git_porcelain -C) 21 | end 22 | 23 | test "sm-2" 24 | "2M" = (echo a > a; echo b > b; and git add a b;and git_porcelain -C) 25 | end 26 | 27 | test "um-1" 28 | "1M" = (echo a > a; and git_porcelain -C) 29 | end 30 | 31 | test "um-2" 32 | "2M" = (echo a > a; echo b > b;and git_porcelain -C) 33 | end 34 | 35 | test "sm-1 um-2" 36 | "1M 2M" = (echo a > a; echo b > b; echo c > c;and git add a;and git_porcelain -C) 37 | end 38 | 39 | test "sm-2 um-1" 40 | "2M 1M" = (echo a > a; echo b > b; echo c > c;and git add a b;and git_porcelain -C) 41 | end 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright Jethro Kuan 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Slack Room][slack-badge]][slack-link] 2 | [![Travis][travis-badge]][travis-link] 3 | 4 | # Git_porcelain 5 | 6 | User-friendly [Git status] output information inspired and adapted from [git-radar]. 7 | 8 | ![git_porcelain] 9 | 10 | ## Install 11 | 12 | With [fisherman] 13 | 14 | ``` 15 | fisher git_porcelain 16 | ``` 17 | 18 | ## Usage 19 | 20 | Typically you'll store the result in a variable to be output later: 21 | 22 | ``` 23 | set gitporcelain (git_porcelain) 24 | ... 25 | printf "blah blah %s" $gitporcelain 26 | ``` 27 | 28 | > git_porcelain comes with colours by default. To disable colors, use `git_porcelain -C`. 29 | 30 | ## Legend 31 | 32 | ### Symbols 33 | 34 | Symbol | Meaning 35 | --------|-------- 36 | A | A file has been Added 37 | D | A file has been Deleted 38 | M | A file has been Modified 39 | R | A file has been Renamed 40 | C | A file has been Copied 41 | U | A file is untracked 42 | 43 | ### Colors 44 | 45 | Color | Meaning 46 | --------|-------- 47 | Green | Staged and ready to be committed (i.e. you have done a `git add`) 48 | Red | Unstaged, you'll need to `git add` them before you can commit 49 | Grey | Untracked, these are new files git is unaware of 50 | Yellow | Conflicted, these need resolved before they can be committed 51 | 52 | ## Prompts using git_porcelain 53 | 54 | 1. [jetty] 55 | 56 | [Git status]: https://git-scm.com/docs/git-status 57 | [git_porcelain]: http://i.imgur.com/EvA0dNI.png 58 | 59 | [slack-link]: https://fisherman-wharf.herokuapp.com/ 60 | [slack-badge]: https://fisherman-wharf.herokuapp.com/badge.svg 61 | [travis-badge]: https://img.shields.io/travis/fisherman/git_porcelain.svg 62 | [travis-link]: https://travis-ci.org/fisherman/git_porcelain 63 | [fisherman]: https://github.com/fisherman/fisherman 64 | [git-radar]:https://github.com/michaeldfallen/git-radar 65 | 66 | [jetty]:https://github.com/jethrokuan/jetty 67 | -------------------------------------------------------------------------------- /functions/git_porcelain.fish: -------------------------------------------------------------------------------- 1 | function git_porcelain 2 | set -l staged (set_color green) 3 | set -l unstaged (set_color red) 4 | set -l untracked (set_color -o black) 5 | set -l normal (set_color normal) 6 | set -l opts "" 7 | set -l empty 1 8 | 9 | if set -q argv[1] 10 | switch "$argv[1]" 11 | case "-C" "--no-color" 12 | set opts "no-color" 13 | case \* 14 | printf "%s is not a valid option." "$argv[1]" 15 | return 1 16 | end 17 | end 18 | 19 | git status --porcelain 2> /dev/null | awk ' 20 | 21 | BEGIN { 22 | sa=0; 23 | sm=0; 24 | sd=0; 25 | sr=0; 26 | sc=0; 27 | um=0; 28 | ud=0; 29 | uu=0; 30 | } 31 | 32 | /^A[MCDR ]/ { sa++ } 33 | /^M[ACDRM ]/ { sm++ } 34 | /^D[AMCR ]/ { sd++ } 35 | /^R[AMCD ]/ { sr++ } 36 | /^C[AMDR ]/ { sc++ } 37 | /^[ACDRM ]M/ { um++ } 38 | /^[AMCR ]D/ { ud++ } 39 | /^\?\?/ { uu++ } 40 | 41 | END { 42 | printf("%d %d %d %d %d %d %d %d", sa, sm, sd, sr, sc, um, ud, uu) 43 | } 44 | 45 | ' | read -a vars 46 | 47 | set legend "A" "M" "D" "R" "C" "M" "D" "U" 48 | 49 | if not contains -- no-color $opts 50 | echo -n -s $normal 51 | end 52 | 53 | for i in (seq 5) 54 | if test ! $vars[$i] -eq 0 55 | set empty 0 56 | if contains -- no-color $opts 57 | echo -n -s $vars[$i] $legend[$i] 58 | else 59 | echo -n -s $vars[$i] $staged $legend[$i] $normal 60 | end 61 | end 62 | end 63 | 64 | if test $vars[6] -gt 0 -o $vars[7] -gt 0 65 | if test 0 -eq $empty 66 | echo -n -s " " 67 | end 68 | end 69 | 70 | for i in (seq 6 7) 71 | if test ! $vars[$i] -eq 0 72 | set empty 0 73 | if contains -- no-color $opts 74 | echo -n -s $vars[$i] $legend[$i] 75 | else 76 | echo -n -s $vars[$i] $unstaged $legend[$i] $normal 77 | end 78 | end 79 | end 80 | 81 | if test ! $vars[8] -eq 0 82 | if test 0 -eq $empty 83 | echo -n -s " " 84 | end 85 | if contains -- no-color $opts 86 | echo -n -s $vars[8] "U" 87 | else 88 | echo -n -s $vars[8] $untracked "U" $normal 89 | end 90 | end 91 | end 92 | --------------------------------------------------------------------------------