Skip to content

Instantly share code, notes, and snippets.

@ChrisRenfrow
Last active December 13, 2023 22:21
Show Gist options
  • Save ChrisRenfrow/a973bd1f9c552ff1080247f059f747d4 to your computer and use it in GitHub Desktop.
Save ChrisRenfrow/a973bd1f9c552ff1080247f059f747d4 to your computer and use it in GitHub Desktop.
A simple-ish fish script for randomly selecting a new Mullvad relay from those available.
function mullmix
# Locally scoped function
function usage
echo "$_ - Randomly set a new mullvad relay from the list of available relays"
echo "Usage: $_ [-h|--help] [COUNTRY]"
echo " -h, --help: Display this message"
echo " COUNTRY: a two-letter country code, e.g. \"us\". If provided, $_ will only select relays from this country."
# Delete self to avoid potential conflicts
functions -e usage
end
set -l arg_count (count $argv)
switch $arg_count
case 0
# Default
set pattern "[a-z]{2}-[a-z]{3}-wg-[0-9]{3}"
case 1
switch $argv[1]
case '-h' '--help'
usage
return 0
# COUNTRY code provided
case '*'
set pattern "$argv[1]-[a-z]{3}-wg-[0-9]{3}"
end
case '*'
echo "Error: Unexpected extra arguments"
usage
return 1
end
# Select a hostname
set relay_hostnames (mullvad relay list | grep -Po "$pattern")
# Set new relay
mullvad relay set location (random choice $relay_hostnames)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment