Skip to content

Commit

Permalink
Merge pull request #248 from stokito/browser
Browse files Browse the repository at this point in the history
Open in browser
  • Loading branch information
mjarkk authored Mar 22, 2021
2 parents 415b14f + 7ede2f8 commit 3663fe5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/gui/containers_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type TranslationSet struct {
ViewRestartOptions string
RunCustomCommand string
ViewBulkCommands string
OpenInBrowser string

LogsTitle string
ConfigTitle string
Expand Down Expand Up @@ -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?",
Expand Down

0 comments on commit 3663fe5

Please sign in to comment.