Skip to content

Commit 9811d86

Browse files
author
Bhavi Dhingra
committed
feat(new-command): add gstashapply
1 parent d720e35 commit 9811d86

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

cmd/gstashapply

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=SC1091 # Not following: ./__assertgitrepo was not specified as input
4+
#shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values
5+
#shellcheck disable=SC2001 # See if you can use ${variable//search/replace}
6+
7+
source "${__CUSTOM_GIT_UTIL}"/fzf_headers/__gstash_header
8+
source "${__CUSTOM_GIT_UTIL}"/__assertgitrepo
9+
10+
__assertgitrepo
11+
12+
function main() {
13+
14+
local GSTASH_HEADER="$(__gstash_header)"
15+
16+
local selectedStr="$(git stash list | \
17+
fzf --bind '?:toggle-preview'\
18+
--header "${GSTASH_HEADER}"\
19+
--preview "source ${__CUSTOM_GIT_UTIL}/fzf_previews/__gstash_preview; __gstash_preview {}")"
20+
[ -z "${selectedStr}" ] && return
21+
22+
local stashId="$(echo "${selectedStr}" | sed 's/\:.*//g')"
23+
git stash apply "${stashId}"
24+
25+
git status
26+
}
27+
28+
main

util/fzf_headers/__gstash_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 __gstash_header() {
10+
11+
local msg="gstashapply | enter: apply stash | ?: toggle preview"
12+
local colorMsgL1="${UNDERLINE}${MAGENTA}gstashapply${RESET} | \
13+
${BLUE}enter:${RESET} apply stash | \
14+
${BLUE}?:${RESET} toggle preview"
15+
local colorMsgL2=" | ${BLUE}esc:${RESET} quit"
16+
17+
local edge="$(echo "${msg}" | sed -e 's/./-/g')"
18+
local GSTASH_HEADER="${edge}"'
19+
'"${colorMsgL1}"'
20+
'"${colorMsgL2}"'
21+
'"${edge}"'
22+
'
23+
24+
echo "${GSTASH_HEADER}"
25+
}

util/fzf_previews/__gshow_preview

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22

33
#shellcheck disable=SC2155
4-
#shellcheck disable=SC1091 # Not following: ./__common was not specified as input (see shellcheck -x)
54

65
function __gshow_preview() {
76

util/fzf_previews/__gstash_preview

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
#shellcheck disable=SC2155
4+
#shellcheck disable=SC2001 # See if you can use ${variable//search/replace}
5+
6+
7+
function __gstash_preview() {
8+
9+
local str="${1}"
10+
local stashId="$(echo "$str" | sed 's/\:.*//g')"
11+
git stash show -p --color=always "${stashId}" | ${CUSTOM_GIT_PAGER}
12+
}

0 commit comments

Comments
 (0)