Skip to content

Add a helper utility#2

Open
one-d-wide wants to merge 1 commit intomainfrom
cli-util
Open

Add a helper utility#2
one-d-wide wants to merge 1 commit intomainfrom
cli-util

Conversation

@one-d-wide
Copy link
Copy Markdown
Owner

Add small portable cli utility allowing to individually manipulate simple hosts.d entries. A quick interface showcase from the readme:

$ hosts.d -h # --help
A front-end to individually manipulate simple hosts.d entries

Usage: ./hosts.sh [OPERATION] [OPTIONS] [--] [ARGS]
Operations:
  -c, --create [HOST] [ADDR]
  -m, --move [SRC_HOST] [DST_HOST]
  -d, --delete [HOST]
  -r, --resolve [HOST]
  -l, --list [GLOB]
Options:
  -t, --target-dir <path> [default: '/etc/hosts.d']
  -p, --priority <priority>
  -f, --force
  -q, --quiet
      --resolver-script <script>
      --resolver <command> [default: 'dig']
      --resolver-arg <arg> [default: '+short']
      --resolver-erase-args
      --dry-run

$ hosts.d localhost 127.0.0.1 # -c, --create
Writing '127.0.0.1 localhost' to '/etc/hosts.d/localhost.conf'

$ hosts.d -l # --list
## From /etc/hosts.d/localhost.conf ##
127.0.0.1 localhost

$ hosts.d -m localhost local # --move
Writing '127.0.0.1 local' to '/etc/hosts.d/local.conf'
Deleting '/etc/hosts.d/localhost.conf'

$ hosts.d -m local -p 99 # --priority 99
Moving '/etc/hosts.d/local.conf' to '/etc/hosts.d/99-local.conf'

$ hosts.d -d local # --delete
Deleting '/etc/hosts.d/99-local.conf'

$ ./hosts.sh -r google.com # --resolve
Executing: 'dig' '+short' 'google.com'
Writing 'XX.XX.XX.XX google.com' to '/etc/hosts.d/google.com.conf'

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