jarun / ddgr

:duck: DuckDuckGo from the terminal
GNU General Public License v3.0
2.92k stars 139 forks source link

Close after a selection #144

Closed mikeslattery closed 2 years ago

mikeslattery commented 2 years ago

I love this tool. It would even better if it had an option to close after you pick an item. This would be a cli switch and/or a command.

This is my most common use case. I always have to go back and close ddgr. --ducky is similar, but it just picks the first item, whereas I want to pick an item and then auto-close. Possible interfaces:

  1. Command line switch: --close-after
  2. Omniprompt, to open and quit: <index> q.
mikecappella commented 2 years ago

Similar to what @mikeslattery requests, close on exit, I'd like the option to return the selected URL, perhaps as the last line of STDOUT (or some other form). This would allow calling ddgr from another program, selecting an item, ddgr exits, and the caller obtains the URL w/out having to use clipboard copy/paste functionality (which requires extra user steps, and is circuitous).

The problem with the clipboard copy/paste is that there's no way for the calling program to know a user has performed the copy action.

jarun commented 2 years ago

Guys, why don't you raise PRs and we can have a look?

mikecappella commented 2 years ago

Sorry, I'm confused. You're asking for a Pull Request, or Problem Report.

Pull Request - I know little about Python, not one of the many languages I use.

Problem Report - the opening tag line on this git site says "If you have a bug or an idea, browse the open issues before opening a new one". So, I thought, and perhaps @mikeslattery thought, we're opening an idea.

Is there something else you need me/us to do ?

jarun commented 2 years ago

Pull Request

mikeslattery commented 2 years ago

Maybe later. For now as a workaround I made index search auto-close. I can use o or O commands if I don't want it to close.

--- /usr/bin/ddgr   2021-01-25 23:11:56.000000000 -0500
+++ /usr/bin/ddgr   2022-06-29 15:40:31.671198375 -0400
@@ -1779,6 +1779,7 @@
                     self.help()
                 elif _num and cmd.isdigit() and int(cmd) in range(1, _num + 1):
                     open_url(self._urltable[str(int(cmd) + self.index)])
+                    break
                 elif _num == 0 and cmd in self._urltable:
                     open_url(self._urltable[cmd])
                 elif self.keywords and cmd.isdigit() and int(cmd) < 100:

For anyone that doesn't want to edit code, you can type number plus enter quickly 3 times and it will do the same thing.

jarun commented 2 years ago

Closing the issue with the above patch.

jarun commented 2 years ago

Also, it does make sense to add custom patches in the code for minor personal conveniences. I don't see too many changes in the code going forward. Just don't have the time to deal with python anymore.