Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: allow customizing key-bindings #16

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/modules/branch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env bash

GIT_FUZZY_BRANCH_WORKING_COPY_KEY=${GIT_FUZZY_BRANCH_WORKING_COPY_KEY:-Ctrl-P}
GIT_FUZZY_BRANCH_MERGE_BASE_KEY=${GIT_FUZZY_BRANCH_MERGE_BASE_KEY:-Alt-P}
GIT_FUZZY_BRANCH_COMMIT_LOG_KEY=${GIT_FUZZY_BRANCH_COMMIT_LOG_KEY:-Alt-L}
GIT_FUZZY_BRANCH_CHECKOUT_KEY=${GIT_FUZZY_BRANCH_CHECKOUT_KEY:-Alt-F}
GIT_FUZZY_BRANCH_DELETE_BRANCH_KEY=${GIT_FUZZY_BRANCH_DELETE_BRANCH_KEY:-Alt-D}

GF_BRANCH_RELOAD="reload(git fuzzy helper branch_menu_content)"

GF_BRANCH_CHECKOUT="git fuzzy helper branch_checkout {1}"
Expand All @@ -21,21 +27,21 @@ gf_fzf_branch() {
BRANCH_HEADER='
Type to filter. '"${WHITE}Enter${NORMAL} to ${GREEN}ACCEPT${NORMAL}"'

'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}Ctrl-P${NORMAL} $BRANCH_HEADER_BRANCH_CHECKOUT"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}Alt-P${NORMAL} ${GREEN}${BOLD}checkout ${YELLOW}${BOLD}📁${NORMAL} ${WHITE}Alt-F${NORMAL}"'
'"${GREEN}commit log${NORMAL} ${WHITE}Alt-L${NORMAL} ${RED}${BOLD}delete branch ✗${NORMAL} ${WHITE}Alt-D${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}$GIT_FUZZY_BRANCH_WORKING_COPY_KEY${NORMAL} $BRANCH_HEADER_BRANCH_CHECKOUT"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}$GIT_FUZZY_BRANCH_MERGE_BASE_KEY${NORMAL} ${GREEN}${BOLD}checkout ${YELLOW}${BOLD}📁${NORMAL} ${WHITE}$GIT_FUZZY_BRANCH_CHECKOUT_KEY${NORMAL}"'
'"${GREEN}commit log${NORMAL} ${WHITE}$GIT_FUZZY_BRANCH_COMMIT_LOG_KEY${NORMAL} ${RED}${BOLD}delete branch ✗${NORMAL} ${WHITE}$GIT_FUZZY_BRANCH_DELETE_BRANCH_KEY${NORMAL}"'

'

# shellcheck disable=2046,2016,2090,2086
gf_fzf_one -m \
--header "$BRANCH_HEADER" \
$BRANCH_CHECKOUT_BINDING \
--bind 'alt-f:execute(git fuzzy helper branch_checkout_files {1})' \
--bind "alt-d:$GF_BRANCH_DELETE_BINDING" \
--bind 'alt-l:execute(git fuzzy log {1})' \
--bind 'ctrl-p:execute(git fuzzy diff {1})' \
--bind 'alt-p:execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})' \
--bind $GIT_FUZZY_BRANCH_CHECKOUT_KEY':execute(git fuzzy helper branch_checkout_files {1})' \
--bind "$GIT_FUZZY_BRANCH_DELETE_BRANCH_KEY:$GF_BRANCH_DELETE_BINDING" \
--bind $GIT_FUZZY_BRANCH_COMMIT_LOG_KEY':execute(git fuzzy log {1})' \
--bind $GIT_FUZZY_BRANCH_WORKING_COPY_KEY':execute(git fuzzy diff {1})' \
--bind $GIT_FUZZY_BRANCH_MERGE_BASE_KEY':execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})' \
--preview 'git fuzzy helper branch_preview_content {1}' | \
awk '{ print $1 }'
}
Expand Down
16 changes: 10 additions & 6 deletions lib/modules/log.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env bash

GIT_FUZZY_LOG_WORKING_COPY_KEY=${GIT_FUZZY_LOG_WORKING_COPY_KEY:-Ctrl-P}
GIT_FUZZY_MERGE_BASE_KEY=${GIT_FUZZY_MERGE_BASE_KEY:-Alt-P}
GIT_FUZZY_COMMIT_KEY=${GIT_FUZZY_COMMIT_KEY:-Alt-D}

# shellcheck disable=2016
GF_LOG_HEADER='
Use '"${YELLOW}|${NORMAL} to separate CLI args for ${MAGENTA}git log${NORMAL} vs ${MAGENTA}git diff${NORMAL}. ${WHITE}Enter${NORMAL} to ${GREEN}ACCEPT${NORMAL}"'

'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}Ctrl-P${NORMAL} ${GRAY}-- search messages${NORMAL} ${MAGENTA}--grep=Foo${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}Alt-P${NORMAL} ${GRAY}-- search patch${NORMAL} ${MAGENTA}-G 'Foo'${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}commit${NORMAL} ${WHITE}Alt-D${NORMAL} ${GRAY}-- customize patch${NORMAL} ${MAGENTA}-G 'Foo' | -W -- foo.c${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}$GIT_FUZZY_LOG_WORKING_COPY_KEY${NORMAL} ${GRAY}-- search messages${NORMAL} ${MAGENTA}--grep=Foo${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}$GIT_FUZZY_MERGE_BASE_KEY${NORMAL} ${GRAY}-- search patch${NORMAL} ${MAGENTA}-G 'Foo'${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}commit${NORMAL} ${WHITE}$GIT_FUZZY_COMMIT_KEY${NORMAL} ${GRAY}-- customize patch${NORMAL} ${MAGENTA}-G 'Foo' | -W -- foo.c${NORMAL}"'

'

Expand All @@ -18,9 +22,9 @@ gf_fzf_log() {
--header "$GF_LOG_HEADER" \
--preview 'git fuzzy helper log_preview_content {1} {q}' \
--bind 'change:reload(git fuzzy helper log_menu_content {q})' \
--bind 'alt-d:execute(git fuzzy diff {1}^ {1})' \
--bind 'ctrl-p:execute(git fuzzy diff {1})' \
--bind 'alt-p:execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})'
--bind $GIT_FUZZY_COMMIT_KEY':execute(git fuzzy diff {1}^ {1})' \
--bind $GIT_FUZZY_LOG_WORKING_COPY_KEY':execute(git fuzzy diff {1})' \
--bind $GIT_FUZZY_MERGE_BASE_KEY':execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})'
}

gf_log() {
Expand Down
16 changes: 10 additions & 6 deletions lib/modules/reflog.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env bash

GIT_FUZZY_REFLOG_WORKING_COPY_KEY=${GIT_FUZZY_REFLOG_WORKING_COPY_KEY:-Ctrl-P}
GIT_FUZZY_REFLOG_MERGE_BASE_KEY=${GIT_FUZZY_REFLOG_MERGE_BASE_KEY:-Alt-P}
GIT_FUZZY_REFLOG_COMMIT_KEY=${GIT_FUZZY_REFLOG_COMMIT_KEY:-Alt-D}

# shellcheck disable=2016
GF_REFLOG_HEADER='
Use '"${YELLOW}|${NORMAL} to separate CLI args for ${MAGENTA}git reflog${NORMAL} vs ${MAGENTA}git diff${NORMAL}. ${WHITE}Enter${NORMAL} to ${GREEN}ACCEPT${NORMAL}"'

'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}Ctrl-P${NORMAL} ${GRAY}-- search messages${NORMAL} ${MAGENTA}--grep=Foo${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}Alt-P${NORMAL} ${GRAY}-- search patch${NORMAL} ${MAGENTA}-G 'Foo'${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}commit${NORMAL} ${WHITE}Alt-C${NORMAL} ${GRAY}-- customize patch${NORMAL} ${MAGENTA}-G 'Foo' | -W -- foo.c${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}working copy${NORMAL} ${WHITE}$GIT_FUZZY_REFLOG_WORKING_COPY_KEY${NORMAL} ${GRAY}-- search messages${NORMAL} ${MAGENTA}--grep=Foo${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}merge-base${NORMAL} ${WHITE}$GIT_FUZZY_REFLOG_MERGE_BASE_KEY${NORMAL} ${GRAY}-- search patch${NORMAL} ${MAGENTA}-G 'Foo'${NORMAL}"'
'"${YELLOW}${BOLD}∆${NORMAL} ${GREEN}commit${NORMAL} ${WHITE}$GIT_FUZZY_REFLOG_COMMIT_KEY${NORMAL} ${GRAY}-- customize patch${NORMAL} ${MAGENTA}-G 'Foo' | -W -- foo.c${NORMAL}"'

'

Expand All @@ -18,9 +22,9 @@ gf_fzf_reflog() {
--header "$GF_REFLOG_HEADER" \
--preview 'git fuzzy helper reflog_preview_content {1} {q}' \
--bind 'change:reload(git fuzzy helper reflog_menu_content {q})' \
--bind 'alt-d:execute(git fuzzy diff {1}^ {1})' \
--bind 'ctrl-p:execute(git fuzzy diff {1})' \
--bind 'alt-p:execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})'
--bind $GIT_FUZZY_REFLOG_COMMIT_KEY':execute(git fuzzy diff {1}^ {1})' \
--bind $GIT_FUZZY_REFLOG_WORKING_COPY_KEY':execute(git fuzzy diff {1})' \
--bind $GIT_FUZZY_REFLOG_MERGE_BASE_KEY':execute(git fuzzy diff "$(git merge-base "'"$GF_BASE_BRANCH"'" {1})" {1})'
}

gf_reflog() {
Expand Down
24 changes: 15 additions & 9 deletions lib/modules/status.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env bash
# shellcheck disable=2016

GIT_FUZZY_STATUS_ADD_KEY=${GIT_FUZZY_STATUS_ADD_KEY:-Alt-S}
GIT_FUZZY_STATUS_EDIT_KEY=${GIT_FUZZY_STATUS_EDIT_KEY:-Alt-E}
GIT_FUZZY_STATUS_COMMIT_KEY=${GIT_FUZZY_STATUS_EDIT_KEY:-Alt-C}
GIT_FUZZY_STATUS_RESET_KEY=${GIT_FUZZY_STATUS_RESET_KEY:-Alt-R}
GIT_FUZZY_STATUS_DISCARD_KEY=${GIT_FUZZY_STATUS_DISCARD_KEY:-Alt-U}

GF_STATUS_HEADER='
Type to filter. '"${WHITE}Enter${NORMAL} to ${GREEN}ACCEPT${NORMAL}"'

'"${GRAY}-- (${NORMAL}*${GRAY}) editor: ${MAGENTA}${EDITOR} ${NORMAL}${GF_EDITOR_ARGS}${NORMAL}"'
'" * ${GREEN}${BOLD}edit ✎${NORMAL} ${WHITE}Alt-E${NORMAL}"'
'"${GREEN}all ☑${NORMAL} ${WHITE}Alt-A${NORMAL} ${GREEN}stage ${BOLD}⇡${NORMAL} ${WHITE}Alt-S${NORMAL} ${RED}${BOLD}discard ✗${NORMAL} ${WHITE}Alt-U${NORMAL}"'
'"${GREEN}none ☐${NORMAL} ${WHITE}Alt-D${NORMAL} ${GREEN}reset ${RED}${BOLD}⇣${NORMAL} ${WHITE}Alt-R${NORMAL} * ${RED}${BOLD}commit ${NORMAL}${RED}⇧${NORMAL} ${WHITE}Alt-C${NORMAL}"'
'" * ${GREEN}${BOLD}edit ✎${NORMAL} ${WHITE}$GIT_FUZZY_STATUS_EDIT_KEY${NORMAL}"'
'"${GREEN}all ☑${NORMAL} ${WHITE}Alt-A${NORMAL} ${GREEN}stage ${BOLD}⇡${NORMAL} ${WHITE}$GIT_FUZZY_STATUS_ADD_KEY${NORMAL} ${RED}${BOLD}discard ✗${NORMAL} ${WHITE}$GIT_FUZZY_STATUS_DISCARD_KEY${NORMAL}"'
'"${GREEN}none ☐${NORMAL} ${WHITE}Alt-D${NORMAL} ${GREEN}reset ${RED}${BOLD}⇣${NORMAL} ${WHITE}$GIT_FUZZY_STATUS_RESET_KEY${NORMAL} * ${RED}${BOLD}commit ${NORMAL}${RED}⇧${NORMAL} ${WHITE}$GIT_FUZZY_STATUS_COMMIT_KEY${NORMAL}"'

'
gf_fzf_status() {
Expand All @@ -16,21 +22,21 @@ gf_fzf_status() {

gf_fzf -m --header "$GF_STATUS_HEADER" \
--header-lines=2 \
--expect='alt-e,alt-c' \
--expect='$GIT_FUZZY_STATUS_EDIT_KEY,$GIT_FUZZY_STATUS_COMMIT_KEY' \
--nth=2 \
--preview 'git fuzzy helper status_preview_content {1} {2..}' \
--bind "alt-s:execute-silent(git fuzzy helper status_add {+2..})+down+$RELOAD" \
--bind "alt-r:execute-silent(git fuzzy helper status_reset {+2..})+down+$RELOAD" \
--bind "alt-u:execute-silent(git fuzzy helper status_discard {2..})+$RELOAD"
--bind "$GIT_FUZZY_STATUS_ADD_KEY:execute-silent(git fuzzy helper status_add {+2..})+down+$RELOAD" \
--bind "$GIT_FUZZY_STATUS_RESET_KEY:execute-silent(git fuzzy helper status_reset {+2..})+down+$RELOAD" \
--bind "$GIT_FUZZY_STATUS_DISCARD_KEY:execute-silent(git fuzzy helper status_discard {2..})+$RELOAD"
}

gf_status_interpreter() {
CONTENT="$(cat -)"
HEAD="$(echo "$CONTENT" | head -n1)"
TAIL="$(echo "$CONTENT" | tail -n +2)"
if [ "$HEAD" = 'alt-e' ]; then
if [ "$HEAD" = "$GIT_FUZZY_STATUS_EDIT_KEY" ]; then
eval "git fuzzy helper status_edit $(echo "$TAIL" | cut -c4- | join_lines_quoted)"
elif [ "$HEAD" = 'alt-c' ]; then
elif [ "$HEAD" = "$GIT_FUZZY_STATUS_COMMIT_KEY" ]; then
eval "git fuzzy helper status_commit"
else
echo "$TAIL" | cut -c4-
Expand Down