-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.go
35 lines (30 loc) · 965 Bytes
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"os"
)
func removeRepo(config Config) {
log := NewLogUtil()
repoBasePath := config.ReposBasePath
selectedRepo := selectRepo(repoBasePath)
sessionName := createSessionName(selectedRepo)
sessionPath := createSessionPath(repoBasePath, selectedRepo)
log.Ask(fmt.Sprintf("Are you sure you want to remove %s?", sessionPath))
// Remove the directory
if err := os.RemoveAll(sessionPath); err != nil {
log.Negative("Error removing session", err)
return
} else {
log.Positive(fmt.Sprintf("Removed directory: %s", sessionPath))
}
// Check if a session exists for that repo
if sessionExists(sessionName) {
log.Positive(fmt.Sprintf("Killing session: %s", sessionName))
if err := tmux("kill-session", "-t", sessionName); err != nil {
log.Negative(fmt.Sprintf("Error killing session %s:", sessionName), err)
return
}
} else {
log.Info(fmt.Sprintf("No session found for %s. Skipping removal.", sessionName))
}
}