-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improved the 'git-info' command #755
Open
bbugyi200
wants to merge
7
commits into
tj:main
Choose a base branch
from
bbugyi200:colored-git-info
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c441e5
Add: colored output to git-info
bbugyi200 3b60b41
Doc: include git-info '-n' option in Commands.md
bbugyi200 b75b285
Mod: better use of whitespace in output
bbugyi200 9df13b9
Mod: clear screen before running commands in 'git-info'
bbugyi200 0ca9146
Add: --no-color option
bbugyi200 1d3de77
Mod: removed the -n option
bbugyi200 bf7dd69
Add: the '-c <N>' option (where '<N>' is an integer)
bbugyi200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,64 @@ | ||
#!/usr/bin/env bash | ||
|
||
get_config() { | ||
git config --list | ||
} | ||
clear | ||
|
||
most_recent_commit() { | ||
git log --max-count=1 --pretty=short | ||
} | ||
|
||
local_branches() { | ||
git branch | ||
} | ||
max_count=1 | ||
if [[ "$1" == "-c" ]]; then | ||
shift | ||
max_count="$1"; shift | ||
fi | ||
|
||
remote_branches() { | ||
git branch -r | ||
} | ||
color="--color=always" | ||
no_color="--no-color" | ||
if [[ "$1" == "${no_color}" ]]; then | ||
color="$1"; shift | ||
else | ||
if [[ "$2" == "${no_color}" ]]; then | ||
color="$2" | ||
fi | ||
fi | ||
|
||
remote_urls() { | ||
git remote -v | ||
|
||
header() { | ||
if [[ "${color}" != "${no_color}" ]]; then | ||
tput setaf 242 | ||
fi | ||
|
||
printf "### $1\n" | ||
|
||
if [[ "${color}" != "${no_color}" ]]; then | ||
tput sgr0 | ||
fi | ||
} | ||
|
||
echon() { | ||
echo "$@" | ||
echo | ||
git_cmd() { | ||
eval "$1" | ||
printf "\n" | ||
} | ||
|
||
|
||
# Show info similar to svn | ||
|
||
echo | ||
echon "## Remote URLs:" | ||
echon "$(remote_urls)" | ||
header "Remote URLs:" | ||
git_cmd "git remote -v" | ||
|
||
header "Remote Branches:" | ||
git_cmd "git branch -r ${color}" | ||
|
||
echon "## Remote Branches:" | ||
echon "$(remote_branches)" | ||
header "Local Branches:" | ||
git_cmd "git branch ${color}" | ||
|
||
echon "## Local Branches:" | ||
echon "$(local_branches)" | ||
if [[ "${max_count}" -ne 1 ]]; then | ||
header="Top ${max_count} Commits:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, |
||
else | ||
header="Most Recent Commit:" | ||
fi | ||
|
||
echon "## Most Recent Commit:" | ||
echon "$(most_recent_commit)" | ||
echon "Type 'git log' for more commits, or 'git show <commit id>' for full commit details." | ||
header "${header}" | ||
git_cmd "git --no-pager log --max-count=${max_count} --pretty=short ${color}" | ||
|
||
if test "$1" != "--no-config"; then | ||
echon "## Configuration (.git/config):" | ||
echon "$(get_config)" | ||
if [[ "$1" != "--no-config" ]]; then | ||
header "Configuration (.git/config):" | ||
git --no-pager config --list | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use a while loop to get rid of this limitation, like: https://github.com/tj/git-extras/blob/master/bin/git-release#L31