-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement config and startup scripts (#22)
Implements parsing of a sesh/sesh.toml config file and creates a pattern for future use. Add the ability to configure a startup script for a project
- Loading branch information
1 parent
db29565
commit b6f0de4
Showing
11 changed files
with
160 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/pelletier/go-toml/v2" | ||
) | ||
|
||
type ( | ||
Script struct { | ||
SessionPath string `toml:"session_path"` | ||
ScriptPath string `toml:"script_path"` | ||
} | ||
Config struct { | ||
StartupScripts []Script `toml:"startup_scripts"` | ||
DefaultStartupScript string `toml:"default_startup_script"` | ||
} | ||
) | ||
|
||
func getUserConfigDir() (string, error) { | ||
switch runtime.GOOS { | ||
case "darwin": | ||
// typically ~/Library/Application Support, but we want to use ~/.config | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
return path.Join(homeDir, ".config"), nil | ||
default: | ||
return os.UserConfigDir() | ||
} | ||
} | ||
|
||
func ParseConfigFile() Config { | ||
config := Config{} | ||
configDir, err := getUserConfigDir() | ||
if err != nil { | ||
fmt.Printf( | ||
"Error determining the user config directory: %s\nUsing default config instead", | ||
err, | ||
) | ||
return config | ||
} | ||
configPath := filepath.Join(configDir, "sesh", "sesh.toml") | ||
data, err := os.ReadFile(configPath) | ||
if err != nil { | ||
return config | ||
} | ||
err = toml.Unmarshal(data, &config) | ||
if err != nil { | ||
fmt.Printf( | ||
"Error parsing config file: %s\nUsing default config instead", | ||
err, | ||
) | ||
return config | ||
} | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters