Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created September 9, 2025 18:02
Show Gist options
  • Save nkhil/6242f4d51558861d98dfabf00fae933c to your computer and use it in GitHub Desktop.
Save nkhil/6242f4d51558861d98dfabf00fae933c to your computer and use it in GitHub Desktop.

Useful .zshrc helpers

uuid() {
  uuidgen | tr -d '\n' | pbcopy
}
rand() {
  # Define the set of characters to choose from
  charset="[:alnum:]"

  # Get the length parameter (default to 16)
  length=${1:-16}

  # Use /dev/urandom for randomness and LC_ALL=C to force ASCII encoding
  random_string=$(head /dev/urandom | LC_ALL=C tr -dc $charset | fold -w $length | head -n 1)

  # Return the random string
  echo $random_string
}
function killp()
{
  PORT="$1"
  kill $(lsof -t -i:$PORT)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment