Skip to content

Commit 0dfcdcd

Browse files
committed
add sourcing string to zshrc file
1 parent 8c7f63d commit 0dfcdcd

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- setup_remote_docker
2323
- run: sudo apt install ruby
24-
- run: sudo gem install ci-scripts
24+
- run: sudo gem install ci-scripts bundler
2525

2626
- run: ci-scripts go/test
2727
- run: bash <(curl -s https://codecov.io/bash)

cmd/devctl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func initConfig() {
8585
devctlHomeFolder = path.Join(userHomeDir(), ".devctl")
8686
_, folderExists := os.Stat(devctlHomeFolder)
8787
if os.IsNotExist(folderExists) {
88-
err := os.MkdirAll(devctlHomeFolder, os.ModePerm)
88+
err := os.MkdirAll(devctlHomeFolder, 0644)
8989
utilities.Check(err, "Creating folder "+devctlHomeFolder)
9090
}
9191

cmd/generate.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ var gitignoreCmd = &cobra.Command{
4848
// get list of gitignore
4949
printer.Info("Fetching gitignore list from github")
5050
resp, err := http.Get("http://api.github.com/gitignore/templates")
51-
defer resp.Body.Close()
5251
if utilities.HandleError(err) {
5352
return
5453
}
54+
defer resp.Body.Close()
5555
availableTemplates := new([]string)
5656
err = json.NewDecoder(resp.Body).Decode(availableTemplates)
5757
if utilities.HandleError(err) {
@@ -82,10 +82,10 @@ var gitignoreCmd = &cobra.Command{
8282
printer.Info("Fetching template for " + templateLanguage)
8383

8484
resp, err := http.Get("http://api.github.com/gitignore/templates/" + templateLanguage)
85-
defer resp.Body.Close()
8685
if utilities.HandleError(err) {
8786
return
8887
}
88+
defer resp.Body.Close()
8989

9090
gitignore := new(Gitignore)
9191
err = json.NewDecoder(resp.Body).Decode(gitignore)
@@ -106,11 +106,14 @@ var gitignoreCmd = &cobra.Command{
106106

107107
var fileData []byte
108108
fileData, err = ioutil.ReadFile(fileName)
109-
if utilities.HandleError(err) {
109+
if utilities.HandleError(err, "Reading "+fileName) {
110110
return
111111
}
112112
writeString := utilities.UniqueStringMerge(string(fileData), *(gitignore.Source))
113113
err = ioutil.WriteFile(fileName, []byte(writeString), 0644)
114+
if utilities.HandleError(err, "Appending source string to "+fileName) {
115+
return
116+
}
114117
}
115118
},
116119
}

cmd/setup.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package cmd
22

33
import (
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

3336
func 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
}

plugins/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ func (n Node) String() string {
2525
func (n Node) Setup() {
2626
isNvmInstalled := nvmInstalled()
2727
if isNvmInstalled {
28-
printer.Success("nvm already installed")
28+
printer.InfoBar(printer.ColoredString("{{blue:%s}} nvm already installed"), printer.SuccessIcon)
2929
return
3030
}
3131
resp, err := http.Get("https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh")
3232
utilities.ErrorCheck(err, "nvm download")
3333
defer resp.Body.Close()
3434
body, err := ioutil.ReadAll(resp.Body)
3535

36-
printer.Info("Installing nvm")
36+
printer.InfoBar("Installing nvm")
3737
err = shell.Command("bash").SetInput(string(body)).Run()
3838
utilities.ErrorCheck(err, "nvm install")
3939
}

0 commit comments

Comments
 (0)