Last active
September 25, 2018 13:15
-
-
Save mdouchement/82532d991a21f830badbb82eba237903 to your computer and use it in GitHub Desktop.
Disable GVM GOPATH handling
This file contains hidden or 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 Go script will disable annoying GVM GOPATH management. | |
// Based on https://github.com/e-nikolov/gvm repository | |
// | |
// MIT License | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Println("Invalid number of arguments") | |
os.Exit(1) | |
} | |
gvmHome := os.ExpandEnv(os.Args[1]) | |
gvmInstaller := filepath.Join(gvmHome, "binscripts", "gvm-installer") | |
gvmDefault := filepath.Join(gvmHome, "scripts", "gvm-default") | |
gvmEnvironments, err := filepath.Glob(filepath.Join(gvmHome, "environments", "*")) | |
if err != nil { | |
panic(err) | |
} | |
// ======== | |
for _, p := range append(gvmEnvironments, gvmInstaller) { | |
data, err := ioutil.ReadFile(p) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
data = bytes.Replace( | |
data, | |
[]byte(`export GOPATH; GOPATH="`), | |
[]byte(`# export GOPATH; GOPATH="`), | |
-1, | |
) | |
f, err := os.Create(p) | |
if err != nil { | |
panic(err) | |
} | |
_, err = f.Write(data) | |
if err != nil { | |
panic(err) | |
} | |
err = f.Close() | |
if err != nil { | |
panic(err) | |
} | |
} | |
// ======== | |
gdefault, err := ioutil.ReadFile(gvmDefault) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
gdefault = bytes.Replace( | |
gdefault, | |
[]byte(`unset GOPATH`), | |
[]byte(`# unset GOPATH`), | |
-1, | |
) | |
f, err := os.Create(gvmDefault) | |
if err != nil { | |
panic(err) | |
} | |
_, err = f.Write(gdefault) | |
if err != nil { | |
panic(err) | |
} | |
err = f.Close() | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment