Created
October 23, 2012 01:14
-
-
Save yonchu/3936073 to your computer and use it in GitHub Desktop.
Gitリポジトリの色んな情報を表示. どんなリポジトリなのかを瞬時に把握するのに便利
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 実行イメージ | |
| $ gits | |
| ===== Status (git status -sb) ===== | |
| ## master...origin/master [ahead 1] | |
| M bin/gits | |
| ===== Remote Update Info ===== | |
| ## origin | |
| (fast-forwardable) git@github.com:yonchu/dotfiles.git | |
| ===== Submodule Status (git submodule status) ===== | |
| 9150244afd8cb992b90390ea9789054ed376c468 .tmux/tmux-powerline (heads/master) | |
| 1579b53125011063b6b37c3ffde8cc05023e29ad .tmux/tmux-powerline-wrapper (heads/master) | |
| 3b2a24914b9ff3a51673a1f2223c57a21dbda390 .vim/neobundle.vim (ver.2.0-190-g3b2a249) | |
| 4ac57be0cdcae5aa0f482916ae68e48187856df0 .zsh/dircolors-solarized (heads/master) | |
| f7c0f031cab5eca993e517200df68e43184ffcbf .zsh/functions/Completion/zsh-completions (0.3.0-89-gf7c0f03) | |
| dfd4308ae84da481f774b3f5e732ee277d9d8769 .zsh/z (v1.4-2-gdfd4308) | |
| 45194671af8e1d6b37b16e214a58674762ab8e49 .zsh/zsh-syntax-highlighting (0.1.2-2-g4519467) | |
| 2b4704d67920e89e2e809ff8eae058bae7d57c59 .zsh/zsh-vcs-prompt (heads/master) | |
| ===== Submodule Remote Update Info ===== | |
| (local out of date) https://github.com/erikw/tmux-powerline.git | |
| (local out of date) https://github.com/yonchu/tmux-powerline-wrapper.git | |
| (local out of date) git://github.com/Shougo/neobundle.vim.git | |
| (up to date) git://github.com/seebi/dircolors-solarized.git | |
| (up to date) https://github.com/zsh-users/zsh-completions.git | |
| (up to date) git://github.com/rupa/z.git | |
| (up to date) https://github.com/yonchu/zsh-syntax-highlighting.git | |
| (up to date) https://github.com/yonchu/zsh-vcs-prompt.git | |
| ===== Remote List (git remote -v) ===== | |
| github git@github.com:yonchu/dotfiles.git (fetch) | |
| github git@github.com:yonchu/dotfiles.git (push) | |
| origin /Users/yonchu/Dropbox/Repos/git/dotfiles.git (fetch) | |
| origin /Users/yonchu/Dropbox/Repos/git/dotfiles.git (push) | |
| ===== Branch List (git branch -av) ===== | |
| * master a49010a [ahead 1] Update .gitconfig, Add .gittemplate | |
| remotes/github/master 33c9001 Add a screenshot for iTerm on Mac | |
| remotes/origin/HEAD -> origin/master | |
| remotes/origin/master 33c9001 Add a screenshot for iTerm on Mac | |
| ===== Stash List (git stash list) ===== | |
| stash@{0}: WIP on master: a49010a Update .gitconfig, Add .gittemplate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Print detail infomation about current git repository. | |
| # | |
| if ! type git > /dev/null 2>&1; then | |
| echo 'Error: Git is not installed.' 2>%1 | |
| exit 1 | |
| fi | |
| if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then | |
| echo 'Error: Not a git repository' 2>&1 | |
| exit 1 | |
| fi | |
| cmd_remote_update_info(){ | |
| local remote_name=${1:-origin} | |
| echo "git remote show $remote_name \ | |
| | tail -1 | sed 's/.*\((.*)\)/\1/' | tr '\n' ' ' \ | |
| && git remote -v | head -1 | tr '\t' ' ' | cut -d' ' -f 2" | |
| } | |
| echo -e "===== \033[0;32mStatus (git status -sb)\033[0;39m =====" | |
| git status -sb | |
| echo -e "===== \033[0;32mRemote Update Info\033[0;39m =====" | |
| # HEAD branch (e.g. refs/heads/<branch-name>) | |
| head_branch=$(git symbolic-ref HEAD) | |
| if [ -z "$head_branch" ]; then | |
| prehash=$(git rev-parse --short HEAD) | |
| echo 'Not on any branch : prehash=$prehash' | |
| else | |
| # Retrieve brach name (like master) from HEAD branch | |
| branch=$(echo "$head_branch" | sed -E s/^.\{11\}//g) | |
| # The remote name of HEAD branch (e.g. origin) | |
| remote_name=$(git config branch."${branch}".remote) | |
| if [ -z "$remote_name" ]; then | |
| echo 'No remote repository' | |
| else | |
| echo -e "## \033[0;32m$remote_name\033[0;39m" | |
| eval $(cmd_remote_update_info "$remote_name") | |
| fi | |
| fi | |
| # Submodule | |
| ( | |
| cd "$(git rev-parse --show-toplevel)" >/dev/null 2>&1; | |
| echo -e "===== \033[0;33mSubmodule Status (git submodule status)\033[0;39m =====" | |
| sub_status=$(git submodule status) | |
| if [ -n "$sub_status" ]; then | |
| echo "$sub_status" | |
| echo -e "===== \033[0;33mSubmodule Remote Update Info\033[0;39m =====" | |
| origin_status=$(git submodule foreach "$(cmd_remote_update_info)") | |
| echo "$origin_status" | sed '/^Entering/d' | |
| fi | |
| ) | |
| echo -e "===== \033[0;34mRemote List (git remote -v)\033[0;39m =====" | |
| git remote -v | |
| echo -e "===== \033[0;35mBranch List (git branch -av)\033[0;39m =====" | |
| git branch -av | |
| echo -e "===== \033[0;36mStash List (git stash list)\033[0;39m =====" | |
| git stash list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment