3 ms·
Here's a few functions / aliases I have set up that I use on a pretty regular basis: # Generate a random password and copy it to the clipboard. pw () {
by nickjj 6y ago
Here's a few functions / aliases I have set up that I use on a pretty regular basis:
# Generate a random password and copy it to the clipboard.
pw () {
pwgen -sync "${1:-48}" -1 | xclip
}
# Get the current weather.
weather () {
curl https://wttr.in/"${1}"
}
# Get the numeric value of a file / directory's permissions.
alias octal="stat -c '%a %n'"
All of my aliases are listed in my dotfiles at: https://github.com/nickjj/dotfiles/blob/master/.aliases https://github.com/nickjj/dotfiles/blob/master/.aliases
- gav 6y agoMy version of `pw', might be useful to those without `pwgen': function genpasswd() { openssl rand 150 | LC_CTYPE=C tr -dc '[[:alnum:]!@#$%^&]' | tr -d iIlLOo0 | cut -c 1-${1:-12}; }
- nickjj 6y agoOh yeah I forgot to mention in the alias comment that it depends on pwgen. Thanks for the reminder, I just updated it. I made a whole video on generating random password from the command line and compared a few options (including using openssl) at: https://nickjanetakis.com/blog/generate-a-random-secure-password-on-the-command-line-with-pwgen https://nickjanetakis.com/blog/generate-a-random-secure-pass... The TL;DR for not using openssl is that you're not going to get the same amount of characters every time. For example if you run yours with 48 characters instead of 12 it won't generate 48 characters every time you run it. With pwgen (something you can apt or brew install) you know what you're getting every time.
- gav 6y agoIf you change `openssl rand 150` to a bigger number, say 1000 or so, you can generate longer passwords.
- nickjj 6y agoAh, I see. Did you test your solution on macOS btw? I know macOS uses an ancient version of Bash and has different binaries that act differently vs Linux (such as sed). I don't have a Mac here but I do try to make my dotfiles compatible with it. If your solution works on macOS it would be nice to drop the pwgen dependency.
- gav 6y agoI use it on macOS and it works fine. There is a brew recipe for pwgen, but that's one more dependency to worry about.