Skip to content

Instantly share code, notes, and snippets.

@tippfehlr
Last active February 25, 2024 15:40
Show Gist options
  • Save tippfehlr/843c2d11f356d37495670b5803b714f5 to your computer and use it in GitHub Desktop.
Save tippfehlr/843c2d11f356d37495670b5803b714f5 to your computer and use it in GitHub Desktop.
Think of a port 💭
# bash function to generate ports for projects
# use the first four non-zero digits from the sha256sum of the project’s name
# infer the name from the current directory if no argument is given
thinkofport() {
if [ "$#" -gt 0 ]; then
echo -n "$1" | sha256sum | grep -o '[1-9]' | head -n 4 | tr -d '\n'
else
basename "$(pwd)" | sha256sum | grep -o '[1-9]' | head -n 4 | tr -d '\n'
fi
}
# fish function to generate ports for projects
# use the first four non-zero digits from the sha256sum of the project’s name
# infer the name from the current directory if no argument is given
function thinkofport
if count $argv >/dev/null
echo $argv | sha256sum | grep -o '[1-9]' | head -n 4 | tr -d '\n'
else
basename (pwd) | sha256sum | grep -o '[1-9]' | head -n 4 | tr -d '\n'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment