mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-20 03:13:33 +01:00
Add new plugin for virtual host management
This commit is contained in:
parent
ff4663a6b8
commit
39889dc2f2
3 changed files with 174 additions and 0 deletions
60
plugins/vhost/vhost.plugin.zsh
Normal file
60
plugins/vhost/vhost.plugin.zsh
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# frontend from terminal
|
||||
|
||||
function vhost() {
|
||||
|
||||
|
||||
local hosts_file
|
||||
hosts_file='/etc/hosts'
|
||||
|
||||
# no keyword provided, simply show how call methods
|
||||
if [[ "$#" -le 1 && $1 -ne "ls" ]]; then
|
||||
echo "Please provide a command with params.\nEx:\nvhost <command> <params>\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check whether the search engine is supported
|
||||
if [[ ! $1 =~ "(add|ls|rm)" ]];
|
||||
then
|
||||
echo "Option '$1' is not supported."
|
||||
echo "Usage: vhost <ip> <host>"
|
||||
echo "\t* add <ip> <host>"
|
||||
echo "\t* ls"
|
||||
echo "\t* rm <ip> <host>"
|
||||
echo ""
|
||||
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
"ls")
|
||||
cat $hosts_file
|
||||
;;
|
||||
"add")
|
||||
if [[ $# -le 2 ]]; then
|
||||
echo "This method should receive 2 params <ip> <host>"
|
||||
fi
|
||||
vhost="$2 $3"
|
||||
sudo echo "$vhost" >> $hosts_file
|
||||
echo "New virtual host '$3' created!"
|
||||
;;
|
||||
"rm")
|
||||
if [[ $# -le 2 ]]; then
|
||||
echo "This method should receive 2 params <ip> <host>"
|
||||
fi
|
||||
|
||||
sudo -v
|
||||
vhost="$2 $3"
|
||||
|
||||
echo -n " - Removing '$vhost' from $hosts_file... "
|
||||
cat $hosts_file | grep -v $vhost > /tmp/hosts.tmp
|
||||
if [[ -s /tmp/hosts.tmp ]]; then
|
||||
sudo mv /tmp/hosts.tmp $hosts_file
|
||||
fi
|
||||
echo "Virtual host '$3' removed!"
|
||||
;;
|
||||
*) echo "Command '$1' doesn't exist, sir."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue