wfxr / wfxr/forgit

Discussion: keybindings to support more functions?

Open
#259 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
5.1k
Forks
166
Avg merge
1d 11h
Merged PRs (30d)
5

Description

Check list

  • I have read through the README
  • I have the latest version of forgit
  • I have searched through the existing issues

Environment info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

This came up during a discussion in #251.

fzf supports a list of possible hotkeys that can be bound to custom commands and then be called on list items while browsing them. I personally make use of this in my gss selector by defining these options:

# Use forgit diff on stash enter
export FORGIT_STASH_ENTER_COMMAND='echo {} | cut -d: -f1 | xargs -I % git forgit diff %^1 %'

# Pop stash on alt-enter
export FORGIT_STASH_POP_COMMAND='echo {} | cut -d: -f1 | xargs -I % git stash pop %'

# Drop stash on alt-backspace
export FORGIT_STASH_DROP_COMMAND='echo {} | cut -d: -f1 | xargs -I % git stash drop %'

export FORGIT_STASH_FZF_OPTS="
	--preview-window=top:50%
	--bind='enter:execute($FORGIT_STASH_ENTER_COMMAND)'
	--bind='alt-enter:execute($FORGIT_STASH_POP_COMMAND)+accept'
	--bind='alt-bspace:execute($FORGIT_STASH_DROP_COMMAND)+reload(git stash list)'
	--prompt='[ENTER] show   [ALT+ENTER] pop   [ALT+BACKSPACE] drop > '
"

This makes the stash selector look as follows:

grafik

I can now view, apply or drop stashes all from within the same stash list.

I kind of "hijacked" the fzf prompt to display the available keybindings. Something similar could be achieved passing --header "[ENTER] show [ALT+ENTER] pop [ALT+BACKSPACE] drop" --header-first to fzf, which might be a bit cleaner. I just found putting it into the prompt visually more appealing.

@cjappl @sandr01d @wfxr
How do you like this? Can you imagine including this kind of functionality into forgit? We could make use of this in other forgit dialogs as well, e.g. keybindings in glo for reverting the selected commit or starting a rebase on it.

Let me know what you think.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing forgit dialogs and the fzf key/event bindings described in the issue. Determine whether configurable actions should be supported across selectors such as gss and glo, then define the affected entry points and acceptance behavior before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, shell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.