mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-22 04:45:11 +00:00
Add scripts, update README.md and package.json.
This commit is contained in:
parent
9cbc6ddafb
commit
8cbbdc3550
@ -2,16 +2,34 @@
|
|||||||
|
|
||||||
## Homebrew
|
## Homebrew
|
||||||
|
|
||||||
If you're using Homebrew, just run `brew install xwmx/taps/hosts` and the
|
Installing via Homebrew with `brew install xwmx/taps/hosts` will also
|
||||||
completion scripts will be installed automatically. The extra steps to install
|
install the completion scripts. The extra steps to install `hosts` completion
|
||||||
`hosts` completion scripts outlined below are *not needed*.
|
scripts outlined below are *not needed*.
|
||||||
|
|
||||||
A one-time setup might be needed to [enable completion for all Homebrew
|
A one-time setup might be needed to [enable completion for all Homebrew
|
||||||
programs](https://docs.brew.sh/Shell-Completion).
|
programs](https://docs.brew.sh/Shell-Completion).
|
||||||
|
|
||||||
## bash
|
## npm
|
||||||
|
|
||||||
### Linux
|
Installing via npm should install the completion scripts. If completion
|
||||||
|
isn't working, try the instructions below.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
`hosts` includes scripts for installing and uninstalling completions.
|
||||||
|
|
||||||
|
- [install-completion.bash](../scripts/install-completion.bash)
|
||||||
|
- [uninstall-completion.bash](../scripts/uninstall-completion.bash)
|
||||||
|
|
||||||
|
These scripts will try to determine the completion installation
|
||||||
|
locations from your environment. If completion doesn't work, you might
|
||||||
|
need to try installing manually.
|
||||||
|
|
||||||
|
## Manual Installation
|
||||||
|
|
||||||
|
### bash
|
||||||
|
|
||||||
|
#### Linux
|
||||||
|
|
||||||
On a current Linux OS (in a non-minimal installation), bash completion should
|
On a current Linux OS (in a non-minimal installation), bash completion should
|
||||||
be available.
|
be available.
|
||||||
@ -22,7 +40,7 @@ Place the completion script in `/etc/bash_completion.d/`:
|
|||||||
sudo curl -L https://raw.githubusercontent.com/xwmx/hosts/master/hosts-completion.bash -o /etc/bash_completion.d/hosts
|
sudo curl -L https://raw.githubusercontent.com/xwmx/hosts/master/hosts-completion.bash -o /etc/bash_completion.d/hosts
|
||||||
```
|
```
|
||||||
|
|
||||||
### macOS
|
#### macOS
|
||||||
|
|
||||||
If you aren't installing with homebrew, source the completion script in
|
If you aren't installing with homebrew, source the completion script in
|
||||||
`.bash_profile`:
|
`.bash_profile`:
|
||||||
@ -34,7 +52,7 @@ then
|
|||||||
fi
|
fi
|
||||||
```
|
```
|
||||||
|
|
||||||
## zsh
|
### zsh
|
||||||
|
|
||||||
Place the completion script in your `/path/to/zsh/completion` (typically
|
Place the completion script in your `/path/to/zsh/completion` (typically
|
||||||
`~/.zsh/completion/`):
|
`~/.zsh/completion/`):
|
||||||
@ -43,13 +61,13 @@ Place the completion script in your `/path/to/zsh/completion` (typically
|
|||||||
$ mkdir -p ~/.zsh/completion
|
$ mkdir -p ~/.zsh/completion
|
||||||
$ curl -L https://raw.githubusercontent.com/xwmx/hosts/master/hosts-completion.zsh > ~/.zsh/completion/_hosts
|
$ 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`:
|
Include the directory in your `$fpath` by adding in `~/.zshrc`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fpath=(~/.zsh/completion $fpath)
|
fpath=(~/.zsh/completion $fpath)
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure compinit is loaded or do it by adding in `~/.zshrc`:
|
Make sure `compinit` is loaded or do it by adding in `~/.zshrc`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
autoload -Uz compinit && compinit -i
|
autoload -Uz compinit && compinit -i
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bats test"
|
"test": "bats test",
|
||||||
|
"postinstall": "scripts/install-completion.bash",
|
||||||
|
"preuninstall": "scripts/uninstall-completion.bash"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
45
scripts/get-bash-completion-path.bash
Executable file
45
scripts/get-bash-completion-path.bash
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
###############################################################################
|
||||||
|
# uninstall.bash
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Strict Mode
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
|
||||||
|
set -o errtrace
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
_get_bash_completion_path() {
|
||||||
|
local _bash_completion_path=
|
||||||
|
|
||||||
|
if [[ -n "${BASH_COMPLETION_COMPAT_DIR:-}" ]]
|
||||||
|
then
|
||||||
|
_bash_completion_path="${BASH_COMPLETION_COMPAT_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${_bash_completion_path:-}" ]]
|
||||||
|
then
|
||||||
|
_bash_completion_path="$(
|
||||||
|
pkg-config --variable=completionsdir bash-completion 2>/dev/null || true
|
||||||
|
)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${_bash_completion_path:-}" ]] &&
|
||||||
|
[[ -d "/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" ]]
|
||||||
|
then
|
||||||
|
_bash_completion_path="/etc/bash_completion.d"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\\n" "${_bash_completion_path:-}"
|
||||||
|
} && _get_bash_completion_path
|
42
scripts/install-completion.bash
Executable file
42
scripts/install-completion.bash
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
###############################################################################
|
||||||
|
# install-completion.bash
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
|
||||||
|
set -o errtrace
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
_MY_DIR="$(cd "$(dirname "$0")"; pwd)"
|
||||||
|
if [[ -z "${_MY_DIR}" ]] && [[ ! -d "${_MY_DIR}" ]]
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
_install_completion() {
|
||||||
|
local _bash_completion_path=
|
||||||
|
_bash_completion_path="$("${_MY_DIR}/get-bash-completion-path.bash")"
|
||||||
|
|
||||||
|
if [[ -n "${_bash_completion_path:-}" ]] &&
|
||||||
|
[[ -d "${_bash_completion_path}" ]] &&
|
||||||
|
[[ ! -e "${_bash_completion_path}/notes-completion.bash" ]]
|
||||||
|
then
|
||||||
|
cp \
|
||||||
|
"${_MY_DIR}/../etc/notes-completion.bash" \
|
||||||
|
"${_bash_completion_path}/notes-completion.bash"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local _zsh_completion_path="/usr/local/share/zsh/site-functions"
|
||||||
|
|
||||||
|
if [[ -d "${_zsh_completion_path}" ]] &&
|
||||||
|
[[ ! -e "${_zsh_completion_path}/_notes" ]]
|
||||||
|
then
|
||||||
|
cp \
|
||||||
|
"${_MY_DIR}/../etc/notes-completion.zsh" \
|
||||||
|
"${_zsh_completion_path}/_notes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
} && _install_completion "$@"
|
38
scripts/uninstall-completion.bash
Executable file
38
scripts/uninstall-completion.bash
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
###############################################################################
|
||||||
|
# uninstall-completion.bash
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
|
||||||
|
set -o errtrace
|
||||||
|
set -o pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
_MY_DIR="$(cd "$(dirname "$0")"; pwd)"
|
||||||
|
if [[ -z "${_MY_DIR}" ]] && [[ ! -d "${_MY_DIR}" ]]
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
_uninstall_completion() {
|
||||||
|
local _bash_completion_path=
|
||||||
|
_bash_completion_path="$("${_MY_DIR}/get-bash-completion-path.bash")"
|
||||||
|
|
||||||
|
if [[ -n "${_bash_completion_path:-}" ]] &&
|
||||||
|
[[ -d "${_bash_completion_path}" ]] &&
|
||||||
|
[[ -e "${_bash_completion_path}/notes-completion.bash" ]]
|
||||||
|
then
|
||||||
|
rm "${_bash_completion_path}/notes-completion.bash"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local _zsh_completion_path="/usr/local/share/zsh/site-functions"
|
||||||
|
|
||||||
|
if [[ -d "${_zsh_completion_path}" ]] &&
|
||||||
|
[[ -e "${_zsh_completion_path}/_notes" ]]
|
||||||
|
then
|
||||||
|
rm "${_zsh_completion_path}/_notes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
} && _uninstall_completion "$@"
|
Loading…
Reference in New Issue
Block a user