From 638da3200e8f8002f1d393424bc6f0390755bc08 Mon Sep 17 00:00:00 2001 From: William Melody Date: Mon, 13 Apr 2020 16:36:58 -0700 Subject: [PATCH] Reconfigure completion setup. --- README.md | 7 +++ etc/README.md | 62 +++++++++++++++++++ .../hosts-completion.bash | 0 .../hosts-completion.zsh | 0 4 files changed, 69 insertions(+) create mode 100644 etc/README.md rename hosts-completion.bash => etc/hosts-completion.bash (100%) rename hosts-completion.zsh => etc/hosts-completion.zsh (100%) diff --git a/README.md b/README.md index 63ae5a0..f3c383d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ curl -L https://raw.github.com/xwmx/hosts/master/hosts \ A package for Arch users is also [available in the AUR](https://aur.archlinux.org/packages/hosts/). +### Completions + +`hosts` supports tab completion for bash and zsh. If you install `hosts` +with Homebrew, the completion scripts will be installed automatically. +When installing `hosts` through other methods, [completion can be +enabled with a few commands](etc/README.md). + ## Usage ### Listing Entries diff --git a/etc/README.md b/etc/README.md new file mode 100644 index 0000000..6ba4cd4 --- /dev/null +++ b/etc/README.md @@ -0,0 +1,62 @@ +# Installation instructions + +## Homebrew + +If you're using Homebrew, just run `brew install xwmx/taps/hosts` and the +completion scripts will be installed automatically. The extra steps to install +`hosts` completion scripts outlined below are *not needed*. + +A one-time setup might be needed to [enable completion for all Homebrew +programs](https://docs.brew.sh/Shell-Completion). + +## bash + +### Linux + +On a current Linux OS (in a non-minimal installation), bash completion should +be available. + +Place the completion script in `/etc/bash_completion.d/`: + +```bash +sudo curl -L https://raw.githubusercontent.com/xwmx/hosts/master/hosts-completion.bash -o /etc/bash_completion.d/hosts +``` + +### macOS + +If you aren't installing with homebrew, source the completion script in +`.bash_profile`: + +```sh +if [[ -f /path/to/hosts-completion.bash ]] +then + source /path/to/hosts-completion.bash +fi +``` + +## zsh + +Place the completion script in your `/path/to/zsh/completion` (typically +`~/.zsh/completion/`): + +```bash +$ mkdir -p ~/.zsh/completion +$ curl -L https://raw.githubusercontent.com/xwmx/hosts/master/hosts-completion.zsh > ~/.zsh/completion/_hosts +``` +Include the directory in your $fpath by adding in `~/.zshrc`: + +```bash +fpath=(~/.zsh/completion $fpath) +``` + +Make sure compinit is loaded or do it by adding in `~/.zshrc`: + +```bash +autoload -Uz compinit && compinit -i +``` + +Then reload your shell: + +```bash +exec $SHELL -l +``` diff --git a/hosts-completion.bash b/etc/hosts-completion.bash similarity index 100% rename from hosts-completion.bash rename to etc/hosts-completion.bash diff --git a/hosts-completion.zsh b/etc/hosts-completion.zsh similarity index 100% rename from hosts-completion.zsh rename to etc/hosts-completion.zsh