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

Custom commands submenus #4324

Merged
merged 7 commits into from
Feb 28, 2025
Merged

Custom commands submenus #4324

merged 7 commits into from
Feb 28, 2025

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

I want to be able to configure custom commands that I don't need very often; I don't want these to pollute the global keybindings menu, and I don't want to assign globally unique keybindings to them (because there are only so many of these available, and also because I wouldn't be able to remember them, because the commands are not used often). However, I still want to invoke them through keybindings somehow.

I find that the perfect solution for this is to configure a menu that contains custom commands. I can pop open the menu using only one key that I need to remember, but I can access the individual custom commands inside using keys that don't need to be unique with the rest of the global keybindings.

In this PR we achieve this by adding an optional subCommands property to customCommand that can be used instead of the other properties like command, etc. This is an alternative approach to #4276, which added a new top-level property for custom command menus.

Potentially closes #3799.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller stefanhaller mentioned this pull request Feb 25, 2025
7 tasks
@stefanhaller stefanhaller added the enhancement New feature or request label Feb 25, 2025
customCommands:
- key: X
description: "Copy/paste commits across repos"
subCommands:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure subCommands is the best name for the key. Better suggestions welcome.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about commandMenu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I like that. Changed in 255ca8b and 82658ff.

Copy link

codacy-production bot commented Feb 25, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for a7b0ccf1 87.58%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a7b0ccf) Report Missing Report Missing Report Missing
Head commit (df17896) 53200 46078 86.61%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4324) 153 134 87.58%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, see comments

description: "Paste selected commits from clipboard"
```

If you use the subCommands property, none of the other properties except key and description must be used.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you use the subCommands property, none of the other properties except key and description must be used.
If you use the subCommands property, none of the other properties except key and description can be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ da74a08

customCommands:
- key: X
description: "Copy/paste commits across repos"
subCommands:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about commandMenu?

return self.showCustomCommandsMenu(customCommand)
}
bindings = append(bindings, &types.Binding{
ViewName: "", // custom commands menus are global; we filter the commands inside by context
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allow optionally specifying a context on a top-level custom command menu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question; complexity? This would give us two levels of filtering by context, one for the menu itself and then again for the commands inside. I think this could be confusing, I find it easier to understand if menus are always global.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that it would be confusing, but I also don't mind not supporting it at the moment. We can wait and see if the use case comes up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about cases like this:

customCommands:
  - context: files
    commandMenu:
      - command: whatever
        context: commits

This sub-command would just never show up in the menu, ever. And I think you could easily run into cases like that in practice when you start to restructure your menus and move commands from one to another.

We could probably add validation to catch and disallow such cases, but it's actually not trivial if you think about the details, and I don't think it's worth it.

This was backwards; we renamed Sha to Hash, so Sha is now deprecated, not Hash.
It has been 'e' instead of 'o' for quite a while now.
It is false by default. This way there's one less change to make in the next
commit.
This allows us to tell whether they appear in the user's config file, which we
will need later in this branch.
We'll reuse it in the next commit.
@stefanhaller stefanhaller force-pushed the custom-commands-submenus branch from b8f0b9e to 82658ff Compare February 28, 2025 09:08
@stefanhaller
Copy link
Collaborator Author

Addressed the feedback, mentioned the individual fixups above; will squash now for easier re-review.

@stefanhaller stefanhaller force-pushed the custom-commands-submenus branch from 82658ff to df17896 Compare February 28, 2025 09:11
Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stefanhaller stefanhaller merged commit 1b571f9 into master Feb 28, 2025
15 checks passed
@stefanhaller stefanhaller deleted the custom-commands-submenus branch February 28, 2025 09:48
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.47.2` -> `v0.48.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.48.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.48.0)

[Compare Source](jesseduffield/lazygit@v0.47.2...v0.48.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.48.0 -->

#### What's Changed

##### Enhancements 🔥

-   Custom commands submenus by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4324

##### Maintenance ⚙️

-   Refactor migrations to only marshall yaml twice by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4318

**Full Changelog**: jesseduffield/lazygit@v0.47.2...v0.48.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODIuNCIsInVwZGF0ZWRJblZlciI6IjM5LjE4Mi40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom command and custom command
2 participants