Skip to content

install.sh: offer to configure PATH and shell completions in shellrc#3

Open
murrayju wants to merge 1 commit intomainfrom
murrayju/install-sh-shellrc-prompts
Open

install.sh: offer to configure PATH and shell completions in shellrc#3
murrayju wants to merge 1 commit intomainfrom
murrayju/install-sh-shellrc-prompts

Conversation

@murrayju
Copy link
Copy Markdown
Member

Summary

The install script now helps users finish setup by offering (with a y/N confirmation prompt) to:

  1. Add the install directory to PATH in the user's shellrc when it isn't already there.
  2. Enable shell completions by appending a source <(ghost completion <shell>) snippet to the shellrc when completions aren't already configured.

Both prompts work under curl | sh (they read from /dev/tty). Declining a prompt or running non-interactively falls back to printing the exact manual command the user would need to run, so the installer stays useful in CI / pipelines.

Modeled on the equivalent logic in ox's install.sh, adapted to stay POSIX/dash-compatible (the Ghost installer's existing shebang is #!/bin/sh).

Details

Shellrc detection (detect_shell_rc) uses $SHELL:

  • zsh${ZDOTDIR:-$HOME}/.zshrc
  • bash$HOME/.bash_profile on macOS when it exists, otherwise $HOME/.bashrc
  • fish${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish
  • Unknown → .zshrc on Darwin or when it already exists, otherwise .bashrc

PATH configuration (configure_path_in_shellrc):

  • No-op when the dir is already in PATH or already referenced in the shellrc.
  • Uses fish_add_path / set -gx PATH for fish, export PATH="$dir:$PATH" otherwise.

Completion configuration (configure_shell_completions):

  • Supports bash, zsh, fish. Silently skips for unknown shells with a pointer to ghost completion --help.
  • For zsh, detects whether compinit is already loaded (directly or via oh-my-zsh, prezto, zinit, antigen, zplug, or zgenom) and offers to add autoload -Uz compinit && compinit -i when it isn't.
  • Uses ghost completion fish | source for fish, source <(ghost completion <shell>) otherwise.

Removed the static PATH warning that lived inside verify_installation — that responsibility now belongs to configure_path_in_shellrc, which can actually fix the problem instead of just warning about it.

Testing

  • sh -n scripts/install.sh passes.
  • Manually tested the helper functions in isolation for zsh / bash / fish / unknown $SHELL values; each returns the expected rc path, shell type, and completion snippet.

When the install directory isn't on PATH, the installer now warns and
offers to append an `export PATH=...` line to the user's shellrc,
guarded behind a y/N confirmation prompt. Declining or running
non-interactively falls back to printing the manual command.

Likewise, when shell completions aren't already configured, offer to
append a `source <(ghost completion <shell>)` snippet to the shellrc.
For zsh users whose rc doesn't already load compinit (directly or via
a framework like oh-my-zsh, prezto, zinit, antigen, zplug, or zgenom),
also offer to add `autoload -Uz compinit && compinit -i`.

Both prompts read from /dev/tty so they work under `curl | sh`. The
shellrc file is detected from $SHELL (zsh -> .zshrc, bash -> .bashrc
or .bash_profile on macOS, fish -> config.fish), with sensible
fallbacks for unknown shells. Fish uses `set -gx PATH ...` and
`ghost completion fish | source`.

Modeled on the equivalent logic in ox's install.sh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant