Skip to content

Commit a704211

Browse files
author
Bhavi Dhingra
committed
gshow and glog
1 parent a525b28 commit a704211

File tree

6 files changed

+140
-0
lines changed

6 files changed

+140
-0
lines changed

cmd/glog

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC2155
4+
#shellcheck disable=SC1091
5+
6+
source "$__CUSTOM_GIT_UTIL"/fzf_previews/__gshow_preview
7+
source "$__CUSTOM_GIT_UTIL"/fzf_headers/__glog_header
8+
9+
function main() {
10+
11+
local GLOG_HEADER="$(__glog_header)"
12+
13+
while true; do
14+
local selectedStr="$(git log --pretty='format:%C(auto)%h%d [%an] [%ar] %s' --graph --color=always |\
15+
fzf --bind "q:abort"\
16+
--bind "?:toggle-preview"\
17+
--bind "ctrl-c:preview(source $__CUSTOM_GIT_UTIL/fzf_actions/__gshow_actions; __gshow_actions {})"\
18+
--header "${GLOG_HEADER}"\
19+
--preview-window hidden\
20+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gshow_preview; __gshow_preview {}")"
21+
22+
if [[ -z "${selectedStr}" ]]; then
23+
break
24+
fi
25+
__gshow_preview "${selectedStr}"
26+
done
27+
}
28+
29+
main

cmd/gshow

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC2155
4+
#shellcheck disable=SC1091
5+
6+
source "$__CUSTOM_GIT_UTIL"/fzf_previews/__gshow_preview
7+
source "$__CUSTOM_GIT_UTIL"/fzf_headers/__gshow_header
8+
9+
function main() {
10+
11+
local GSHOW_HEADER="$(__gshow_header)"
12+
13+
while true; do
14+
local selectedStr="$(git log --pretty='format:%C(auto)%h%d [%an] [%ar] %s' --graph --color=always |\
15+
fzf --bind "q:abort"\
16+
--bind "?:toggle-preview"\
17+
--bind "ctrl-c:preview(source $__CUSTOM_GIT_UTIL/fzf_actions/__gshow_actions; __gshow_actions {})"\
18+
--header "${GSHOW_HEADER}"\
19+
--preview "source $__CUSTOM_GIT_UTIL/fzf_previews/__gshow_preview; __gshow_preview {}")"
20+
21+
if [[ -z "${selectedStr}" ]]; then
22+
break
23+
fi
24+
__gshow_preview "${selectedStr}"
25+
done
26+
}
27+
28+
main

util/fzf_actions/__gshow_actions

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC2155
4+
#shellcheck disable=SC1091
5+
6+
source "$__CUSTOM_CONSOLE_UTIL"/__print_as
7+
8+
function __gshow_actions() {
9+
10+
local str="${1}"
11+
local abbrCommitSHA="$(echo "$str" | grep -E "[0-9a-z]+" -o | head -n 1)"
12+
local longCommitSHA="$(git rev-parse "${abbrCommitSHA}")"
13+
14+
printf "%s" "${longCommitSHA}" | clipboard
15+
16+
# the following statements will be printed in the preview window
17+
echo
18+
__print_as "yellow" "bold" "${longCommitSHA}"
19+
echo " is copied to the clipboard."
20+
}

util/fzf_headers/__glog_header

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091
4+
#shellcheck disable=SC2001
5+
#shellcheck disable=SC2155
6+
7+
source "$__CUSTOM_CONSOLE_UTIL"/__common
8+
9+
function __glog_header() {
10+
11+
local msg="glog | <enter>: git show, <ctrl-c>: copy commit SHA, <?>: toggle preview, <q/esc>: quit"
12+
local colormsg="${UNDERLINE}${MAGENTA}glog${RESET} | \
13+
${BLUE}<enter>: ${RESET}git show, \
14+
${BLUE}<ctrl-c>: ${RESET}copy commit SHA, \
15+
${BLUE}<?>: ${RESET}toggle preview, \
16+
${BLUE}<q/esc>: ${RESET}quit"
17+
18+
local edge="$(echo "${msg}" | sed -e 's/./-/g')"
19+
local GLOG_HEADER="${edge}"'
20+
'"${colormsg}"'
21+
'"${edge}"'
22+
'
23+
24+
echo "${GLOG_HEADER}"
25+
}

util/fzf_headers/__gshow_header

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091
4+
#shellcheck disable=SC2001
5+
#shellcheck disable=SC2155
6+
7+
source "$__CUSTOM_CONSOLE_UTIL"/__common
8+
9+
function __gshow_header() {
10+
11+
local msg="gshow | <enter>: git show, <ctrl-c>: copy commit SHA, <?>: toggle preview, <q/esc>: quit"
12+
local colormsg="${UNDERLINE}${MAGENTA}gshow${RESET} | \
13+
${BLUE}<enter>: ${RESET}git show, \
14+
${BLUE}<ctrl-c>: ${RESET}copy commit SHA, \
15+
${BLUE}<?>: ${RESET}toggle preview, \
16+
${BLUE}<q/esc>: ${RESET}quit"
17+
18+
local edge="$(echo "${msg}" | sed -e 's/./-/g')"
19+
local GSHOW_HEADER="${edge}"'
20+
'"${colormsg}"'
21+
'"${edge}"'
22+
'
23+
24+
echo "${GSHOW_HEADER}"
25+
}

util/fzf_previews/__gshow_preview

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC2155
4+
5+
function __gshow_preview() {
6+
7+
local str="${1}"
8+
local commitSHA="$(echo "$str" | grep -E "[0-9a-z]+" -o | head -n 1)"
9+
if [[ -z "${commitSHA}" ]]; then
10+
return
11+
fi
12+
git show --color=always "${commitSHA}"
13+
}

0 commit comments

Comments
 (0)