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

Update shell completion configuration to remove root privileges prompt

parent bd036e68
No related branches found
No related tags found
No related merge requests found
...@@ -31,20 +31,20 @@ symlink() { ...@@ -31,20 +31,20 @@ symlink() {
} }
configure() { configure() {
# Auto-completion $HOME/bin/boilr init
if [ $? -ne 0 ]; then
binary_error="Failed to complete boilr initialization"
return
fi
# Auto-completion prompt
if [ -z "$auto_completion" ]; then if [ -z "$auto_completion" ]; then
ask "Do you want to enable auto-completion for boilr commmands?" ask "Do you want to enable auto-completion for boilr commmands?"
auto_completion=$? auto_completion=$?
fi fi
if [ $auto_completion -eq 1 ]; then if [ $auto_completion -eq 1 ]; then
sudo $HOME/bin/boilr configure-bash-completion $HOME/bin/boilr configure-bash-completion
fi
$HOME/bin/boilr init
if [ $? -ne 0 ]; then
binary_error="Failed to complete boilr initialization"
return
fi fi
} }
...@@ -124,5 +124,7 @@ esac ...@@ -124,5 +124,7 @@ esac
cat << EOF cat << EOF
Completed installation Completed installation
Boilr executable is installed to ~/bin/boilr
For more information, see: https://github.com/tmrts/boilr For more information, see: https://github.com/tmrts/boilr
EOF EOF
...@@ -48,6 +48,7 @@ const ( ...@@ -48,6 +48,7 @@ const (
// file in the configuration directory. // file in the configuration directory.
var Configuration = struct { var Configuration = struct {
FilePath string FilePath string
ConfigDirPath string
TemplateDirPath string TemplateDirPath string
}{} }{}
...@@ -68,6 +69,7 @@ func init() { ...@@ -68,6 +69,7 @@ func init() {
} }
Configuration.FilePath = filepath.Join(homeDir, ConfigDirPath, ConfigFileName) Configuration.FilePath = filepath.Join(homeDir, ConfigDirPath, ConfigFileName)
Configuration.ConfigDirPath = filepath.Join(homeDir, ConfigDirPath)
Configuration.TemplateDirPath = filepath.Join(homeDir, ConfigDirPath, TemplateDir) Configuration.TemplateDirPath = filepath.Join(homeDir, ConfigDirPath, TemplateDir)
// Read .config/boilr/config.json if exists // Read .config/boilr/config.json if exists
......
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
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"
) )
const bashrcText = `
# Enables shell command completion for boilr
source $HOME/bin/boilr
`
func configureBashCompletion() error { func configureBashCompletion() error {
var bash_completion_dir string bash_completion_file := filepath.Join(boilr.Configuration.ConfigDirPath, "completion.bash")
if bash_completion_dir = os.Getenv("BASH_COMPLETION_COMPAT_DIR"); bash_completion_dir == "" {
bash_completion_dir = "/etc/bash_completion.d"
}
bash_completion_file := filepath.Join(bash_completion_dir, boilr.AppName+".bash") if err := Root.GenBashCompletionFile(bash_completion_file); err != nil {
return err
}
if err := Root.GenBashCompletionFile(bash_completion_file); err != nil { if err := Root.GenBashCompletionFile(bash_completion_file); err != nil {
if strings.Contains(err.Error(), "permission") { return err
return fmt.Errorf("couldn't configure bash completion for %s: permission denied", boilr.AppName)
} }
bashrcPath := filepath.Join(os.Getenv("HOME"), ".bashrc")
if bashrcPath == "" {
return errors.New("environment variable ${HOME} should be set")
}
f, err := os.OpenFile(bashrcPath, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer f.Close()
if _, err = f.WriteString(bashrcText); err != nil {
return err return err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment