mirror of https://github.com/octoleo/hosts.git
Compare commits
78 Commits
Author | SHA1 | Date |
---|---|---|
William Melody | 8916c43efa | |
William Melody | 9ea716f861 | |
William Melody | 9a929dc70f | |
William Melody | 80699292a4 | |
William Melody | 06ad3e8deb | |
William Melody | c74671613b | |
William Melody | 0201480ffb | |
William Melody | 0ce875c210 | |
William Melody | 6a58eb693d | |
William Melody | 245188025a | |
William Melody | 39a182b47e | |
William Melody | bd7edba09b | |
William Melody | 5049abe817 | |
William Melody | 5c87ad62b0 | |
William Melody | ca51f3f742 | |
William Melody | ade1109cba | |
William Melody | 3c383581c5 | |
William Melody | 2346f6f814 | |
William Melody | 0715b9ec66 | |
William Melody | 42a2a9f3d4 | |
William Melody | c11f22e558 | |
William Melody | 0d5f41537d | |
William Melody | 0a98202f84 | |
William Melody | 040593bd51 | |
William Melody | 0b79763874 | |
William Melody | d6e3a8a128 | |
William Melody | 0fa9b240c6 | |
William Melody | 83bb517312 | |
William Melody | d396c5eefb | |
William Melody | 8ab47640f0 | |
William Melody | c3be802faf | |
William Melody | 768acb5d80 | |
William Melody | 379f99f4e1 | |
William Melody | 28fea3a599 | |
William Melody | bf65fbcad8 | |
William Melody | 5d4a9dfb28 | |
William Melody | 0bd86e533d | |
William Melody | a39c60aafa | |
William Melody | 1da838faeb | |
William Melody | 6e1d408ad5 | |
William Melody | c381c8bd98 | |
William Melody | 426f2ed602 | |
William Melody | 7596a2901f | |
William Melody | 4e9ad74697 | |
William Melody | 051e8b3840 | |
William Melody | f585447612 | |
William Melody | 4238e8bd81 | |
William Melody | a64c20bdd8 | |
William Melody | 5865f92977 | |
William Melody | 2b81ea530f | |
William Melody | 1e6af9b309 | |
William Melody | 47b5d51fa3 | |
William Melody | d775353c9a | |
William Melody | 73ecc3119e | |
William Melody | d242aed463 | |
William Melody | 9bf7f782c9 | |
William Melody | f0ebb08cd4 | |
William Melody | 4aeab14d2d | |
William Melody | 952e2465b3 | |
William Melody | 23d6a1c653 | |
William Melody | 17b2615820 | |
William Melody | 68b421f95a | |
William Melody | a09e7b2468 | |
William Melody | dfbc83e12c | |
William Melody | fff87648d4 | |
William Melody | 8f6a700909 | |
William Melody | 1d948837d0 | |
William Melody | 8f2553b5a3 | |
William Melody | 2f6290f3d4 | |
William Melody | 16a672d52a | |
William Melody | 16a95406fe | |
William Melody | 5a7d0cca91 | |
William Melody | 40be65b7da | |
William Melody | affd8d8657 | |
William Melody | 6e751065de | |
William Melody | 3e326dad13 | |
William Melody | 6bde3438c6 | |
William Melody | ca43d92d85 |
|
@ -0,0 +1,2 @@
|
|||
github: xwmx
|
||||
custom: https://paypal.me/WilliamMelody
|
|
@ -0,0 +1,84 @@
|
|||
###############################################################################
|
||||
# .github/workflows/tests.yml
|
||||
#
|
||||
# NOTE: GitHub Actions does not allocate a TTY, preventing detection of
|
||||
# piped input using `[[ -t 0 ]]`.
|
||||
#
|
||||
# More information:
|
||||
#
|
||||
# https://github.com/actions/runner/issues/241
|
||||
#
|
||||
# faketty is a GitHub action that uses work-arounds to provide a tty:
|
||||
#
|
||||
# https://github.com/marketplace/actions/faketty
|
||||
#
|
||||
# Scripts used by faketty for each platform:
|
||||
#
|
||||
# linux: `faketty`
|
||||
#
|
||||
# ```bash
|
||||
# #!/bin/bash
|
||||
#
|
||||
# script -q -e -c "$*"
|
||||
# ```
|
||||
#
|
||||
# win32: `faketty.ps1`
|
||||
#
|
||||
# ```posh
|
||||
# Invoke-Expression "$args"
|
||||
# ```
|
||||
#
|
||||
# darwin: `faketty`
|
||||
#
|
||||
# requires: `brew install expect`
|
||||
#
|
||||
# ```bash
|
||||
# #!/bin/bash
|
||||
#
|
||||
# unbuffer $*
|
||||
# ```
|
||||
###############################################################################
|
||||
|
||||
name: "hosts · Test Suite"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
push:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-macos-11:
|
||||
name: "Test: macOS Big Sur 11.0"
|
||||
runs-on: macos-11.0
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: "Setup"
|
||||
run: |
|
||||
brew update
|
||||
brew install bats-core
|
||||
brew install expect
|
||||
- name: "Set $TERM=xterm"
|
||||
run: printf "TERM=xterm\\n" >> $GITHUB_ENV
|
||||
- name: "Run bats tests"
|
||||
run: unbuffer bats test
|
||||
test-ubuntu-latest:
|
||||
name: "Test: Ubuntu Latest"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: "Setup"
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install bats -y
|
||||
- name: "Install bats-core"
|
||||
run: |
|
||||
git clone https://github.com/bats-core/bats-core.git "${HOME}/bats-core" &&
|
||||
cd "${HOME}/bats-core"
|
||||
git checkout 2e2e5df6adf0b846b411b6b2f7bb654cbc3e2c4e
|
||||
sudo ./install.sh /usr/local
|
||||
- name: "Set $TERM=xterm"
|
||||
run: printf "TERM=xterm\\n" >> $GITHUB_ENV
|
||||
- name: "Run bats tests"
|
||||
run: script -q -e -c "bats test"
|
|
@ -5,6 +5,14 @@
|
|||
# https://github.com/koalaman/shellcheck/wiki/Ignore
|
||||
###############################################################################
|
||||
|
||||
# Disable SC2183
|
||||
#
|
||||
# Running into this: https://github.com/koalaman/shellcheck/issues/1310
|
||||
# TODO: Check if resolved.
|
||||
#
|
||||
#https://github.com/koalaman/shellcheck/wiki/SC2183
|
||||
disable=SC2183
|
||||
|
||||
# Disable SC2206 and SC2207
|
||||
#
|
||||
# `IFS` and `noglob` are set.
|
||||
|
|
18
.travis.yml
18
.travis.yml
|
@ -1,18 +0,0 @@
|
|||
jobs:
|
||||
include:
|
||||
- os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:duggan/bats'
|
||||
packages:
|
||||
- bats
|
||||
dist: bionic
|
||||
language: minimal
|
||||
- os: osx
|
||||
before_install:
|
||||
- brew install bats-core
|
||||
osx_image: xcode11.3
|
||||
|
||||
script: bats test
|
||||
|
4
Makefile
4
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
|
||||
|
|
124
README.md
124
README.md
|
@ -1,4 +1,4 @@
|
|||
[![Build Status](https://travis-ci.org/xwmx/hosts.svg?branch=master)](https://travis-ci.org/xwmx/hosts)
|
||||
[![Build Status](https://img.shields.io/github/actions/workflow/status/xwmx/hosts/tests.yml?branch=master)](https://github.com/xwmx/hosts/actions)
|
||||
|
||||
__ __
|
||||
/ /_ ____ _____/ /______
|
||||
|
@ -25,7 +25,8 @@ single, portable script that can be `curl`ed into any environment.
|
|||
To install with [Homebrew](http://brew.sh/):
|
||||
|
||||
```bash
|
||||
brew install xwmx/taps/hosts
|
||||
brew tap xwmx/taps
|
||||
brew install hosts
|
||||
```
|
||||
|
||||
### npm
|
||||
|
@ -50,18 +51,50 @@ To install with [Make](https://en.wikipedia.org/wiki/Make_(software)),
|
|||
clone this repository, navigate to the clone's root directory, and run:
|
||||
|
||||
```bash
|
||||
make install
|
||||
sudo 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/).
|
||||
|
||||
|
@ -127,7 +160,7 @@ address, domain, or regular expression:
|
|||
|
||||
```bash
|
||||
> hosts remove example.com
|
||||
Removing the following records:
|
||||
Removing the following entries:
|
||||
127.0.0.1 example.com
|
||||
Are you sure you want to proceed? [y/N] y
|
||||
Removed:
|
||||
|
@ -159,7 +192,7 @@ Removed:
|
|||
|
||||
### Enabling / Disabling Entries
|
||||
|
||||
Add entries are enabled by default. Disabiling an entry comments it out
|
||||
All entries are enabled by default. Disabiling an entry comments it out
|
||||
so it has no effect, but remains in the hosts file ready to be enabled
|
||||
again.
|
||||
|
||||
|
@ -299,6 +332,7 @@ Usage:
|
|||
hosts add <ip> <hostname> [<comment>]
|
||||
hosts backups [create | (compare | delete | restore | show) <filename>]
|
||||
hosts block <hostname>...
|
||||
hosts completions (check | install [-d | --download] | uninstall)
|
||||
hosts disable (<ip> | <hostname> | <search string>)
|
||||
hosts disabled
|
||||
hosts edit
|
||||
|
@ -308,6 +342,7 @@ Usage:
|
|||
hosts list [enabled | disabled | <search string>]
|
||||
hosts search <search string>
|
||||
hosts show (<ip> | <hostname> | <search string>)
|
||||
hosts subcommands [--raw]
|
||||
hosts remove (<ip> | <hostname> | <search string>) [--force]
|
||||
hosts unblock <hostname>...
|
||||
hosts --auto-sudo
|
||||
|
@ -342,7 +377,7 @@ hosts help <command name>
|
|||
<a href="#hosts-add">add</a> •
|
||||
<a href="#hosts-backups">backups</a> •
|
||||
<a href="#hosts-block">block</a> •
|
||||
<a href="#hosts-commands">commands</a> •
|
||||
<a href="#hosts-completions">completions</a> •
|
||||
<a href="#hosts-disable">disable</a> •
|
||||
<a href="#hosts-disabled">disabled</a> •
|
||||
<a href="#hosts-edit">edit</a> •
|
||||
|
@ -354,6 +389,7 @@ hosts help <command name>
|
|||
<a href="#hosts-remove">remove</a> •
|
||||
<a href="#hosts-search">search</a> •
|
||||
<a href="#hosts-show">show</a> •
|
||||
<a href="#hosts-subcommands">subcommands</a> •
|
||||
<a href="#hosts-unblock">unblock</a> •
|
||||
<a href="#hosts-version">version</a>
|
||||
</p>
|
||||
|
@ -366,7 +402,7 @@ Usage:
|
|||
|
||||
Description:
|
||||
List the existing IP / hostname pairs, optionally limited to a specified
|
||||
state. When provided with a seach string, all matching enabled records will
|
||||
state. When provided with a seach string, all matching enabled entries will
|
||||
be printed.
|
||||
|
||||
Alias for `hosts list`
|
||||
|
@ -382,7 +418,7 @@ Description:
|
|||
Add a given IP address and hostname pair, along with an optional comment.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 Entry successfully added.
|
||||
1 Invalid parameters or entry exists.
|
||||
```
|
||||
|
||||
|
@ -427,7 +463,7 @@ Description:
|
|||
for IPv4 and both `fe80::1%lo0` and `::1` for IPv6.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 <hostname> successfully blocked.
|
||||
1 Invalid parameters or entry exists.
|
||||
```
|
||||
|
||||
|
@ -436,17 +472,22 @@ Exit status:
|
|||
- [jmdugan/blocklists](https://github.com/jmdugan/blocklists)
|
||||
- [notracking/hosts-blocklists](https://github.com/notracking/hosts-blocklists)
|
||||
|
||||
### `hosts commands`
|
||||
### `hosts completions`
|
||||
|
||||
```text
|
||||
Usage:
|
||||
hosts commands [--raw]
|
||||
hosts completions (check | install [-d | --download] | uninstall)
|
||||
|
||||
Options:
|
||||
--raw Display the command list without formatting.
|
||||
-d, --download Download the completion scripts and install.
|
||||
|
||||
Description:
|
||||
Display the list of available commands.
|
||||
Manage completion scripts. For more information, visit:
|
||||
https://github.com/xwmx/hosts/blob/master/etc/README.md
|
||||
|
||||
Exit status:
|
||||
0 Completions successfully installed.
|
||||
1 Invalid parameters or other error.
|
||||
```
|
||||
|
||||
### `hosts disable`
|
||||
|
@ -456,11 +497,11 @@ Usage:
|
|||
hosts disable (<ip> | <hostname> | <search string>)
|
||||
|
||||
Description:
|
||||
Disable one or more records based on a given ip address, hostname, or
|
||||
Disable one or more entries based on a given ip address, hostname, or
|
||||
search string.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 Entry successfully disabled.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
|
@ -471,7 +512,11 @@ Usage:
|
|||
hosts disabled
|
||||
|
||||
Description:
|
||||
List all disabled records. This is an alias for `hosts list disabled`.
|
||||
List all disabled entries. This is an alias for `hosts list disabled`.
|
||||
|
||||
Exit status:
|
||||
0 One or more disabled entries found.
|
||||
1 Invalid parameters or no disabled entries found.
|
||||
```
|
||||
|
||||
### `hosts edit`
|
||||
|
@ -491,11 +536,11 @@ Usage:
|
|||
hosts enable (<ip> | <hostname> | <search string>)
|
||||
|
||||
Description:
|
||||
Enable one or more disabled records based on a given ip address, hostname,
|
||||
Enable one or more disabled entries based on a given ip address, hostname,
|
||||
or search string.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 Entry successfully enabled.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
|
@ -506,7 +551,11 @@ Usage:
|
|||
hosts enabled
|
||||
|
||||
Description:
|
||||
List all enabled records. This is an alias for `hosts list enabled`.
|
||||
List all enabled entries. This is an alias for `hosts list enabled`.
|
||||
|
||||
Exit status:
|
||||
0 One or more enabled entries found.
|
||||
1 Invalid parameters or no enabled entries found.
|
||||
```
|
||||
|
||||
### `hosts file`
|
||||
|
@ -537,8 +586,12 @@ Usage:
|
|||
|
||||
Description:
|
||||
List the existing IP / hostname pairs, optionally limited to a specified
|
||||
state. When provided with a seach string, all matching enabled records will
|
||||
state. When provided with a seach string, all matching enabled entries will
|
||||
be printed.
|
||||
|
||||
Exit status:
|
||||
0 One or more matching entries found.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
### `hosts remove`
|
||||
|
@ -552,12 +605,12 @@ Options:
|
|||
--force Skip the confirmation prompt.
|
||||
|
||||
Description:
|
||||
Remove one or more records based on a given IP address, hostname, or search
|
||||
string. If an IP and hostname are both provided, only records matching the
|
||||
Remove one or more entries based on a given IP address, hostname, or search
|
||||
string. If an IP and hostname are both provided, only entries matching the
|
||||
IP and hostname pair will be removed.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 Entry successfully removed.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
|
@ -569,6 +622,10 @@ Usage:
|
|||
|
||||
Description:
|
||||
Search entries for <search string>.
|
||||
|
||||
Exit status:
|
||||
0 One or more matching entries found.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
### `hosts show`
|
||||
|
@ -581,10 +638,23 @@ Description:
|
|||
Print entries matching a given IP address, hostname, or search string.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 One or more matching entries found.
|
||||
1 Invalid parameters or entry not found.
|
||||
```
|
||||
|
||||
### `hosts subcommands`
|
||||
|
||||
```text
|
||||
Usage:
|
||||
hosts subcommands [--raw]
|
||||
|
||||
Options:
|
||||
--raw Display the subcommands list without formatting.
|
||||
|
||||
Description:
|
||||
Display the list of available subcommands.
|
||||
```
|
||||
|
||||
### `hosts unblock`
|
||||
|
||||
```text
|
||||
|
@ -595,7 +665,7 @@ Description:
|
|||
Unblock one or more hostnames by removing the entries from the hosts file.
|
||||
|
||||
Exit status:
|
||||
0 Success.
|
||||
0 <hostname> successfully unblocked.
|
||||
1 Invalid parameters or entry not found
|
||||
```
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "hosts.sh",
|
||||
"version": "3.5.0",
|
||||
"version": "3.6.4",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hosts.sh",
|
||||
"version": "3.5.0",
|
||||
"version": "3.6.4",
|
||||
"description": "A command line tool for managing hosts file entries.",
|
||||
"global": true,
|
||||
"install": "make install",
|
||||
|
@ -12,8 +12,8 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test": "bats test",
|
||||
"postinstall": "scripts/hosts-completion install",
|
||||
"preuninstall": "scripts/hosts-completion uninstall"
|
||||
"postinstall": "./hosts completions install",
|
||||
"preuninstall": "./hosts completions uninstall"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,199 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
###############################################################################
|
||||
# hosts / scripts / hosts-completion
|
||||
#
|
||||
# Install and uninstall completions for `hosts`.
|
||||
#
|
||||
# https://github.com/xwmx/hosts
|
||||
###############################################################################
|
||||
|
||||
###############################################################################
|
||||
# Strict Mode
|
||||
#
|
||||
# More Information:
|
||||
# https://github.com/xwmx/bash-boilerplate#bash-strict-mode
|
||||
###############################################################################
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
set -o errtrace
|
||||
set -o pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
###############################################################################
|
||||
|
||||
export _MY_DIR=
|
||||
_MY_DIR="$(cd "$(dirname "$0")"; pwd)"
|
||||
if [[ -z "${_MY_DIR}" ]] || [[ ! -d "${_MY_DIR}" ]]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Usage: _get_bash_completion_path
|
||||
_get_bash_completion_path() {
|
||||
local _bash_completion_path=
|
||||
|
||||
if [[ -n "${BASH_COMPLETION_COMPAT_DIR:-}" ]] &&
|
||||
[[ -w "${BASH_COMPLETION_COMPAT_DIR:-}" ]]
|
||||
then
|
||||
_bash_completion_path="${BASH_COMPLETION_COMPAT_DIR}"
|
||||
fi
|
||||
|
||||
if [[ -z "${_bash_completion_path:-}" ]]
|
||||
then
|
||||
local _maybe_path
|
||||
_maybe_path="$(
|
||||
pkg-config --variable=completionsdir bash-completion 2>/dev/null || true
|
||||
)"
|
||||
|
||||
if [[ -n "${_maybe_path:-}" ]] &&
|
||||
[[ -w "${_maybe_path:-}" ]]
|
||||
then
|
||||
_bash_completion_path="${_maybe_path}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${_bash_completion_path:-}" ]] &&
|
||||
[[ -d "/usr/local/etc/bash_completion.d" ]] &&
|
||||
[[ -w "/usr/local/etc/bash_completion.d" ]]
|
||||
then
|
||||
_bash_completion_path="/usr/local/etc/bash_completion.d"
|
||||
fi
|
||||
|
||||
if [[ -z "${_bash_completion_path:-}" ]] &&
|
||||
[[ -d "/etc/bash_completion.d" ]] &&
|
||||
[[ -w "/etc/bash_completion.d" ]]
|
||||
then
|
||||
_bash_completion_path="/etc/bash_completion.d"
|
||||
fi
|
||||
|
||||
printf "%s\\n" "${_bash_completion_path:-}"
|
||||
}
|
||||
|
||||
# subcommands ################################################### subcommands #
|
||||
|
||||
# Usage: _check
|
||||
_check() {
|
||||
local _bash_completion_path=
|
||||
_bash_completion_path="$(_get_bash_completion_path)"
|
||||
|
||||
local _exists=0
|
||||
|
||||
if [[ -n "${_bash_completion_path:-}" ]] &&
|
||||
[[ -d "${_bash_completion_path}" ]] &&
|
||||
[[ -w "${_bash_completion_path}" ]] &&
|
||||
[[ -e "${_bash_completion_path}/hosts" ]]
|
||||
then
|
||||
_exists=1
|
||||
printf "Exists: %s\\n" "${_bash_completion_path}/hosts"
|
||||
fi
|
||||
|
||||
local _zsh_completion_path="/usr/local/share/zsh/site-functions"
|
||||
|
||||
if [[ -d "${_zsh_completion_path}" ]] &&
|
||||
[[ -w "${_zsh_completion_path}" ]] &&
|
||||
[[ -e "${_zsh_completion_path}/_hosts" ]]
|
||||
then
|
||||
_exists=1
|
||||
printf "Exists: %s\\n" "${_zsh_completion_path}/_hosts"
|
||||
fi
|
||||
|
||||
((_exists)) || return 1
|
||||
}
|
||||
|
||||
# Usage: _install
|
||||
_install() {
|
||||
local _bash_completion_path=
|
||||
_bash_completion_path="$(_get_bash_completion_path)"
|
||||
|
||||
if [[ -n "${_bash_completion_path:-}" ]] &&
|
||||
[[ -d "${_bash_completion_path}" ]] &&
|
||||
[[ -w "${_bash_completion_path}" ]] &&
|
||||
[[ ! -e "${_bash_completion_path}/hosts" ]]
|
||||
then
|
||||
cp \
|
||||
"${_MY_DIR}/../etc/hosts-completion.bash" \
|
||||
"${_bash_completion_path}/hosts"
|
||||
printf "Completion installed: %s\\n" "${_bash_completion_path}/hosts"
|
||||
|
||||
# Cleanup old completion script.
|
||||
if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]]
|
||||
then
|
||||
rm "${_bash_completion_path}/hosts-completion.bash"
|
||||
fi
|
||||
fi
|
||||
|
||||
local _zsh_completion_path="/usr/local/share/zsh/site-functions"
|
||||
|
||||
if [[ -d "${_zsh_completion_path}" ]] &&
|
||||
[[ -w "${_zsh_completion_path}" ]] &&
|
||||
[[ ! -e "${_zsh_completion_path}/_hosts" ]]
|
||||
then
|
||||
cp \
|
||||
"${_MY_DIR}/../etc/hosts-completion.zsh" \
|
||||
"${_zsh_completion_path}/_hosts"
|
||||
printf "Completion installed: %s\\n" "${_zsh_completion_path}/_hosts"
|
||||
fi
|
||||
}
|
||||
|
||||
# Usage: _uninstall
|
||||
_uninstall() {
|
||||
local _bash_completion_path=
|
||||
_bash_completion_path="$(_get_bash_completion_path)"
|
||||
|
||||
if [[ -n "${_bash_completion_path:-}" ]] &&
|
||||
[[ -d "${_bash_completion_path}" ]] &&
|
||||
[[ -w "${_bash_completion_path}" ]] &&
|
||||
[[ -e "${_bash_completion_path}/hosts" ]]
|
||||
then
|
||||
rm "${_bash_completion_path}/hosts"
|
||||
printf "Completion removed: %s\\n" "${_bash_completion_path}/hosts"
|
||||
|
||||
# Cleanup old completion script.
|
||||
if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]]
|
||||
then
|
||||
rm "${_bash_completion_path}/hosts-completion.bash"
|
||||
fi
|
||||
fi
|
||||
|
||||
local _zsh_completion_path="/usr/local/share/zsh/site-functions"
|
||||
|
||||
if [[ -d "${_zsh_completion_path}" ]] &&
|
||||
[[ -w "${_zsh_completion_path}" ]] &&
|
||||
[[ -e "${_zsh_completion_path}/_hosts" ]]
|
||||
then
|
||||
rm "${_zsh_completion_path}/_hosts"
|
||||
printf "Completion removed: %s\\n" "${_zsh_completion_path}/_hosts"
|
||||
fi
|
||||
}
|
||||
|
||||
# main ################################################################# main #
|
||||
|
||||
# Usage: _main <args>...
|
||||
_main() {
|
||||
_subcommand="${1:-}"
|
||||
|
||||
case "${_subcommand}" in
|
||||
check)
|
||||
_check
|
||||
;;
|
||||
install)
|
||||
_install
|
||||
;;
|
||||
uninstall)
|
||||
_uninstall
|
||||
;;
|
||||
*)
|
||||
cat <<HEREDOC
|
||||
hosts-completion
|
||||
|
||||
Usage:
|
||||
hosts-completion [check | install | uninstall]
|
||||
|
||||
Description:
|
||||
Manage completion scripts for \`hosts\`.
|
||||
HEREDOC
|
||||
;;
|
||||
esac
|
||||
} && _main "$@"
|
||||
|
|
@ -85,7 +85,7 @@ No backups found. Create a new backup:
|
|||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
}
|
||||
|
||||
run "${_HOSTS}" backups compare "${_backup_basename}" --diff
|
||||
run "${_HOSTS}" backups compare "${_backup_basename}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
printf "\${lines[1]}: '%s'\\n" "${lines[1]}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
|
@ -100,7 +100,7 @@ No backups found. Create a new backup:
|
|||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
}
|
||||
|
||||
run "${_HOSTS}" backups compare --diff
|
||||
run "${_HOSTS}" backups compare
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
|
@ -115,7 +115,7 @@ No backups found. Create a new backup:
|
|||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
}
|
||||
|
||||
run "${_HOSTS}" backups compare "invalid-backup-name" --diff
|
||||
run "${_HOSTS}" backups compare "invalid-backup-name"
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
|
@ -128,6 +128,7 @@ No backups found. Create a new backup:
|
|||
{
|
||||
run "${_HOSTS}" backups create
|
||||
_backup_path="$(echo "${output}" | sed -e 's/Backed up to \(.*\)/\1/')"
|
||||
[[ -e "${_backup_path}" ]]
|
||||
_backup_basename="$(basename "${_backup_path}")"
|
||||
}
|
||||
|
||||
|
@ -230,6 +231,7 @@ No backups found. Create a new backup:
|
|||
{
|
||||
run "${_HOSTS}" backups create
|
||||
_backup_path="$(echo "${output}" | sed -e 's/Backed up to \(.*\)/\1/')"
|
||||
[[ -e "${_backup_path:-}" ]]
|
||||
_backup_basename="$(basename "${_backup_path}")"
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts block` #################################################################
|
||||
# `hosts block` ###############################################################
|
||||
|
||||
@test "\`block\` with no arguments exits with status 1." {
|
||||
run "${_HOSTS}" block
|
||||
|
@ -28,7 +28,7 @@ load test_helper
|
|||
[[ "${lines[1]}" == " hosts block <hostname>..." ]]
|
||||
}
|
||||
|
||||
# `hosts block <hostname>` #################################################
|
||||
# `hosts block <hostname>` ####################################################
|
||||
|
||||
@test "\`block <hostname>\` exits with status 0." {
|
||||
run "${_HOSTS}" block example.com
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts disabled` #############################################################
|
||||
# `hosts disabled` ############################################################
|
||||
|
||||
@test "\`disabled\` with no arguments exits with status 0." {
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ load test_helper
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`disabled\` with no arguments prints list of disabled records." {
|
||||
@test "\`disabled\` with no arguments prints list of disabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -34,6 +34,13 @@ load test_helper
|
|||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`disabled\` exits with status 1 when no matching entries found." {
|
||||
run "${_HOSTS}" disabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# help ########################################################################
|
||||
|
||||
@test "\`help disabled\` exits with status 0." {
|
||||
|
|
|
@ -18,7 +18,7 @@ load test_helper
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`enabled\` with no arguments prints list of enabled records." {
|
||||
@test "\`enabled\` with no arguments prints list of enabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -36,6 +36,18 @@ load test_helper
|
|||
[[ "${lines[4]}" =~ 127.0.0.2[[:space:]]+example.com ]]
|
||||
}
|
||||
|
||||
@test "\`enabled\` exits with status 1 when no matching entries found." {
|
||||
{
|
||||
run "${_HOSTS}" disable localhost
|
||||
run "${_HOSTS}" disable broadcasthost
|
||||
}
|
||||
|
||||
run "${_HOSTS}" enabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# help ########################################################################
|
||||
|
||||
@test "\`help enabled\` exits with status 0." {
|
||||
|
|
|
@ -10,9 +10,9 @@ load test_helper
|
|||
@test "\`hosts\` with no arguments prints enabled rules." {
|
||||
run "${_HOSTS}"
|
||||
[[ "${#lines[@]}" -eq 4 ]]
|
||||
[[ "${lines[0]}" =~ 127.0.0.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[1]}" =~ 255.255.255.255[[:space:]]+broadcasthost ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[0]}" =~ 127.0.0.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[1]}" =~ 255.255.255.255[[:space:]]+broadcasthost ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[4]}" == "" ]]
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts list` #############################################################
|
||||
# `hosts list` ################################################################
|
||||
|
||||
@test "\`list\` exits with status 0." {
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ load test_helper
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`list\` prints lists of enabled and disabled records." {
|
||||
@test "\`list\` prints lists of enabled and disabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -60,7 +60,7 @@ Disabled:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`list enabled\` prints list of enabled records." {
|
||||
@test "\`list enabled\` prints list of enabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -71,11 +71,23 @@ Disabled:
|
|||
run "${_HOSTS}" list enabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 127\.0\.0\.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[0]}" =~ 127\.0\.0\.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[1]}" =~ 255\.255\.255\.255[[:space:]]+broadcasthost ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[4]}" =~ 127\.0\.0\.2[[:space:]]+example.com ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[4]}" =~ 127\.0\.0\.2[[:space:]]+example.com ]]
|
||||
}
|
||||
|
||||
@test "\`list enabled\` exits with status 1 when no matching entries found." {
|
||||
{
|
||||
run "${_HOSTS}" disable localhost
|
||||
run "${_HOSTS}" disable broadcasthost
|
||||
}
|
||||
|
||||
run "${_HOSTS}" list enabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# `hosts list disabled` #######################################################
|
||||
|
@ -94,7 +106,7 @@ Disabled:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`list disabled\` prints list of disabled records." {
|
||||
@test "\`list disabled\` prints list of disabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -110,6 +122,13 @@ Disabled:
|
|||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`list disabled\` exits with status 1 when no matching entries found." {
|
||||
run "${_HOSTS}" list disabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# `hosts list <search string>` ################################################
|
||||
|
||||
@test "\`list <search string>\` exits with status 0." {
|
||||
|
@ -125,7 +144,7 @@ Disabled:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`list <search string>\` prints list of matching records." {
|
||||
@test "\`list <search string>\` prints list of matching entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -140,7 +159,7 @@ Disabled:
|
|||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`list <search string>\` prints records with matching comments." {
|
||||
@test "\`list <search string>\` prints entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -155,7 +174,7 @@ Disabled:
|
|||
}
|
||||
|
||||
|
||||
@test "\`list <search string>\` prints disabled records with matching comments." {
|
||||
@test "\`list <search string>\` prints disabled entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -172,6 +191,13 @@ Disabled:
|
|||
[[ "${lines[4]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`list <search string>\` exits with status 1 when no matching entries found." {
|
||||
run "${_HOSTS}" list query-that-matches-no-entries
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# help ########################################################################
|
||||
|
||||
@test "\`help list\` exits with status 0." {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts remove` #################################################################
|
||||
# `hosts remove` ##############################################################
|
||||
|
||||
@test "\`remove\` with no arguments exits with status 1." {
|
||||
run "${_HOSTS}" remove
|
||||
|
@ -53,7 +53,7 @@ load test_helper
|
|||
run "${_HOSTS}" remove 127.0.0.3 --force
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${output} == "No matching records found." ]]
|
||||
[[ ${output} == "${_ERROR_PREFIX}No matching entries found." ]]
|
||||
}
|
||||
|
||||
# `hosts remove <ip> --force` #################################################
|
||||
|
@ -83,9 +83,9 @@ load test_helper
|
|||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
_compare "${_original}" "$(cat "${HOSTS_PATH}")"
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]]
|
||||
[[ "$(sed -n '13p' "${HOSTS_PATH}")" == "" ]]
|
||||
[[ "$(sed -n '11p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "$(sed -n '12p' "${HOSTS_PATH}")" =~ 0.0.0.0[[:space:]]+example.net ]]
|
||||
[[ "$(sed -n '13p' "${HOSTS_PATH}")" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`remove <ip>\` removes all matches." {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts search` #############################################################
|
||||
# `hosts search` ##############################################################
|
||||
|
||||
@test "\`search\` with no arguments exits with status 1." {
|
||||
{
|
||||
|
@ -29,14 +29,8 @@ load test_helper
|
|||
run "${_HOSTS}" search
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
_expected="\
|
||||
Usage:
|
||||
hosts search <search string>
|
||||
|
||||
Description:
|
||||
Search entries for <search string>."
|
||||
_compare "'${_expected}'" "'${output}'"
|
||||
[[ "${output}" == "${_expected}" ]]
|
||||
[[ "${lines[0]}" == "Usage:" ]]
|
||||
[[ "${lines[1]}" == " hosts search <search string>" ]]
|
||||
}
|
||||
|
||||
# `hosts search enabled` ######################################################
|
||||
|
@ -55,7 +49,7 @@ Description:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`search enabled\` prints list of enabled records." {
|
||||
@test "\`search enabled\` prints list of enabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -66,14 +60,26 @@ Description:
|
|||
run "${_HOSTS}" search enabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 127.0.0.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[1]}" =~ 255.255.255.255[[:space:]]+broadcasthost ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[4]}" =~ 127.0.0.2[[:space:]]+example.com ]]
|
||||
[[ "${lines[0]}" =~ 127.0.0.1[[:space:]]+localhost ]]
|
||||
[[ "${lines[1]}" =~ 255.255.255.255[[:space:]]+broadcasthost ]]
|
||||
[[ "${lines[2]}" =~ \:\:1[[:space:]]+localhost ]]
|
||||
[[ "${lines[3]}" =~ fe80\:\:1\%lo0[[:space:]]+localhost ]]
|
||||
[[ "${lines[4]}" =~ 127.0.0.2[[:space:]]+example.com ]]
|
||||
}
|
||||
|
||||
# `hosts search disabled` #######################################################
|
||||
@test "\`search enabled\` exits with status 1 when no matching entries found." {
|
||||
{
|
||||
run "${_HOSTS}" disable localhost
|
||||
run "${_HOSTS}" disable broadcasthost
|
||||
}
|
||||
|
||||
run "${_HOSTS}" search enabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# `hosts search disabled` #####################################################
|
||||
|
||||
@test "\`search disabled\` exits with status 0." {
|
||||
{
|
||||
|
@ -89,7 +95,7 @@ Description:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`search disabled\` prints list of disabled records." {
|
||||
@test "\`search disabled\` prints list of disabled entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -100,11 +106,18 @@ Description:
|
|||
run "${_HOSTS}" search disabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]]
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]]
|
||||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`search disabled\` exits with status 1 when no matching entries found." {
|
||||
run "${_HOSTS}" search disabled
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# `hosts search <search string>` ################################################
|
||||
|
||||
@test "\`search <search string>\` exits with status 0." {
|
||||
|
@ -120,7 +133,7 @@ Description:
|
|||
[[ ${status} -eq 0 ]]
|
||||
}
|
||||
|
||||
@test "\`search <search string>\` prints list of matching records." {
|
||||
@test "\`search <search string>\` prints list of matching entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -130,12 +143,12 @@ Description:
|
|||
run "${_HOSTS}" search example.com
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]]
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[1]}" =~ 127.0.0.1[[:space:]]+example.com ]]
|
||||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`search <search string>\` prints records with matching comments." {
|
||||
@test "\`search <search string>\` prints entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -149,7 +162,7 @@ Description:
|
|||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`search <search string>\` prints disabled records with matching comments." {
|
||||
@test "\`search <search string>\` prints disabled entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -161,11 +174,18 @@ Description:
|
|||
run "${_HOSTS}" search "Comment"
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.net[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[3]}" =~ 127.0.0.1[[:space:]]+example.biz[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[0]}" =~ 0.0.0.0[[:space:]]+example.net[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[3]}" =~ 127.0.0.1[[:space:]]+example.biz[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[4]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`search <search string>\` exits with status 1 when no matching entries found." {
|
||||
run "${_HOSTS}" search query-that-matches-no-entries
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 1 ]]
|
||||
}
|
||||
|
||||
# help ########################################################################
|
||||
|
||||
@test "\`help search\` exits with status 0." {
|
||||
|
@ -177,6 +197,6 @@ Description:
|
|||
run "${_HOSTS}" help search
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" == "Usage:" ]]
|
||||
[[ "${lines[1]}" == " hosts search <search string>" ]]
|
||||
[[ "${lines[0]}" == "Usage:" ]]
|
||||
[[ "${lines[1]}" == " hosts search <search string>" ]]
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts show` ##############################################################
|
||||
# `hosts show` ################################################################
|
||||
|
||||
@test "\`show\` with no arguments exits with status 1." {
|
||||
run "${_HOSTS}" show
|
||||
|
@ -21,7 +21,7 @@ load test_helper
|
|||
|
||||
# `hosts show <no matching>` ##################################################
|
||||
|
||||
@test "\`show <query>\` with no matching records with status 1." {
|
||||
@test "\`show <query>\` with no matching entries with status 1." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -37,7 +37,7 @@ load test_helper
|
|||
[[ "${lines[0]}" =~ No\ matching\ entries ]]
|
||||
}
|
||||
|
||||
# `hosts show <ip>` #########################################################
|
||||
# `hosts show <ip>` ###########################################################
|
||||
|
||||
@test "\`show <ip>\` exits with status 0 and shows all matches." {
|
||||
{
|
||||
|
@ -72,12 +72,12 @@ load test_helper
|
|||
[[ ${status} -eq 0 ]]
|
||||
|
||||
[[ "${lines[0]}" =~ 127\.0\.0\.2[[:space:]]+example.com ]]
|
||||
[[ "${lines[3]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[3]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
||||
}
|
||||
|
||||
# `hosts show <search string>` ################################################
|
||||
|
||||
@test "\`show <search string>\` exits with status 0 and shows matching records." {
|
||||
@test "\`show <search string>\` exits with status 0 and shows matching entries." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net
|
||||
|
@ -89,12 +89,12 @@ load test_helper
|
|||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${status} -eq 0 ]]
|
||||
|
||||
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example.com ]]
|
||||
[[ "${lines[1]}" =~ 127\.0\.0\.1[[:space:]]+example.com ]]
|
||||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`show <search string>\` prints records with matching comments." {
|
||||
@test "\`show <search string>\` prints entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -109,7 +109,7 @@ load test_helper
|
|||
[[ "${lines[2]}" == "" ]]
|
||||
}
|
||||
|
||||
@test "\`show <search string>\` prints disabled records with matching comments." {
|
||||
@test "\`show <search string>\` prints disabled entries with matching comments." {
|
||||
{
|
||||
run "${_HOSTS}" add 0.0.0.0 example.com
|
||||
run "${_HOSTS}" add 0.0.0.0 example.net "Example Comment"
|
||||
|
@ -121,8 +121,8 @@ load test_helper
|
|||
run "${_HOSTS}" show "Comment"
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example\.net[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[3]}" =~ 127\.0\.0\.1[[:space:]]+example\.biz[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[0]}" =~ 0\.0\.0\.0[[:space:]]+example\.net[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[3]}" =~ 127\.0\.0\.1[[:space:]]+example\.biz[[:space:]]+\#\ Example\ Comment ]]
|
||||
[[ "${lines[4]}" == "" ]]
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ setup() {
|
|||
export _HOSTS_TEMP_PATH
|
||||
_HOSTS_TEMP_PATH="${_HOSTS_TEMP_DIR}/hosts"
|
||||
|
||||
export _ERROR_PREFIX
|
||||
_ERROR_PREFIX="$(tput setaf 1)!$(tput sgr0) "
|
||||
|
||||
cat "${BATS_TEST_DIRNAME}/fixtures/hosts" > "${_HOSTS_TEMP_PATH}"
|
||||
|
||||
export HOSTS_PATH="${_HOSTS_TEMP_PATH}"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
load test_helper
|
||||
|
||||
# `hosts unblock` #################################################################
|
||||
# `hosts unblock` #############################################################
|
||||
|
||||
@test "\`unblock\` with no arguments exits with status 1." {
|
||||
run "${_HOSTS}" unblock
|
||||
|
@ -28,7 +28,7 @@ load test_helper
|
|||
[[ "${lines[1]}" == " hosts unblock <hostname>..." ]]
|
||||
}
|
||||
|
||||
# `hosts unblock <invalid>` ############################################
|
||||
# `hosts unblock <invalid>` ###################################################
|
||||
|
||||
@test "\`unblock <invalid> \` exits with status 1." {
|
||||
{
|
||||
|
@ -49,10 +49,10 @@ load test_helper
|
|||
run "${_HOSTS}" unblock example.net
|
||||
printf "\${status}: %s\\n" "${status}"
|
||||
printf "\${output}: '%s'\\n" "${output}"
|
||||
[[ ${output} == "No matching records found." ]]
|
||||
[[ ${output} == "${_ERROR_PREFIX}No matching entries found." ]]
|
||||
}
|
||||
|
||||
# `hosts unblock <hostname>` ###########################################
|
||||
# `hosts unblock <hostname>` ##################################################
|
||||
|
||||
@test "\`unblock <hostname>\` exits with status 0." {
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue