-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init cmd for initializing antidot
- Loading branch information
1 parent
975d27c
commit 3e3f7b8
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/doron-cohen/antidot/internal/utils" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(initCmd) | ||
} | ||
|
||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
Short: "Initialize antidot for aliases and env vars to work", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO: detect shell and generate appropriate script | ||
envFilePath, err := utils.GetEnvFile() | ||
if err != nil { | ||
log.Fatalf("Failed to get env file path: %v", err) | ||
} | ||
|
||
aliasFilePath, err := utils.GetAliasFile() | ||
if err != nil { | ||
log.Fatalf("Failed to get alias file path: %v", err) | ||
} | ||
|
||
fmt.Printf(`if [[ "$ANTIDOT_INIT" != "1" ]]; then | ||
%s | ||
source %s | ||
source %s | ||
export ANTIDOT_INIT=1 | ||
fi`, | ||
utils.IndentLines(utils.XdgVarsExport()), | ||
envFilePath, | ||
aliasFilePath, | ||
) | ||
}, | ||
} |
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func IndentLines(lines string) string { | ||
var builder strings.Builder | ||
for _, line := range strings.Split(lines, "\n") { | ||
builder.WriteString(fmt.Sprintf(" %s\n", line)) | ||
} | ||
return builder.String() | ||
} |