Skip to content

Commit 49cfdd5

Browse files
author
Bhavi Dhingra
committed
style(gbranchout): header and preview changes
1 parent 63e090c commit 49cfdd5

File tree

11 files changed

+128
-53
lines changed

11 files changed

+128
-53
lines changed

cmd/gbranchout

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,30 @@ function main() {
2020

2121
__assertgitrepo
2222

23+
echo
24+
2325
local branchName=""
24-
print_branch_name "${branchName}"
26+
printf "${branchName}"
2527

2628
local prefix="$(get_prefix)"
2729
[ -n "${prefix}" ] && branchName="${prefix}/"
28-
print_branch_name "${branchName}"
30+
printf "${branchName}"
2931

3032
local branchType="$(get_branch_type)"
3133
[ -n "${branchType}" ] && branchName="${branchName}${branchType}/"
32-
print_branch_name "${branchName}"
34+
printf "${branchName}"
3335

3436
local name="$(get_branch_name)"
3537
[ -z "${name}" ] && {
3638
__print_info "branch name can't be empty"
3739
return
3840
}
3941
branchName="${branchName}${name}"
40-
print_branch_name "${branchName}"
42+
printf "${branchName}"
4143

4244
printf "\r"
4345

44-
local confirmation="$(__ask "Create branch ${REVERSE}${branchName}${RESET} ?" "false")"
46+
local confirmation="$(__ask "Create branch ${BLUE}${branchName}${RESET} ?" "false")"
4547
[ "${confirmation}" != "yes" ] && return
4648

4749
git branch "${branchName}"
@@ -51,50 +53,55 @@ function main() {
5153
exit ${FAILURE}
5254
fi
5355

54-
local switch="$(__ask "Switch to the new branch ${REVERSE}${branchName}${RESET} ?")"
56+
local switch="$(__ask "Switch to the new branch ${BLUE}${branchName}${RESET} ?")"
5557
[ "${switch}" == "yes" ] && git checkout "${branchName}"
5658
}
5759

5860
function get_prefix() {
5961

60-
local GBRANCHOUT_PREFIX_HEADER="$(__prefix_header)"
62+
local PREFIX_HEADER="$(__prefix_header)"
6163
local prefix="$(echo "" | grep "x" |\
62-
fzf --height 10%\
64+
fzf --height 40%\
6365
--info=hidden\
6466
--bind 'enter:print-query'\
65-
--header "${GBRANCHOUT_PREFIX_HEADER}")"
67+
--header "${PREFIX_HEADER}"\
68+
--bind '?:toggle-preview'\
69+
--preview-window hidden\
70+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gbranchcreate/__prefix_preview;
71+
__prefix_preview")"
6672
echo "${prefix}"
6773
}
6874

6975
function get_branch_type() {
7076

71-
local GBRANCHOUT_TYPE_HEADER="$(__type_header)"
77+
local TYPE_HEADER="$(__type_header)"
7278
local branchTypes=("feat" "fix" "perf" "refactor" "test" "style" "docs" "build" "ci" "cd")
7379

7480
local branchType="$(printf "%s\n" "${branchTypes[@]}" |\
75-
fzf --height=60% --preview-window :10%\
76-
--header "${GBRANCHOUT_TYPE_HEADER}"\
81+
fzf --height=70% --preview-window :30%\
82+
--info=hidden\
83+
--header "${TYPE_HEADER}"\
7784
--bind '?:toggle-preview'\
7885
--preview-window hidden\
79-
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gcommit_type_preview; __gcommit_type_preview {}")"
86+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gbranchcreate/__type_preview;
87+
__type_preview {}")"
8088

8189
echo "${branchType}"
8290
}
8391

8492
function get_branch_name() {
8593

86-
local GBRANCHOUT_NAME_HEADER="$(__name_header)"
94+
local NAME_HEADER="$(__name_header)"
8795
local name="$(echo "" | grep "x" |\
88-
fzf --height 10%\
96+
fzf --height 35%\
8997
--info=hidden\
9098
--bind 'enter:print-query'\
91-
--header "${GBRANCHOUT_NAME_HEADER}")"
99+
--header "${NAME_HEADER}"\
100+
--bind '?:toggle-preview'\
101+
--preview-window hidden\
102+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gbranchcreate/__name_preview;
103+
__name_preview")"
92104
echo "${name}"
93105
}
94106

95-
function print_branch_name() {
96-
__print_as "bold" "FORMATTED BRANCH NAME:- "
97-
printf "${REVERSE}${1}${RESET}"
98-
}
99-
100107
main

cmd/gcommit

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ function get_commit_type() {
121121
--header "${GCOMMIT_TYPE_HEADER}"\
122122
--bind '?:toggle-preview'\
123123
--preview-window ${previewVisibility}\
124-
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gcommit_type_preview;
125-
__gcommit_type_preview {} ${isBreakingChange}")"
124+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gcommit/__type_preview;
125+
__type_preview {} ${isBreakingChange}")"
126126

127127
echo "${commitType}"
128128
}
@@ -145,8 +145,8 @@ function get_commit_scope() {
145145
--header "${GCOMMIT_SCOPE_HEADER}"\
146146
--bind '?:toggle-preview'\
147147
--preview-window hidden\
148-
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gcommit_scope_preview;
149-
__gcommit_scope_preview ${isBreakingChange}")"
148+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gcommit/__scope_preview;
149+
__scope_preview ${isBreakingChange}")"
150150

151151
echo "${commitScope}"
152152
}
@@ -189,8 +189,8 @@ function get_commit_description() {
189189
--header "${GCOMMIT_DESCRIPTION_HEADER}"\
190190
--bind '?:toggle-preview'\
191191
--preview-window hidden\
192-
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gcommit_description_preview;
193-
__gcommit_description_preview ${isBreakingChange}")"
192+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/gcommit/__description_preview;
193+
__description_preview ${isBreakingChange}")"
194194
echo "${commitDescription}"
195195
}
196196

util/fzf_headers/gbranchout/__name_header

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ source "$__CUSTOM_CONSOLE_UTIL"/__common
88

99
function __name_header() {
1010

11-
local colorMsg="What is the branch name?\n"
12-
colorMsg="${colorMsg}${BLUE}<esc>: ${RESET}exits, "
13-
colorMsg="${colorMsg}${BLUE}<enter>: ${RESET}ends the branch name with the input\n\n"
14-
colorMsg="${colorMsg}${UNDERLINE}${MAGENTA}gbranchout${RESET} follows the format ${BLUE}[optional prefix]/[optional type]/${MAGENTA}<branch_name>${RESET}"
11+
local colorMsg="${BLUE}<?>:${RESET} help, ${BLUE}<esc>:${RESET} exit"
1512

16-
local msg="gbranchout follows the format [optional prefix]/[optional type]/<branch_name>"
17-
local edge="$(echo "${msg}" | sed "s/./-/g")"
18-
local GBRANCHOUT_NAME_HEADER="${edge}\n${colorMsg}"
13+
local edge="------------------------------------------"
14+
local NAME_HEADER="${edge}\n${colorMsg}\n "
1915

20-
echo -e "${GBRANCHOUT_NAME_HEADER}"
16+
echo -e "${NAME_HEADER}"
2117
}

util/fzf_headers/gbranchout/__prefix_header

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ source "$__CUSTOM_CONSOLE_UTIL"/__common
88

99
function __prefix_header() {
1010

11-
local colorMsg="(optional) Give a prefix to the branch name (e.g. issue number / JIRA ticket etc.)\n"
12-
colorMsg="${colorMsg}${BLUE}<esc>: ${RESET}skips the prefix, "
13-
colorMsg="${colorMsg}${BLUE}<enter>: ${RESET}starts the branch name with the input prefix\n\n"
14-
colorMsg="${colorMsg}${UNDERLINE}${MAGENTA}gbranchout${RESET} follows the format ${MAGENTA}[optional prefix]${BLUE}/[optional type]/<branch_name>${RESET}"
11+
local colorMsg="Write a prefix\n\n"
12+
colorMsg="${colorMsg}${BLUE}<?>:${RESET} help, ${BLUE}<esc>:${RESET} skip prefix"
1513

16-
local msg="(optional) Give a prefix to the branch name (e.g. issue number / JIRA ticket etc.)"
14+
local msg="<?>: help, <esc>: skip prefix"
1715
local edge="$(echo "${msg}" | sed "s/./-/g")"
18-
local GBRANCHOUT_PREFIX_HEADER="${edge}\n${colorMsg}"
16+
local GBRANCHCREATE_HEADER="${edge}\n${colorMsg}\n "
1917

20-
echo -e "${GBRANCHOUT_PREFIX_HEADER}"
18+
echo -e "${GBRANCHCREATE_HEADER}"
2119
}

util/fzf_headers/gbranchout/__type_header

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ source "$__CUSTOM_CONSOLE_UTIL"/__common
88

99
function __type_header() {
1010

11-
local colorMsg="Select the type of branch you're creating\n"
12-
colorMsg="${colorMsg}${BLUE}<?>: ${RESET}toggles type definition, "
13-
colorMsg="${colorMsg}${BLUE}<esc>: ${RESET}skips the branch type, "
14-
colorMsg="${colorMsg}${BLUE}<enter>: ${RESET}selects the branch type\n\n"
15-
colorMsg="${colorMsg}${UNDERLINE}${MAGENTA}gbranchout${RESET} follows the format ${BLUE}[optional prefix]/${MAGENTA}[optional type]${BLUE}/<branch_name>${RESET}"
11+
local colorMsg="${BLUE}<?>:${RESET} help, ${BLUE}<esc>:${RESET} skip branch type"
1612

17-
local msg=" <?>: toggles type definition, <esc>: skips the branch type, <enter>: selects the branch type"
13+
local msg="<?>: help, <esc>: skip branch type"
1814
local edge="$(echo "${msg}" | sed "s/./-/g")"
19-
local GBRANCHOUT_TYPE_HEADER="${edge}\n${colorMsg}\n${edge}\n "
15+
local TYPE_HEADER="${edge}\n${colorMsg}\n${edge}\n "
2016

21-
echo -e "${GBRANCHOUT_TYPE_HEADER}"
17+
echo -e "${TYPE_HEADER}"
2218
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__println_as was not specified as input (see shellcheck -x)
4+
5+
source "$__CUSTOM_CONSOLE_UTIL"/__println_as
6+
source "$__CUSTOM_CONSOLE_UTIL"/__common
7+
8+
function __name_preview() {
9+
10+
local colorMsg="[optional <prefix>]/[optional <type>]/${MAGENTA}<name>${RESET}\n"
11+
colorMsg="${colorMsg}${MAGENTA}\t\t\t\t\t\t\t\t\t\t│${RESET}\n"
12+
colorMsg="${colorMsg}${MAGENTA}\t\t\t\t\t\t\t\t\t\t│${RESET}\n"
13+
colorMsg="${colorMsg}${MAGENTA}\t\t\t\t\t\t\t\t\t\t└─⫸ "
14+
colorMsg="${colorMsg}a-short-branch-name${RESET}"
15+
16+
echo -e "\n${colorMsg}"
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__println_as was not specified as input (see shellcheck -x)
4+
5+
source "$__CUSTOM_CONSOLE_UTIL"/__println_as
6+
source "$__CUSTOM_CONSOLE_UTIL"/__common
7+
8+
function __prefix_preview() {
9+
10+
local colorMsg="${MAGENTA}[optional <prefix>]${RESET}/[optional <type>]/<name>\n"
11+
colorMsg="${colorMsg}${MAGENTA}${RESET}\n"
12+
colorMsg="${colorMsg}${MAGENTA}${RESET}\n"
13+
colorMsg="${colorMsg}${MAGENTA} └─⫸ "
14+
colorMsg="${colorMsg}e.g. issue number or JIRA ticket${RESET}"
15+
16+
echo -e "\n${colorMsg}"
17+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__println_as was not specified as input (see shellcheck -x)
4+
5+
source "$__CUSTOM_CONSOLE_UTIL"/__println_as
6+
source "$__CUSTOM_CONSOLE_UTIL"/__common
7+
8+
function __type_preview() {
9+
10+
local commit_type="${1}"
11+
12+
case "${commit_type}" in
13+
feat) __println_as bold "${commit_type}: A new feature"
14+
;;
15+
fix) __println_as bold "${commit_type}: A bug fix"
16+
;;
17+
perf) __println_as bold "${commit_type}: A code change that improves performance"
18+
;;
19+
refactor) __println_as bold "${commit_type}: A code change that neither fixes a bug nor adds a feature"
20+
;;
21+
test) __println_as bold "${commit_type}: Add missing tests or correct existing tests"
22+
;;
23+
style) __println_as bold "${commit_type}: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc)"
24+
;;
25+
docs) __println_as bold "${commit_type}: Documentation only changes"
26+
;;
27+
build) __println_as bold "${commit_type}: Changes that affect the build system or external dependencies"
28+
;;
29+
ci) __println_as bold "${commit_type}: Changes to the CI configuration files and scripts"
30+
;;
31+
cd) __println_as bold "${commit_type}: Changes to the CD configuration files and scripts"
32+
;;
33+
BREAKING-CHANGE) __println_as bold "${commit_type}: Introduce a breaking API change"
34+
;;
35+
*) __println_as bold "Unknown commit type"
36+
;;
37+
esac
38+
39+
local colorMsg="[optional <prefix>]/${MAGENTA}[optional <type>]${RESET}/<name>\n"
40+
colorMsg="${colorMsg}${MAGENTA}\t\t\t\t\t\t\t\t│${RESET}\n"
41+
colorMsg="${colorMsg}${MAGENTA}\t\t\t\t\t\t\t\t└─⫸ "
42+
colorMsg="${colorMsg}type of branch you're creating${RESET}"
43+
echo -e "\n${colorMsg}"
44+
}

util/fzf_previews/__gcommit_description_preview renamed to util/fzf_previews/gcommit/__description_preview

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
source "$__CUSTOM_CONSOLE_UTIL"/__println_as
66
source "$__CUSTOM_CONSOLE_UTIL"/__common
77

8-
function __gcommit_description_preview() {
8+
function __description_preview() {
99

1010
local isBreakingChange="${1}"
1111

util/fzf_previews/__gcommit_scope_preview renamed to util/fzf_previews/gcommit/__scope_preview

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
source "$__CUSTOM_CONSOLE_UTIL"/__println_as
66
source "$__CUSTOM_CONSOLE_UTIL"/__common
77

8-
function __gcommit_scope_preview() {
8+
function __scope_preview() {
99

1010
local isBreakingChange="${1}"
1111

0 commit comments

Comments
 (0)