root.go RawHistoryFolder
1// Package cmd provides Cobra CLI commands for dumber.
2package cmd
3
4import (
5 "fmt"
6 "os"
7
8 "github.com/spf13/cobra"
9
10 "github.com/bnema/dumber/internal/cli"
11 "github.com/bnema/dumber/internal/domain/build"
12)
13
14var (
15 app *cli.App
16 buildInfo build.Info
17 rootCmd = &cobra.Command{
18 Use: "dumber",
19 Short: "A fully unfeatured unbloated browser for tiling WMs",
20 Long: `Dumber - a dumb browser that works like your favorite terminal multiplexer.
21
22A fully unfeatured unbloated browser for tiling WMs, built with GTK4 and WebKitGTK.
23
24Features:
25 - Wayland native (Sway, Hyprland, River, Niri, etc.)
26 - Tabs and workspaces with split or stacked panes
27 - Keyboard-driven workflow inspired by Zellij
28 - GPU rendering with automatic VA-API/VDPAU detection
29 - Built-in ad blocking (UBlock-based network + cosmetic filtering)
30 - Launcher integration (rofi/fuzzel) with favicons
31 - Search shortcuts via bangs (!g, !gi, etc.)
32 - Session management with auto-save and restore
33
34Use 'dumber browse' to launch the graphical browser, or explore the
35subcommands for CLI-based operations like history search and session
36management.`,
37 PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
38 // Skip initialization for commands that don't need app context
39 switch cmd.Name() {
40 case "help", "completion", "gen-docs":
41 return nil
42 }
43
44 var err error
45 app, err = cli.NewApp()
46 if err != nil {
47 return fmt.Errorf("initialize app: %w", err)
48 }
49 // Set build info from main.go
50 app.BuildInfo = buildInfo
51 return nil
52 },
53 PersistentPostRun: func(_ *cobra.Command, _ []string) {
54 if app != nil {
55 _ = app.Close()
56 }
57 },
58 }
59)
60
61// Execute runs the root command.
62func Execute() {
63 if err := rootCmd.Execute(); err != nil {
64 fmt.Fprintln(os.Stderr, err)
65 os.Exit(1)
66 }
67}
68
69// GetApp returns the initialized app (for use by subcommands).
70func GetApp() *cli.App {
71 return app
72}
73
74// browseCmd is a placeholder for help - actual execution is in main.go
75var browseCmd = &cobra.Command{
76 Use: "browse [url]",
77 Short: "Launch the graphical browser",
78 Long: `Launch the GTK4 graphical browser.
79
80If a URL is provided, navigate to it. Otherwise, open the homepage.
81
82Examples:
83 dumber browse # Open browser to homepage
84 dumber browse example.com # Open browser to URL`,
85 Run: func(_ *cobra.Command, _ []string) {
86 // This is handled by main.go before cobra runs
87 },
88}
89
90func init() {
91 rootCmd.AddCommand(browseCmd)
92}
93
94// SetBuildInfo sets the build information (called from main.go before Execute).
95func SetBuildInfo(info build.Info) {
96 buildInfo = info
97}