Skip to content

Instantly share code, notes, and snippets.

@sergsoares
Created February 1, 2023 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergsoares/29357fce095759de553b12faec82f7a5 to your computer and use it in GitHub Desktop.
Save sergsoares/29357fce095759de553b12faec82f7a5 to your computer and use it in GitHub Desktop.
Simple main.go to process a Key/Value bookmarks as .command for be used in MacOS.
package main
import (
"encoding/json"
"os"
"path/filepath"
)
const (
output = "shortcuts"
filePath = "aws-services.json"
)
func main() {
file, err := os.Open(filePath)
if err != nil {
panic(err)
}
defer file.Close()
var data map[string]string
if err := json.NewDecoder(file).Decode(&data); err != nil {
panic(err)
}
for key := range data {
filePath := filepath.Join(output, key+".command")
f, err := os.Create(filePath)
if err != nil {
panic(err)
}
if _, err := f.WriteString(data[key]); err != nil {
panic(err)
}
f.Close()
if err := os.Chmod(filePath, 0755); err != nil {
panic(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment