Open in browser

Most containers expose some http port. We can open it in browser.
For simplicity we can just open first container's published port.
This commit is contained in:
Sergey Ponomarev 2021-03-22 17:43:10 +02:00
parent 415b14fb10
commit 7ede2f8297
3 changed files with 32 additions and 0 deletions

View file

@ -571,3 +571,26 @@ func (gui *Gui) handleContainersBulkCommand(g *gocui.Gui, v *gocui.View) error {
return gui.createBulkCommandMenu(bulkCommands, commandObject)
}
// Open first port in browser
func (gui *Gui) handleContainersOpenInBrowserCommand(g *gocui.Gui, v *gocui.View) error {
container, err := gui.getSelectedContainer()
if err != nil {
return nil
}
// skip if no any ports
if len(container.Container.Ports) == 0 {
return nil
}
// skip if the first port is not published
port := container.Container.Ports[0]
if port.IP == "" {
return nil
}
ip := port.IP
if ip == "0.0.0.0" {
ip = "localhost"
}
link := fmt.Sprintf("http://%s:%d/", ip, port.PublicPort)
return gui.OSCommand.OpenLink(link)
}

View file

@ -262,6 +262,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleContainersBulkCommand,
Description: gui.Tr.ViewBulkCommands,
},
{
ViewName: "containers",
Key: 'w',
Modifier: gocui.ModNone,
Handler: gui.handleContainersOpenInBrowserCommand,
Description: gui.Tr.OpenInBrowser,
},
{
ViewName: "services",
Key: 'd',

View file

@ -82,6 +82,7 @@ type TranslationSet struct {
ViewRestartOptions string
RunCustomCommand string
ViewBulkCommands string
OpenInBrowser string
LogsTitle string
ConfigTitle string
@ -150,6 +151,7 @@ func englishSet() TranslationSet {
ViewRestartOptions: "view restart options",
RunCustomCommand: "run predefined custom command",
ViewBulkCommands: "view bulk commands",
OpenInBrowser: "open in browser (first port is http)",
AnonymousReportingTitle: "Help make lazydocker better",
AnonymousReportingPrompt: "Would you like to enable anonymous reporting data to help improve lazydocker?",