# https://nix-community.github.io/home-manager/options.html
{ pkgs, config, ... }:
{
  home.packages = with pkgs; [
    sshuttle
  ];

  programs.bash.initExtra = ''
    function vpn (
    	ip="$(dig +short -x a $1 | tail -n 1)"
      set -x
      #sshuttle 0.0.0.0/0 --disable-ipv6 --dns -r "$1" -x $ip -x 127.0.0.1 -x 172.0.0.0/8
      sshuttle 0.0.0.0/0 ::/0 --dns -r "$1" -x $ip -x 127.0.0.1 -x 172.0.0.0/8
    )

    if test -f ~/.ssh/config; then
      complete -W "$(cat ~/.ssh/config | grep "^Host " | cut -d" " -f2- | grep -v '\*')" vpn
      complete -W "$(cat ~/.ssh/config | grep "^Host " | cut -d" " -f2- | grep -v '\*')" lvpn
      complete -W "$(cat ~/.ssh/config | grep "^Host " | cut -d" " -f2- | grep -v '\*')" dvpn
    fi
  '';
}
