11package cmd
22
33import (
4+ "fmt"
5+ "io/ioutil"
46 "os"
57 "path"
68
79 "github.com/bcaldwell/devctl/postCommand"
10+ printer "github.com/bcaldwell/go-printer"
811
912 "github.com/bcaldwell/devctl/plugins"
1013 "github.com/bcaldwell/devctl/utilities"
@@ -31,6 +34,8 @@ func init() {
3134}
3235
3336func setup (cmd * cobra.Command , args []string ) {
37+ printer .InfoLineTop ()
38+ // create devctl.sh file in devctl home folder (HOME/.devctl)
3439 data , err := Asset ("devctl.sh" )
3540 utilities .Check (err , "Fetching devctl.sh file contents" )
3641
@@ -42,11 +47,28 @@ func setup(cmd *cobra.Command, args []string) {
4247 _ , err = f .Write (data )
4348 utilities .Check (err , "Writing contents to " + fileName )
4449
45- // TODO: source file
50+ profileFile := detectProfile ()
51+ profileFile = path .Join (os .Getenv ("HOME" ), profileFile )
52+
53+ devctlSourceString := fmt .Sprintf ("[ -f %s ] && \\ . %s # This loads devctl shell super powers" , fileName , fileName )
54+
55+ fileData , err := ioutil .ReadFile (profileFile )
56+ if utilities .HandleError (err ) {
57+ return
58+ }
59+ writeString := utilities .UniqueStringMerge (string (fileData ), devctlSourceString )
60+ err = ioutil .WriteFile (profileFile , []byte (writeString ), 0644 )
4661
4762 postCommand .RunCommand ("source " + fileName )
4863
64+ printer .InfoBar (printer .ColoredString ("{{green:%s}} Setup shell functions" ), printer .SuccessIcon )
65+
4966 for _ , i := range plugins .List {
5067 i .Setup ()
5168 }
69+ printer .InfoLineBottom ()
70+ }
71+
72+ func detectProfile () string {
73+ return ".zshrc"
5274}
0 commit comments