diff options
author | Teddy Wing | 2014-12-06 13:45:27 -0500 |
---|---|---|
committer | Teddy Wing | 2014-12-06 13:45:27 -0500 |
commit | a0d213e24d90bfe95342efd57cf560ae2c1996e1 (patch) | |
tree | 2ce62e7eaa7132e7777d8617b95fabc314f3e717 /git-checkout-store | |
parent | de67895ad542d70a302e5098d63ca9248fde813b (diff) | |
download | git-checkout-history-a0d213e24d90bfe95342efd57cf560ae2c1996e1.tar.bz2 |
git-checkout-store: Create an rc file if it doesn't exist
Make a `.git-checkout-historyrc` file in the current user's home
directory if the file doesn't exist.
Resources:
- [Path to home
directory](http://stackoverflow.com/questions/7922270/obtain-users-home-directory)
- [Cross-compilation version](https://github.com/mitchellh/go-homedir)
Diffstat (limited to 'git-checkout-store')
-rw-r--r-- | git-checkout-store/main.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/git-checkout-store/main.go b/git-checkout-store/main.go index 56b44ec..fcfd1c2 100644 --- a/git-checkout-store/main.go +++ b/git-checkout-store/main.go @@ -3,13 +3,35 @@ package main import ( "bytes" "fmt" + "log" "os" "os/exec" + "os/user" ) +func getHomeDir() string { + usr, err := user.Current() + if err != nil { + log.Fatal(err) + } + return usr.HomeDir +} + +func OpenRCFile() { + filename := ".git-checkout-historyrc" + if _, err := os.Stat(filename); os.IsNotExist(err) { + _, err := os.Create(getHomeDir() + "/" + filename) + if err != nil { + log.Fatal(err) + } + } +} + func main() { args := os.Args[1:] + OpenRCFile() + if len(args) > 0 { cmd := exec.Command("git", "checkout", args[0]) var out bytes.Buffer |