knqyf263 / pet

Simple command-line snippet manager
MIT License
4.26k stars 221 forks source link

[Feature Request] Set cursor point #163

Open JakeElder opened 3 years ago

JakeElder commented 3 years ago

It would be useful to be able to set the cursor point when entering a snippet, IE

$ pet new "git commit -am \"feat(ui): <cursor>\""

This would be a lighter way to enter snippets with one variable

RamiAwar commented 5 months ago

✨ I think 2 things need to be solved here ✨

1. When we have default values, we need to prioritize letting the user pick default values over giving them an empty parameter with the cursor in the right place.

2. If we have multiple parameters, this feature will no longer make sense (unless we can dynamically control the cursor which I have no idea how to do, might even be impossible as its probably maintained in the shell process memory).

We need a solution that can resolve those two points.

💡 Proposed Solution 💡

Have an optional flag on new commands which you can choose to apply if you know you have no need for a default value and you only have a single parameter (commands like the one you just described, I have a lot of those as well so I can relate).

If you do apply this flag to a new command, you won't be able to set any default parameters (will be ignored, or maybe we can even error out if we detect any). And when you execute this command, then your cursor gets placed in the right position.

I'm just not sure how to manipulate the cursor like this yet. Will have to look into it. Do you know how? @JakeElder