Skip to content
Snippets Groups Projects
Commit 90836f9a authored by Tamer Tas's avatar Tamer Tas
Browse files

Use system calls to get the user home dir

parent 04e56be2
No related branches found
No related tags found
No related merge requests found
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -9,33 +8,35 @@ import ( ...@@ -9,33 +8,35 @@ import (
cli "github.com/spf13/cobra" cli "github.com/spf13/cobra"
"github.com/tmrts/boilr/pkg/boilr" "github.com/tmrts/boilr/pkg/boilr"
"github.com/tmrts/boilr/pkg/util/exit" "github.com/tmrts/boilr/pkg/util/exit"
"github.com/tmrts/boilr/pkg/util/osutil"
) )
func configureBashCompletion() error { func configureBashCompletion() error {
bash_completion_file := filepath.Join(boilr.Configuration.ConfigDirPath, "completion.bash") bashCompletionFilePath := filepath.Join(boilr.Configuration.ConfigDirPath, "completion.bash")
if err := Root.GenBashCompletionFile(bash_completion_file); err != nil { if err := Root.GenBashCompletionFile(bashCompletionFilePath); err != nil {
return err return err
} }
if err := Root.GenBashCompletionFile(bash_completion_file); err != nil { if err := Root.GenBashCompletionFile(bashCompletionFilePath); err != nil {
return err return err
} }
bashrcPath := filepath.Join(os.Getenv("HOME"), ".bashrc") homeDir, err := osutil.GetUserHomeDir()
if bashrcPath == "" { if err != nil {
return errors.New("environment variable ${HOME} should be set") return err
} }
bashrcPath := filepath.Join(homeDir, ".bashrc")
f, err := os.OpenFile(bashrcPath, os.O_APPEND|os.O_WRONLY, 0600) f, err := os.OpenFile(bashrcPath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil { if err != nil {
return err return err
} }
defer f.Close() defer f.Close()
bashrcText := ` bashrcText := `
# Enables shell command completion for boilr # Enables command-line completion for boilr
source %s source %s
` `
......
...@@ -9,5 +9,5 @@ func GetUserHomeDir() (string, error) { ...@@ -9,5 +9,5 @@ func GetUserHomeDir() (string, error) {
return "", err return "", err
} }
return usr.HomeDir, err return usr.HomeDir, nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment