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

Expose the command count to the commands #62

Closed
lenormf opened this issue Mar 6, 2017 · 9 comments
Closed

Expose the command count to the commands #62

lenormf opened this issue Mar 6, 2017 · 9 comments

Comments

@lenormf
Copy link

lenormf commented Mar 6, 2017

Hi,

It'd be convenient to have the command count passed as an environment variable to the commands, like ${count}.

Example:

cmd foo ${{
printenv count # prints 2
}}
push 2:foo<ret>

Thanks.

@gokcehan
Copy link
Owner

gokcehan commented Mar 6, 2017

@lenormf I need to check the code to see if this is possible. Is there a use case for this?

@lenormf
Copy link
Author

lenormf commented Mar 7, 2017

I've implemented a bookmark command that works with numbers (like in ranger), and right now my binding is the following:

map b push :bookmark<space>

But I would like to simply bind a key to the bookmark command, and have the latter get the count. My case is not the most representative because bookmarks could also be letters (in which case my current implementation is clearly better), but maybe there's other things out there that could benefit from a count environment variable.

@gokcehan
Copy link
Owner

gokcehan commented Mar 7, 2017

@lenormf It never occurred to me that we could implement bookmarks with commands. This could be interesting. In the meantime, I have looked at the code a little bit and there doesn't seem like an easy way to do this so it may take some time.

@gokcehan
Copy link
Owner

@lenormf I have been thinking about bookmarks. If we pass count variable as you suggested then I think we still won't be able to list available bookmarks to the user to choose from, am I right?

@lenormf
Copy link
Author

lenormf commented Apr 17, 2017

My implementation stores the saved paths in files, so listing all the bookmarks is a easy as walking through all those files and displaying their contents.

The idea behind using counts is that I would be able to save/load a bookmark in just two keystrokes, as opposed to issuing the bookmark command with the bookmark name as parameter, and hitting enter. I managed to trim down the amount of keystrokes to a minimum with the following mapping, but using count would be the fastest way since I assume that bookmarks' names are numbers:

map b push :bookmark<space>

@gokcehan
Copy link
Owner

So there are two parts to a bookmark implementation. We need to be able to save the current directory as a bookmark (e.g. bookmark-save), and we should be able to load a bookmark when we need it (e.g. bookmark-load). I understand this may reduce keystrokes in the first part but we still need the second part. This can also reduce keystrokes in the second part but I can't think of a way to list bookmarks at the same time. So then users need to remember which keys they have saved their bookmarks which may be difficult.

I'm asking because I was thinking second part could be implemented as such. Assume bookmarks are saved in a file. When we run bookmark-load command, which could be bound to a key, we can print the list of bookmarks and wait for a keystroke. Depending on the keystroke we can change the directory with a remote command. It's tricky to read a single character in posix shell without an enter key but it's still possible (lf uses it for its "press any key" implementation).

Then the first part could also be implemented in a similar fashion. When a user run bookmark-save command, ui is paused and a message says something like push a key to assign a bookmark. Then we can save the current directory in the bookmark file. Pausing the ui may not be very desirable but at least it has the advantage to be able to use keys other than numbers.

@lenormf
Copy link
Author

lenormf commented Apr 17, 2017

I only need a single command in my implementation, what would be bookmark-load in your explanation would do bookmark-save of the current directory if no prior bookmark was created with the given ID. I think it's more convenient that way, do you want to have two separate commands (map B bookmark-save; map b bookmark-load)?

This can also reduce keystrokes in the second part but I can't think of a way to list bookmarks at the same time

If you know how/where the bookmarks are stored, you also know which ones have been saved, don't you? Unless you meant there's no logical place where the code to display all the bookmarks would be triggered in an implementation where the ID is hit first?

In any case, I thought of using counts first because I thought it would be easy to add them to the shell environment, and they would allow access to bookmarks using max. 2 strokes. ranger uses alt based mappings, but I don't really like it, so counts seemed like a good deal when -similarly to ranger- I wanted my bookmarks to be single digits. I don't mind having a more interactive implementation as long as I don't have to hit too many keys (3 is borderline cumbersome for me, compared to how fast it was with ranger).

That also raises another question, is there any use for counts as a part of the environment? Should another issue dedicated to bookmarks be created, or should this one be renamed?

@gokcehan
Copy link
Owner

gokcehan commented Apr 17, 2017

I don't mind having a single command or two commands for this purpose as long as it works.

I have now opened a new issue (#76) for bookmarks. Bookmarks were the original motivation for this feature. If we can implement bookmarks without this feature maybe we can leave this issue here with a low priority until another possible use case comes up.

@joelim-work
Copy link
Collaborator

This is fixed in #1187 and can be closed.

@gokcehan I didn't realise this issue existed, otherwise I would have linked it in the PR so that it would automatically be closed.

@gokcehan gokcehan closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants