From 23d6a1c653db78243b2d8b299bf6929a9fa25634 Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 7 Jun 2020 13:13:06 -0700 Subject: [PATCH] Move completion installation into the main script. --- Makefile | 4 +- README.md | 36 +++++- etc/README.md | 55 ++++----- hosts | 258 +++++++++++++++++++++++++++++++++++++++ package.json | 4 +- scripts/hosts-completion | 199 ------------------------------ 6 files changed, 323 insertions(+), 233 deletions(-) delete mode 100755 scripts/hosts-completion diff --git a/Makefile b/Makefile index 5ddea1e..9e45629 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ PREFIX ?= /usr/local install: install $(BIN) $(PREFIX)/bin - ./scripts/hosts-completion install + ./$(BIN) completions install uninstall: rm -f $(PREFIX)/bin/$(BIN) - ./scripts/hosts-completion uninstall + ./$(BIN) completions uninstall diff --git a/README.md b/README.md index 543f070..4b7b9f3 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,45 @@ make install ### Manual -To install manually, simply add the `hosts` script to your `$PATH`. If -you already have a `~/bin` directory, you can use the following command: +To install as an administrator, copy and paste one of the following multi-line +commands: ```bash +# install using wget +sudo wget https://raw.github.com/xwmx/hosts/master/hosts -O /usr/local/bin/hosts && + sudo chmod +x /usr/local/bin/hosts && + sudo hosts completions install + +# install using curl +sudo curl -L https://raw.github.com/xwmx/hosts/master/hosts -o /usr/local/bin/hosts && + sudo chmod +x /usr/local/bin/hosts && + sudo hosts completions install +``` + +###### User-only Installation + +To install with just user permissions, simply add the `hosts` script to your +`$PATH`. If you already have a `~/bin` directory, for example, you can use +one of the following commands: + +```bash +# download with wget +wget https://raw.github.com/xwmx/hosts/master/hosts -O ~/bin/hosts && chmod +x ~/bin/hosts + +# download with curl curl -L https://raw.github.com/xwmx/hosts/master/hosts -o ~/bin/hosts && chmod +x ~/bin/hosts ``` +Installing with just user permissions doesn't install the completions, but +`hosts` works without them. If you have `sudo` access and want to install the +completion scripts, run the following command: + +```bash +sudo hosts completions install +``` + +### Arch Linux + A package for Arch users is also [available in the AUR](https://aur.archlinux.org/packages/hosts/). diff --git a/etc/README.md b/etc/README.md index f6dfac3..fc057c2 100644 --- a/etc/README.md +++ b/etc/README.md @@ -22,42 +22,41 @@ Completion installed: /usr/local/share/zsh/site-functions/_hosts If completion is working after installing through any of these methods, then you don't need to do anything else. -## `scripts/hosts-completion` +## `hosts completions` -`hosts` includes a script for installing and uninstalling `hosts` completions -that is used in installation hooks: -[hosts-completion](../scripts/hosts-completion) - -To run this script directly, navigate to this directory in your terminal, and -run: +The `hosts completions` subcommand can be used for installing and uninstalling +completion scripts. Depending on your configuration, you might need to use +`sudo` to install completion scripts easily: ```bash -./hosts-completion -``` +> sudo hosts completions check +Completion scripts not found. -To install completions: +> sudo hosts completions install +Completion script installed: /usr/share/bash-completion/completions/hosts +Completion script installed: /usr/local/share/zsh/site-functions/_hosts -```bash -./hosts-completion install -``` - -To uninstall: - -```bash -./hosts-completion uninstall -``` - -Use the `check` subcommand to determine if completion scripts are installed: - -```bash -> ./hosts-completion check -Exists: /usr/local/etc/bash_completion.d/hosts +> sudo hosts completions check +Exists: /usr/share/bash-completion/completions/hosts Exists: /usr/local/share/zsh/site-functions/_hosts + +> sudo hosts completions uninstall +Completion script removed: /usr/share/bash-completion/completions/hosts +Completion script removed: /usr/local/share/zsh/site-functions/_hosts ``` -This script will try to determine the completion installation -locations from your environment. If completion doesn't work, you might -need to try installing manually. +If you installed `hosts` manually by downloading just the `hosts` script, +the completion scripts won't be immediately available for +`hosts completions install`. You can try installing the completions with +the `--download` flag, which will get the latest version from GitHub: + +```bash +sudo hosts completions install --download +``` + +`hosts completions` will try to determine the completion script directories +from your environment. If `hosts completions` isn't able to install +the completion scripts, you can try installing them manually. ## Manual Installation diff --git a/hosts b/hosts index c272f2d..c0a3a25 100755 --- a/hosts +++ b/hosts @@ -80,6 +80,16 @@ else # macOS export _SED_I_COMMAND=(sed -i '') fi +# $_REPO +# +# The / identifier for the git repository. +_REPO="xwmx/hosts" + +# $_REPO_RAW_URL +# +# The base URL for raw files. +_REPO_RAW_URL="https://raw.githubusercontent.com/${_REPO}/master" + ############################################################################### # Debug ############################################################################### @@ -579,6 +589,7 @@ Usage: ${_ME} add [] ${_ME} backups [create | [compare | delete | restore | show] ] ${_ME} block ... + ${_ME} completions (check | install [-d | --download] | uninstall) ${_ME} disable ( | | ) ${_ME} disabled ${_ME} edit @@ -919,6 +930,252 @@ block() { done } +# completions ##################################################### completions + +desc "completions" <... -_main() { - _subcommand="${1:-}" - - case "${_subcommand}" in - check) - _check - ;; - install) - _install - ;; - uninstall) - _uninstall - ;; - *) - cat <