Skip to content

Commit 15f25f5

Browse files
author
Bhavi Dhingra
committed
feat(new-command): add gstashlist, gstashdrop, gstashpop
1 parent 0145149 commit 15f25f5

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

Diff for: .gitcommitscopes

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gbranchcreate
66
gcommit
77
gdiff
88
gshow
9+
gstashapply
910
gswitch
1011
header
1112
init

Diff for: cmd/gstashdrop

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__assertgitrepo was not specified as input
4+
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values
5+
6+
source "${__CUSTOM_GIT_UTIL}"/fzf_headers/__gstash_header
7+
source "${__CUSTOM_GIT_UTIL}"/__assertgitrepo
8+
source "${__CUSTOM_GIT_UTIL}"/__select_stash_id
9+
10+
__assertgitrepo
11+
12+
function main() {
13+
14+
local GSTASH_HEADER="$(__gstash_header "drop")"
15+
16+
local stashId="$(__select_stash_id "${GSTASH_HEADER}")"
17+
[ -z "${stashId}" ] && return
18+
19+
git stash drop "${stashId}"
20+
}
21+
22+
main

Diff for: cmd/gstashlist

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__assertgitrepo was not specified as input
4+
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values
5+
6+
source "${__CUSTOM_GIT_UTIL}"/fzf_headers/__gstashlist_header
7+
source "${__CUSTOM_GIT_UTIL}"/__assertgitrepo
8+
9+
__assertgitrepo
10+
11+
function main() {
12+
13+
local GSTASHLIST_HEADER="$(__gstashlist_header)"
14+
15+
git stash list | \
16+
fzf --bind '?:toggle-preview'\
17+
--bind 'enter:'\
18+
--bind 'double-click:'\
19+
--header "${GSTASHLIST_HEADER}"\
20+
--preview "source ${__CUSTOM_GIT_UTIL}/fzf_previews/__gstash_preview; __gstash_preview {}"
21+
22+
}
23+
24+
main

Diff for: cmd/gstashpop

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC1091 # Not following: ./__assertgitrepo was not specified as input
4+
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values
5+
6+
source "${__CUSTOM_GIT_UTIL}"/fzf_headers/__gstash_header
7+
source "${__CUSTOM_GIT_UTIL}"/__assertgitrepo
8+
source "${__CUSTOM_GIT_UTIL}"/__select_stash_id
9+
10+
__assertgitrepo
11+
12+
function main() {
13+
14+
local GSTASH_HEADER="$(__gstash_header "pop")"
15+
16+
local stashId="$(__select_stash_id "${GSTASH_HEADER}")"
17+
[ -z "${stashId}" ] && return
18+
19+
git stash pop "${stashId}"
20+
}
21+
22+
main

Diff for: util/fzf_headers/__gstashlist_header

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 __gstashlist_header() {
10+
11+
local msg="gstashlist | ?: toggle preview | esc: exit"
12+
local colorMsg="${UNDERLINE}${MAGENTA}gstashlist${RESET} | \
13+
${BLUE}?:${RESET} toggle preview | \
14+
${BLUE}esc:${RESET} exit"
15+
16+
local edge="$(echo "${msg}" | sed -e 's/./-/g')"
17+
local GSTASHLIST_HEADER="${edge}"'
18+
'"${colorMsg}"'
19+
'"${edge}"'
20+
'
21+
22+
echo "${GSTASHLIST_HEADER}"
23+
}

0 commit comments

Comments
 (0)