Skip to content

Commit

Permalink
Prefer zsh rather than fish again
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 20, 2023
1 parent 20d1cc0 commit fe7ef3a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/enable_nix_login_shells/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (

// This script requires sudo execution, if it is a reasonable way, including in home.nix may be better

var homePath string

func getShellPath(homePath string, shellName string) string {
return homePath + "/.nix-profile/bin/" + shellName
}

func main() {
homePath, ok := os.LookupEnv("HOME")
if !ok {
Expand All @@ -20,7 +26,8 @@ func main() {
log.Fatalln("used by root looks weird. You should run `sudo -E ...` instead of `sudo ...`")
}

loginableShells := []string{"bash", "zsh", "fish"}
const primaryShell = "zsh"
loginableShells := []string{primaryShell, "bash", "fish"}

etcShellsBytes, err := os.ReadFile("/etc/shells")
if err != nil {
Expand All @@ -29,15 +36,13 @@ func main() {

etcShells := string(etcShellsBytes)
dirty := strings.Clone(etcShells)
examplePath := ""

for _, sh := range loginableShells {
shellPath := homePath + "/.nix-profile/bin/" + sh
shellPath := getShellPath(homePath, sh)
if strings.Contains(etcShells, shellPath) {
log.Printf("skip - %s is already registered in /etc/shells\n", shellPath)
} else {
log.Printf("insert - %s will be registered in /etc/shells\n", shellPath)
examplePath = shellPath
dirty += fmt.Sprintln(shellPath)
}
}
Expand All @@ -47,10 +52,11 @@ func main() {
if err != nil {
log.Fatalf("failed - could you correctly run this with sudo? - %v\n", err)
}
}

fmt.Printf(`Done! Set one of your favorite shell as follows
fmt.Printf(`Done! Set one of your favorite shell as follows
chsh -s %s "$(whoami)"
`, examplePath)
}
`, getShellPath(homePath, primaryShell))

}

0 comments on commit fe7ef3a

Please sign in to comment.