Is your feature request related to a problem? Please describe.
It would be cool if we had an option for users to add their own custom commands via their config. We can define which variables will be available and then the command can refer to them via handlebars e.g.
git reset --hard origin/{{branch}}
Maybe for V1 we can just have them in an array and you access them via the 0-9 number keys. Later down the line we can have configurable keybindings where you can just define the keybinding as a custom command keybinding.
I don't know if that is the idea, but the first thing I thought after install was "I wish I could easily go back to the terminal to run some command and get back" something like a simple fg/bg.
I have something similar to vim https://github.com/alexrochas/zsh-vim-crtl-z.
What do you think, it's better to be able to go back to the terminal (without lose the current state) or run custom commands from inside? And if it's better from the inside (an input field?) or hotkeys for pre-configured commands?
馃槃
I would love to quickly be able to quickly write a one-time custom git command on a window inside lazygit
Sounds like a good use case to me. I think that use case differs somewhat from the one I was thinking of when I put up this FR, so I've made another one for the different use case here https://github.com/jesseduffield/lazygit/issues/389 and I've made a WIP PR here https://github.com/jesseduffield/lazygit/pull/388
Please have a read through my thoughts in both the issue and the PR, and give it a test if you want to see how it works currently. Let me know your thoughts :)
@alexrochas @ferranpujolcamins I've merged the above PR and closed the issue I made. For any further discussion on how we can improve that feature please leave comments on the issue.
This issue shall remain related to the topic of saving 'favourited' commands into lazygit for easy access, so I'll leave it open.
I would love something similar to fzf --bind option, that allows you to map keys to custom commands (taking the file as an argument), but also map/remap fzf's actions to keys. In lazygit it would need an extra argument for the context in which you could map the key.
In lazygit this could be a section of the configuration file, for example:
keys:
files:
enter: commit
shift-delete: execute(rm {file})+refresh
commits:
B: execute(hub browse -- "commit/{sha}")
To add three key bindings:
If lazygit paid attention to git aliases, you would already have most of what you need.
For example, to save a change to Gerrit you have to use this longer command:
git push origin HEAD:refs/for/master
However, I set up a nice alias...
git config --global alias.review="push origin HEAD:refs/for/master"
so all I have to type at the command line is
git review
Of course, that won't work if you want to push a change from or for a different branch than master, but I rarely do that, and can afford to type it all out when I do.
@JalonSolov wouldn't that still require a UX for selecting those commands? We can currently run a custom command using ':'. That seems sufficient to me wrt git aliases.
I think @dvdbng 's suggestion makes sense. I'm thinking we could just mimic the shape of the keybinding struct that we already use, which means you'd need to specify a view name (files/commits/branches) and if a context name applies, that too. And we'd use handlebars for when variables (like a commit SHA) are passed through. If there is a conflicting keybinding, the custom one takes precedence.
This would solve so many issues. E.g. ability to checkout and create remote branch and track it (which is a issue atm).
If we can have ability to specify custom command, with possibility for variables for things like current branch etc. it would be perfect. Obv these need to be able to run through shortcuts through lg.
Any ideas on what's happening with this issue?
@lordlycastle this is definitely something I still want lazygit to have, though I haven't spent much time thinking about it lately. One issue is that we would need a way to define where a keybinding applies. In our keybindings file pkg/gui/keybindings.go we say that a keybinding is defined on a view and also a context e.g. the 'local branches' context of the 'branches' view. I'm thinking we could only specify the context e.g. 'local-branches' and have some list of variables you'll be able to access. The main concern I have is that once we make these things available, it will be harder to change them internally without breaking shortcuts that people have made. For example right now we have a 'commitFiles' context which should really be renamed to the 'diffFiles' context because it applies to any diff.
So things like that are making me hesitant, unless everybody who signed up was happy with the possibility of commands breaking all of a sudden ;)
@lordlycastle @JalonSolov @dvdbng I've got a PR up for custom command keybindings now, let me know your thoughts :) https://github.com/jesseduffield/lazygit/pull/1019
@jesseduffield That makes very cool feature! A lot better than I expected//imagined, it's evident you put some thought in potential use-cases . Thanks for all your time and hard work! We appreciate it very much 鉂わ笍
Very nice. Looks like most if not all bases are covered. Would of course be nice to have a way other than editing a
Glad you like it :) I've merged that PR into master and I've added docs here. I've also started a wiki page that is publicly editable so that if anybody thinks up a good custom command they can include it there for others to use (and if it's popular it can be merged into lazygit itself)
At any rate I'll close this issue but let me know if you have any issues or would like to see changes :)
Most helpful comment
@lordlycastle @JalonSolov @dvdbng I've got a PR up for custom command keybindings now, let me know your thoughts :) https://github.com/jesseduffield/lazygit/pull/1019