JanDeDobbeleer/oh-my-posh · error
failed to get home directory
Error message
failed to get home directory
What it means
getShellConfigPath returns this error when path.Home() yields an empty string, meaning no home directory could be determined for the current user. Without a home path the shell rc file locations (.bashrc, .zshrc, ...) cannot be computed, so Apply aborts early via the "failed to get shell config path" wrapper.
Source
Thrown at src/cli/dsc/shell.go:94
content, err := os.ReadFile(configPath)
if err != nil {
log.Debug("failed to read shell config file")
return err
}
contentStr, updated := s.updateShellConfig(string(content))
if !updated {
log.Debug("shell config already up to date, skipping write")
return nil
}
return os.WriteFile(configPath, []byte(contentStr), 0644)
}
func (s *Shell) getShellConfigPath() (string, error) {
home := path.Home()
if home == "" {
return "", fmt.Errorf("failed to get home directory")
}
switch s.Name {
case shell.BASH:
bashrc := filepath.Join(home, ".bashrc")
if _, err := os.Stat(bashrc); err == nil {
return bashrc, nil
}
return filepath.Join(home, ".bash_profile"), nil
case shell.ZSH:
return filepath.Join(home, ".zshrc"), nil
case shell.FISH:
configDir := filepath.Join(home, ".config", "fish")
return filepath.Join(configDir, "config.fish"), nil
case shell.PWSH:
return cmd.Run(s.Name, "-NoProfile", "-Command", "$PROFILE")
case shell.NU:View on GitHub (pinned to 0976794618)
Solutions
- Set HOME to the user's home directory before running oh-my-posh (e.g. export HOME=/root or /home/<user>)
- Run the command as a normal login user whose home is resolvable (`echo $HOME` should print a non-empty path)
- In containers/CI, pass the env explicitly: docker run -e HOME=/root ... or set it in the pipeline env
- Check for a typo'd or empty HOME entry in your shell profile or service definition
Example fix
// before: HOME unset in CI
oh-my-posh dsc apply -f shell.yaml
// after
export HOME=${HOME:-$(getent passwd $(whoami) | cut -d: -f6)}
oh-my-posh dsc apply -f shell.yaml Defensive patterns
Strategy: validation
Validate before calling
home, err := os.UserHomeDir()
if err != nil || home == "" {
return fmt.Errorf("no home directory available: %w", err)
}
if st, serr := os.Stat(home); serr != nil || !st.IsDir() {
return fmt.Errorf("home %s is not accessible", home)
} Try / catch
if err := sh.Apply(); err != nil {
if strings.Contains(err.Error(), "home directory") {
return fmt.Errorf("set HOME to a valid directory before applying: %w", err)
}
return err
} Prevention
- Export HOME explicitly in containers, cron jobs, and CI runners
- Use login shells or `su -`/`sudo -i` so the environment includes HOME
- Verify `echo $HOME` prints a non-empty, existing path before applying DSC documents
- Avoid stripping the environment with `env -i` unless you re-export HOME
When it happens
Trigger: Applying a DSC Shell resource in an environment where HOME is unset (bare container, some CI runners, su without proper env) or where the OS user lookup fails so path.Home() returns "".
Common situations: Docker containers running as root or a service account without HOME; cron/systemd jobs with a stripped environment; Windows builds where the user profile directory cannot be resolved.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- failed to get shell config path: %w
- unsupported shell type: %s
- environment access is disabled: rendering from recorded data
- terminal width must be greater than zero
- source file %s does not match format %s
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/e0d911cf1a93ee24.
Report an issue: GitHub.