Skip to content

Commit

Permalink
add flag to include ProfileManager in the option list
Browse files Browse the repository at this point in the history
  • Loading branch information
obvionaoe committed May 17, 2024
1 parent a4154f3 commit 822514f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
23 changes: 16 additions & 7 deletions cmd/browser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"github.com/Wing924/shellwords"
"gopkg.in/ini.v1"
"log"
Expand All @@ -11,12 +10,16 @@ import (
"syscall"
)

const args = "--new-instance -P"
const (
commonBrowserArgs = "--new-instance"
profileManagerOption = "Launch Profile Manager"
profileManagerArg = "--ProfileManager"
profilePickerArg = "-P"
)

func getProfiles(path string) ([]string, error) {
cfg, err := ini.Load(path)
if err != nil {
fmt.Println("test")
return nil, err
}

Expand All @@ -32,20 +35,26 @@ func getProfiles(path string) ([]string, error) {
}

func runBrowser(profile string) {
args := strings.Join([]string{args, profile}, " ")
var args string

if profile == profileManagerOption {
args = strings.Join([]string{commonBrowserArgs, profileManagerArg}, " ")
} else {
args = strings.Join([]string{commonBrowserArgs, profilePickerArg, profile}, " ")
}

escapedArgs, err := shellwords.Split(args)
if err != nil {
return
log.Fatal(err)
}

executable, err := exec.LookPath(browser)
if err != nil {

log.Fatal(err)
}

err = syscall.Exec(executable, escapedArgs, os.Environ())
if err != nil {

log.Fatal(err)
}
}
26 changes: 21 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cmd

import (
"cmp"
"fmt"
"github.com/spf13/cobra"
"log"
"os"
Expand All @@ -31,9 +32,10 @@ import (
)

var (
browser string
sortProfiles bool
rofiCmd string
browser string
listProfileManager bool
sortProfiles bool
rofiCmd string
)

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -62,6 +64,13 @@ func init() {
"firefox",
"The browser to use",
)
rootCmd.Flags().BoolVarP(
&listProfileManager,
"list-profile-manager",
"p",
false,
"List the ProfileManager as an option",
)
rootCmd.Flags().BoolVarP(
&sortProfiles,
"sort",
Expand All @@ -79,11 +88,13 @@ func init() {
}

func run(cmd *cobra.Command, args []string) {
profilesFile := ""
var profilesFile string
if browser == "firefox" {
profilesFile = "~/.mozilla/firefox/profiles.ini"
} else {
} else if browser == "librewolf" {
profilesFile = "~/.librewolf/profiles.ini"
} else {
log.Fatal("unsupported browser")
}

profilesFile, err := expandTilde(profilesFile)
Expand All @@ -102,6 +113,11 @@ func run(cmd *cobra.Command, args []string) {
})
}

if listProfileManager {
fmt.Println("true")
profiles = append(profiles, profileManagerOption)
}

selectedProfile, err := runRofi(profiles)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 822514f

Please sign in to comment.