Skip to content

Commit

Permalink
Merge pull request #65 from Calinou/improve-interactive-menu
Browse files Browse the repository at this point in the history
Improve the interactive menu
  • Loading branch information
tomice committed May 13, 2019
2 parents 1282e4b + bdfe3be commit f3931eb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -115,6 +115,13 @@ You can exclude directory from the stats by using [pathspec](https://git-scm.com
export _GIT_PATHSPEC=':!directory'
```

#### Color themes

You can change to the legacy color scheme by toggling the variable `_MENU_THEME` between `default` and `legacy`

```bash
export _MENU_THEME=legacy
```

## Installation

Expand Down
71 changes: 50 additions & 21 deletions git-quick-stats
Expand Up @@ -24,6 +24,10 @@ else
_limit=10
fi

# Default menu theme
# Set the legacy theme by typing "export _MENU_THEME=legacy"
_theme="${_MENU_THEME:=default}"

################################################################################
# DESC: Checks to make sure the user has the appropriate utilities installed
# ARGS: None
Expand Down Expand Up @@ -111,7 +115,9 @@ ADDITIONAL USAGE
You can set _GIT_LIMIT for limited output log
ex: export _GIT_LIMIT=20
You can exclude a directory from the stats by using pathspec
ex: export _GIT_PATHSPEC=':!directory'"
ex: export _GIT_PATHSPEC=':!directory'
You can set _MENU_THEME to display the legacy color scheme
ex: export _MENU_THEME=legacy"
}

################################################################################
Expand All @@ -122,28 +128,51 @@ ADDITIONAL USAGE
function show_menu() {
local normal=$(tput sgr0)
local cyan=$(tput setaf 6)
local bold=$(tput bold)
local red=$(tput setaf 1)
local yellow=$(tput setaf 3)

echo -e "\n${red} Generate: ${normal}"
echo -e "${cyan} ${yellow} 1)${cyan} Contribution stats (by author) ${normal}"
echo -e "${cyan} ${yellow} 2)${cyan} Contribution stats (by author) on a specific branch ${normal}"
echo -e "${cyan} ${yellow} 3)${cyan} Git changelogs (last $_limit days)${normal}"
echo -e "${cyan} ${yellow} 4)${cyan} Git changelogs by author ${normal}"
echo -e "${cyan} ${yellow} 5)${cyan} My daily status ${normal}"
echo -e "${red} List: ${normal}"
echo -e "${cyan} ${yellow} 6)${cyan} Branch tree view (last $_limit)${normal}"
echo -e "${cyan} ${yellow} 7)${cyan} All branches (sorted by most recent commit) ${normal}"
echo -e "${cyan} ${yellow} 8)${cyan} All contributors (sorted by name) ${normal}"
echo -e "${cyan} ${yellow} 9)${cyan} Git commits per author ${normal}"
echo -e "${cyan} ${yellow} 10)${cyan} Git commits per date ${normal}"
echo -e "${cyan} ${yellow} 11)${cyan} Git commits per month ${normal}"
echo -e "${cyan} ${yellow} 12)${cyan} Git commits per weekday ${normal}"
echo -e "${cyan} ${yellow} 13)${cyan} Git commits per hour ${normal}"
echo -e "${cyan} ${yellow} 14)${cyan} Git commits by author per hour ${normal}"
echo -e "${red} Suggest: ${normal}"
echo -e "${cyan} ${yellow} 15)${cyan} Code reviewers (based on git history) ${normal}"
echo -e "\n${yellow}Please enter a menu option or ${red}press enter to exit. ${normal}"
local white=$(tput setaf 7)
local titles=""
local text=""
local nums=""
local help_txt=""
local exit_txt=""

# Adjustable color menu option
if [[ "${_theme}" == "legacy" ]]; then
titles="${bold}${red}"
text="${normal}${cyan}"
nums="${bold}${yellow}"
help_txt="${normal}${yellow}"
exit_txt="${bold}${red}"
else
titles="${bold}${cyan}"
text="${normal}${white}"
nums="${normal}${bold}${white}"
help_txt="${normal}${cyan}"
exit_txt="${bold}${cyan}"
fi

echo -e "\n${titles} Generate:${normal}"
echo -e "${nums} 1)${text} Contribution stats (by author)"
echo -e "${nums} 2)${text} Contribution stats (by author) on a specific branch"
echo -e "${nums} 3)${text} Git changelogs (last $_limit days)"
echo -e "${nums} 4)${text} Git changelogs by author"
echo -e "${nums} 5)${text} My daily status"
echo -e "\n${titles} List:"
echo -e "${nums} 6)${text} Branch tree view (last $_limit)"
echo -e "${nums} 7)${text} All branches (sorted by most recent commit)"
echo -e "${nums} 8)${text} All contributors (sorted by name)"
echo -e "${nums} 9)${text} Git commits per author"
echo -e "${nums} 10)${text} Git commits per date"
echo -e "${nums} 11)${text} Git commits per month"
echo -e "${nums} 12)${text} Git commits per weekday"
echo -e "${nums} 13)${text} Git commits per hour"
echo -e "${nums} 14)${text} Git commits by author per hour"
echo -e "\n${titles} Suggest:"
echo -e "${nums} 15)${text} Code reviewers (based on git history)"
echo -e "\n${help_txt}Please enter a menu option or ${exit_txt}press Enter to exit."
echo -n "${text}> ${normal}"
read -r opt
}

Expand Down
4 changes: 4 additions & 0 deletions git-quick-stats.1
Expand Up @@ -112,6 +112,10 @@ You can set _GIT_LIMIT for limited output log, example:
You can exclude a directory from the stats by using pathspec, example:
.PP
.B export _GIT_PATHSPEC=':!directory'
.PP
You can switch to the legacy color scheme, example:
.PP
.B export _MENU_THEME=legacy
.
.fi

2 changes: 1 addition & 1 deletion tests/commands_test.sh
Expand Up @@ -4,7 +4,7 @@

src="./git-quick-stats"
#assert "$src fail" "Invalid argument\n\nNAME\n git-quick-stats - Simple and efficient way to access various stats in a git repo\n\nSYNOPSIS\n For non-interactive mode: git-quick-stats [OPTIONS]\n For interactive mode: git-quick-stats\n\nDESCRIPTION\n Any git repository contains tons of information about commits, contributors,\n and files. Extracting this information is not always trivial, mostly because\n of a gadzillion options to a gadzillion git commands.\n\n This program allows you to see detailed information about a git repository.\n\nOPTIONS\n suggestReviewers - see best people to contact to review code\n detailedGitStats - displays a detailed list of git status\n commitsPerDay - displays a list of commits per day\n commitsByMonth - displays a list of commits per month\n commitsByWeekday - displays a list of commits per weekday\n commitsByHour - displays a list of commits per hour\n commitsByAuthorByHour - see a list of commits per hour by author\n commitsPerAuthor - displays a list of commits per author\n myDailyStats - see your current daily stats\n contributors - see a list of all contributors\n branchTree - see an ASCII graph of the git repo\n branchesByDate - show branches by date\n changelogs - see changelogs\n changelogsByAuthor - see changelogs by author\n\nADDITIONAL USAGE\n You can set _GIT_SINCE and _GIT_UNTIL to limit the git time log\n ex: export _GIT_SINCE=2017-20-01\n You can set _GIT_LIMIT for limited output log\n ex: export _GIT_LIMIT=20\n You can exclude a directory from the stats by using pathspec\n ex: export _GIT_PATHSPEC=':!directory'\n \nCONTRIBUTION\n For details regarding contribution, please see the contribution.md document\n\nLICENSE\n This is under the MIT license. See LICENSE in the repo for more info"
assert "$src fail" "Invalid argument\n\nNAME\n git-quick-stats - Simple and efficient way to access various stats in a git repo\n\nSYNOPSIS\n For non-interactive mode: git-quick-stats [OPTIONS]\n For interactive mode: git-quick-stats\n\nDESCRIPTION\n Any git repository contains tons of information about commits, contributors,\n and files. Extracting this information is not always trivial, mostly because\n of a gadzillion options to a gadzillion git commands.\n\n This program allows you to see detailed information about a git repository.\n\nOPTIONS\n -r, --suggest-reviewers\n show the best people to contact to review code\n -T, --detailed-git-stats\n give a detailed list of git stats\n -R, --git-stats-by-branch\n see detailed list of git stats by branch\n -d, --commits-per-day\n displays a list of commits per day\n -m, --commits-by-month\n displays a list of commits per month\n -w, --commits-by-weekday\n displays a list of commits per weekday\n -o, --commits-by-hour\n displays a list of commits per hour\n -A, --commits-by-author-by-hour\n displays a list of commits per hour by author\n -a, --commits-per-author\n displays a list of commits per author\n -S, --my-daily-stats\n see your current daily stats\n -C, --contributors\n see a list of everyone who contributed to the repo\n -b, --branch-tree\n show an ASCII graph of the git repo branch history\n -D, --branches-by-date\n show branches by date\n -c, --changelogs\n see changelogs\n -L, --changelogs-by-author\n see changelogs by author\n -h, -?, --help\n display this help text in the terminal\n\nADDITIONAL USAGE\n You can set _GIT_SINCE and _GIT_UNTIL to limit the git time log\n ex: export _GIT_SINCE=\"2017-20-01\"\n You can set _GIT_LIMIT for limited output log\n ex: export _GIT_LIMIT=20\n You can exclude a directory from the stats by using pathspec\n ex: export _GIT_PATHSPEC=':!directory'"
assert "$src fail" "Invalid argument\n\nNAME\n git-quick-stats - Simple and efficient way to access various stats in a git repo\n\nSYNOPSIS\n For non-interactive mode: git-quick-stats [OPTIONS]\n For interactive mode: git-quick-stats\n\nDESCRIPTION\n Any git repository contains tons of information about commits, contributors,\n and files. Extracting this information is not always trivial, mostly because\n of a gadzillion options to a gadzillion git commands.\n\n This program allows you to see detailed information about a git repository.\n\nOPTIONS\n -r, --suggest-reviewers\n show the best people to contact to review code\n -T, --detailed-git-stats\n give a detailed list of git stats\n -R, --git-stats-by-branch\n see detailed list of git stats by branch\n -d, --commits-per-day\n displays a list of commits per day\n -m, --commits-by-month\n displays a list of commits per month\n -w, --commits-by-weekday\n displays a list of commits per weekday\n -o, --commits-by-hour\n displays a list of commits per hour\n -A, --commits-by-author-by-hour\n displays a list of commits per hour by author\n -a, --commits-per-author\n displays a list of commits per author\n -S, --my-daily-stats\n see your current daily stats\n -C, --contributors\n see a list of everyone who contributed to the repo\n -b, --branch-tree\n show an ASCII graph of the git repo branch history\n -D, --branches-by-date\n show branches by date\n -c, --changelogs\n see changelogs\n -L, --changelogs-by-author\n see changelogs by author\n -h, -?, --help\n display this help text in the terminal\n\nADDITIONAL USAGE\n You can set _GIT_SINCE and _GIT_UNTIL to limit the git time log\n ex: export _GIT_SINCE=\"2017-20-01\"\n You can set _GIT_LIMIT for limited output log\n ex: export _GIT_LIMIT=20\n You can exclude a directory from the stats by using pathspec\n ex: export _GIT_PATHSPEC=':!directory'\n You can set _MENU_THEME to display the legacy color scheme\n ex: export _MENU_THEME=legacy"
assert_raises "$src fail" 1

assert_contains "$src --suggest-reviewers" "Suggested code reviewers (based on git history)" 127
Expand Down

0 comments on commit f3931eb

Please sign in to comment.