Skip to content

Commit 4a050cc

Browse files
author
Bhavi Dhingra
committed
style(gswitch): add fzf header
1 parent 24bed8b commit 4a050cc

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

cmd/gswitch

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ main () {
1414

1515
__assertgitrepo
1616

17-
local branchName="$(__select_local_branch)"
17+
local branchName="$(__select_local_branch "gswitch" "select local branch to switch to" "exit")"
1818
__exit_if_empty_str "${branchName}" ${SUCCESS}
1919

2020
clear

util/__select_local_branch

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/bin/bash
22

3-
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values.
3+
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values.
4+
#shellcheck disable=SC1091 # Not following: ./fzf_headers/__select_local_branch_header was not specified as input (see shellcheck -x)
45

6+
source "${__CUSTOM_GIT_UTIL}"/fzf_headers/__select_local_branch_header
7+
8+
# Usage: __select_local_branch "gswitch" "select local branch to switch to" "exit"
59
function __select_local_branch() {
610

7-
local branchName=$(git branch --sort=-committerdate | fzf | sed 's/^. //g')
11+
local cmd="${1}"
12+
local cmdMsg="${2}"
13+
local escAction="${3}"
14+
local HEADER="$(__select_local_branch_header "${cmd}" "${cmdMsg}" "${escAction}")"
15+
local branchName="$(git branch --sort=-committerdate |\
16+
fzf --height=50%\
17+
--header "${HEADER}" |\
18+
sed 's/^. //g')"
19+
820
local rawBranchNameFile="$(getrawstr "${branchName}")"
9-
echo "${rawBranchNameFile}" | xargs -I "{}" echo {} # xargs used to handle "invalid reference" error in git switch command
21+
echo "${rawBranchNameFile}" | xargs -I "{}" echo {} # xargs used to handle "invalid reference" for special characters
22+
# like ', '#' in branch names
1023
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091
4+
#shellcheck disable=SC2155
5+
#shellcheck disable=SC2001
6+
7+
source "${__CUSTOM_CONSOLE_UTIL}"/__common # for colors
8+
9+
# Usage: __select_local_branch_header "gswitch" "select local branch" "exit"
10+
function __select_local_branch_header() {
11+
12+
local cmd="${1}"
13+
local cmdMsg="${2}"
14+
local escAction="${3}"
15+
local colorMsg="${MAGENTA}${UNDERLINE}${cmd}${RESET} | ${cmdMsg}\n\n"
16+
colorMsg="${colorMsg}${BLUE}esc:${RESET} ${escAction} "
17+
18+
local x="${cmd} | ${cmdMsg}"
19+
local edge="$(echo "${x}" | sed "s/./-/g")"
20+
local HEADER="${edge}\n${colorMsg}\n${edge}\n "
21+
22+
echo -e "${HEADER}"
23+
}

0 commit comments

Comments
 (0)