Skip to content

Instantly share code, notes, and snippets.

@ketanshah79
Forked from nddrylliog/host-manager
Created May 1, 2016 17:56
Show Gist options
  • Save ketanshah79/be7f45e7924e016d1007ca377f0d26eb to your computer and use it in GitHub Desktop.
Save ketanshah79/be7f45e7924e016d1007ca377f0d26eb to your computer and use it in GitHub Desktop.

Revisions

  1. Amos Wenger revised this gist Nov 15, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion host-manager
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ remusage="Usage: `basename $0` -remove host"
    case "$1" in
    -add)
    if [ $# -eq 3 ]; then
    if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" hosts) ]]; then
    if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" ${path}) ]]; then
    echo "Duplicate address/host combination, ${path} unchanged."
    else
    printf "$3\t$2\n" >> ${path}
  2. Amos Wenger revised this gist Nov 15, 2011. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion host-manager
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,11 @@ remusage="Usage: `basename $0` -remove host"
    case "$1" in
    -add)
    if [ $# -eq 3 ]; then
    printf "$3\t$2\n" >> ${path}
    if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" hosts) ]]; then
    echo "Duplicate address/host combination, ${path} unchanged."
    else
    printf "$3\t$2\n" >> ${path}
    fi
    else
    echo $addusage;
    fi
  3. Amos Wenger revised this gist Nov 15, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion host-manager
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash
    # Idea and interface taken from https://github.com/macmade/host-manager

    path="hosts"
    path="/etc/hosts"
    addusage="Usage: `basename $0` -add host address"
    remusage="Usage: `basename $0` -remove host"
    case "$1" in
  4. Amos Wenger created this gist Nov 15, 2011.
    25 changes: 25 additions & 0 deletions host-manager
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash
    # Idea and interface taken from https://github.com/macmade/host-manager

    path="hosts"
    addusage="Usage: `basename $0` -add host address"
    remusage="Usage: `basename $0` -remove host"
    case "$1" in
    -add)
    if [ $# -eq 3 ]; then
    printf "$3\t$2\n" >> ${path}
    else
    echo $addusage;
    fi
    ;;
    -remove)
    if [ $# -eq 2 ]; then
    sed -i '' -e "s/^[^#].*[^A-Za-z0-9\.]$2$//g" -e "/^$/ d" ${path}
    else
    echo $remusage;
    fi
    ;;
    *)
    echo $addusage;
    echo $remusage;
    esac