6

Is it possible to have a clickable link, in my PS1, that opens a pop-up menu or something similar?

My scenario

I've personalized my .bashrc, to show my PS1 as

user@machine: path #/$

and if I'm inside a git repository, it also show my branch and a different char for the status

user@machine: path [branch !] #/$

By the way, I got the code to do this here in Ask Ubuntu.

My idea

What I wanted was to click in the branch name, and a list of the downloaded branches is shown (with or without the option to change it).

I found some "dialog" and "select/choice" options for the pop-up menu, but couldn't find anything for the clickable link.

2
  • 1
    I'm unaware of a terminal emulator with support for something like this. You can always add support to one (Terminator which is written in Python looks like a good candidate) or write a Curses-based terminal application (in plain C or Python or any other language with Curses bindings) that is itself a terminal emulator within a terminal emulator. May 9, 2018 at 11:51
  • 1
    how unfortunate, I thought since the terminal is able to understand http links, it could have some sort of trick to do some other action with the link, besides open the browser. Thanks anyway.
    – res
    May 9, 2018 at 12:50

1 Answer 1

5

If I had to do this, I'd pick a terminal emulator like Terminator and write a new plugin. I might have to hack how that all worked but it should be possible for Terminator to pick up the text and then, using what it knows about the shell environment, present a GTK3 menu for picking.

The only other way I can think of to thoroughly handle this is to write your own shell replacement. Something that wraps around bash (et al) and handles mouse involvement. There are things out there like PyScreen that do this but there's nothing out there that does what you want directly. Proxying terminals is also a recipe for render bugs. Even mature things in this space (eg screen) occasionally mess things up.

More than anything, neither of these is 20 minute exercise. The plugin would take me hours, the shell would likely take days to get right. I'd probably push back on whomever was telling me to do this and say it's an uneconomical use of my time.

If I just wanted this for myself, I'd probably just write a little br command that listed the branches and allowed me to pick. There are examples out there but I won't present any one as the best solution. They're all a compromise on what you wanted.

1
  • 1
    Thanks for the answer. Its nothing I "have" to do, it is something I thought as a cool thing to do, and would save me some fractions of seconds. The possible resolution is far above my current knowledge and available time and will, so I guess I'll have to type "git status / git checkout" or some alias.
    – res
    May 9, 2018 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.