Skip to content

Instantly share code, notes, and snippets.

@wlkns
Created September 20, 2024 12:14
Show Gist options
  • Save wlkns/a423ad1b96b9093e8f130ce7b70c7feb to your computer and use it in GitHub Desktop.
Save wlkns/a423ad1b96b9093e8f130ce7b70c7feb to your computer and use it in GitHub Desktop.
Random string / password generator bash / zsh / sh script / alias.
RANDOM STRING 32 d6fBSJDVpQNymaMhgjWXMo0@bTS!9TxJ
Copied to clipboard.
# Add to your .bashrc / .zshrc to have a global command line alias.
# Add to a script.sh and remove the first and last line to use as a runnable script.
random_string() {
local length=${1:-"16"}
local random_str=$(cat /dev/urandom | LC_ALL=C tr -dc "A-Za-z0-9~_-.@!=:" | head -c $length)
echo "\n\033[43m\033[97m RANDOM STRING \033[103m\033[90m ${length} \033[0m ${random_str}"
$(echo -n "$random_str" | pbcopy)
echo "\n\033[92mCopied to clipboard.\033[0m"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment