From 4a9ec9c7ebaec042e154157344683c0b7d965a8b Mon Sep 17 00:00:00 2001 From: giuseppe-g-gelardi Date: Wed, 22 Nov 2023 07:23:27 -0500 Subject: [PATCH] start work on functionality that checks if tmux exists. if it does, attach to it. if not, start a new session. --- .gitignore | 2 ++ cli/repo_selection.go | 2 -- session_config.yaml | 4 ++++ util/run_command.go | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 session_config.yaml diff --git a/.gitignore b/.gitignore index 49168e9..70efd47 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ dist/ .env.* !.env.example +# log file for local development +main.go diff --git a/cli/repo_selection.go b/cli/repo_selection.go index e38daae..a7a322a 100644 --- a/cli/repo_selection.go +++ b/cli/repo_selection.go @@ -32,8 +32,6 @@ func setRepoUrl(repo p.PartialRepo) string { } -func bareRepo() {} - func RepoSelection(config *c.Config) { s := spinner.New(spinner.CharSets[14], 100*time.Millisecond) // Build our new spinner]) s.Start() // Start the spinner diff --git a/session_config.yaml b/session_config.yaml new file mode 100644 index 0000000..d651fc3 --- /dev/null +++ b/session_config.yaml @@ -0,0 +1,4 @@ +access_token: "" +editor: vscode +alias: "" +tmux: false diff --git a/util/run_command.go b/util/run_command.go index 80ce70c..e91a2ac 100644 --- a/util/run_command.go +++ b/util/run_command.go @@ -32,6 +32,12 @@ func StartTmuxSession(sessionName string, editorCmd string) error { editorCmd = editorCmd + " ." session := StrFormat(sessionName) + /* + Check if tmux is already running + if it is, attach to the session + if not, start a new session + */ + // Start the tmux session tmuxCmd := exec.Command("tmux", "new", "-s", string(session)) tmuxCmd.Stdout = os.Stdout @@ -59,3 +65,11 @@ func StartTmuxSession(sessionName string, editorCmd string) error { return nil } +func IsTmuxActive() (bool, error) { + cmd := exec.Command("tmux", "info") + cmd.Stderr = cmd.Stdout + + err := cmd.Run() + + return err == nil, nil +}