User Tools

Site Tools


wiki:comment_uncomment_hosts_file_gnome_shell_panel

Comment/uncomment hosts file from gnome shell panel

Install argos

In .config/argos/hosts.10s.sh add this:

hosts.sh
#!/usr/bin/env bash
 
 
R="hosts"
echo "$R"
echo "---"
echo "host01 | iconName=help-faq-symbolic terminal=true bash='switch_host.sh 01'"
echo "host02 | iconName=help-faq-symbolic terminal=true bash='switch_host.sh 02'"
echo "host03 | iconName=help-faq-symbolic terminal=true bash='switch_host.sh 03'"
echo "RESET | iconName=help-faq-symbolic terminal=true bash='switch_host.sh reset'"
echo "---"
CURRENT=$(awk '/## DELIMITER/,/##\/DELIMITER/' /etc/hosts | grep -v '^$' | grep -B1 -v '^#')
echo "$CURRENT"

Add script .local/bin/ (substitute x.x.x.x with IPs in your hosts file):

switch_hosts.sh
#!/usr/bin/env bash
# Uncomment host in /etc/hosts file to hit it directly with browser.
# used by argos gnome extensions
# https://github.com/rammie/argos
 
if [ "$1" == "01" ];then
    sudo sed -i "/x.x.x.x/s/^#//g" /etc/hosts
elif [ "$1" == "02" ];then
    sudo sed -i "/x.x.x.x/s/^#//g" /etc/hosts
elif [ "$1" == "03" ];then
    sudo sed -i "/x.x.x.x/s/^#//g" /etc/hosts
elif [ "$1" == "reset" ];then
    sudo sed -i "/# DELIMITER/,/#\/DELIMITER/s/^\([^#].*\)/#\1/g" /etc/hosts
fi

Example /etc/hosts:

## DELIMITER
## live-host-01
#x.x.x.x www.domain.com

### live-host-02
#x.x.x.x www.domain.com

### live-host-03
#x.x.x.x www.domain.com
##/DELIMITER

Tested on

  • GNOME Shell 3.36.9

See also

References

wiki/comment_uncomment_hosts_file_gnome_shell_panel.txt · Last modified: 2023/05/31 15:14 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki