Skip to content
Permalink
Browse files

Merge pull request #140 from gmhabchi/localhost

Added localhost plugin
  • Loading branch information...
rgcr committed Jun 17, 2019
2 parents 742d42c + 10a951f commit 2845c347f52052d357f659223eb1e837e604312e
Showing with 67 additions and 0 deletions.
  1. +11 −0 Readme.md
  2. +3 −0 completion/bash/m
  3. +6 −0 completion/fish/m.fish
  4. +9 −0 completion/zsh/_m
  5. +38 −0 plugins/localhost
@@ -58,6 +58,7 @@ usage: m [OPTIONS] COMMAND [help]
hostname
info
itunes
localhost
lock
ntp
printer
@@ -297,6 +298,16 @@ usage: m [OPTIONS] COMMAND [help]
m itunes quit # Quit iTunes
```

#### Localhost:
```
usage: m localhost [ help ]
Examples:
m localhost ls # list current records in localhost
m localhost add 127.0.0.1 webpage.local # add a new host to the localhost file
m localhost remove webpage.local # remove a host from the localhost file
```

#### Lock:
```
usage: m lock [ help ]
@@ -64,6 +64,9 @@ _m_sub () {
itunes)
subcommands=(status play pause next prev mute unmute vol stop quit help)
;;
localhost)
subcommands=(ls add remove help)
;;
lock)
subcommands=(help)
;;
@@ -159,6 +159,12 @@ complete -f -c m -n '__fish_m_using_command itunes ' -a "stop" -d 'stop iTune'
complete -f -c m -n '__fish_m_using_command itunes ' -a "quit" -d 'quit iTunes'
complete -f -c m -n '__fish_m_using_command itunes ' -a "help" -d 'Show help'

complete -f -c m -n '__fish_m_needs_command' -a localhost -d 'Manage localhost file'
complete -f -c m -n '__fish_m_using_command localhost' -a "ls" -d 'list records from localhost file'
complete -f -c m -n '__fish_m_using_command localhost' -a "add" -d 'add record to localhost file'
complete -f -c m -n '__fish_m_using_command localhost' -a "remove" -d 'remove record from localhost file'
complete -f -c m -n '__fish_m_using_command localhost' -a "help" -d 'Show help'

complete -f -c m -n '__fish_m_needs_command' -a lock -d 'Lock session'
complete -f -c m -n '__fish_m_using_command lock' -a "help" -d 'Show help'

@@ -497,6 +497,14 @@ function _m_cmd {
"quit:quit iTunes" \
help
;;
localhost)
_m_solo \
$sub \
"ls:list localhost records" \
"add:add localhost record" \
"remove:remove localhost record" \
help
;;
network)
_m_network
;;
@@ -666,6 +674,7 @@ function _m {
"hostname:displays or set the computer's hostname"
"info:print macOS operating system version information"
"itunes:itunes command line control"
"localhost:manage localhost file"
"lock:lock session"
"network:manage interfaces and locations"
"nosleep:prevent sleeping"
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

spacing=" "

help(){
cat<<__EOF__
usage: m localhost [ help ]
Examples:
m localhost ls # list current records in localhost
m localhost add 127.0.0.1 webpage.local # add a new host to the localhost file
m localhost remove webpage.local # remove a host from the localhost file
__EOF__
}

case $1 in
help)
help
;;
ls)
sudo echo "IP $spacing DOMAIN" && cat /etc/hosts | grep -v "#" | grep -v "^$"
;;
add)
[ -z "$2" ] && [ -z "$3"] && help && exit 1
sudo echo "$2 $3" | sudo tee -a /etc/hosts
sudo m dns flush
;;
remove)
[ -z "$2" ] && help && exit 1
sudo sed -i "" "/$2/d" /etc/hosts
sudo m dns flush
;;
*)
help
;;
esac

# vim: ts=4 sw=4 softtabstop=4 expandtab

0 comments on commit 2845c34

Please sign in to comment.
You can’t perform that action at this time.