Created
February 1, 2023 05:27
-
-
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.
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
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