Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active March 3, 2016 17:27
Show Gist options
  • Save trepmal/f7f067a526a74b67c5ea to your computer and use it in GitHub Desktop.
Save trepmal/f7f067a526a74b67c5ea to your computer and use it in GitHub Desktop.
bash function for zipping with password
# goes in my .bash_profile so I can quickly zip files/directories with encryption
# (remove or replace `pbcopy/pbpaste` as needed for your system)
# > pzip [file/directory]
function pzip {
head -n5 /dev/urandom | shasum | awk '{print $1}' | tr -d '\n' | pbcopy
output=${1%/} #trim trailing slash
output=${output%.*} #trim file extension
echo -e "Making \033[32m$output.zip\033[0m from $1"
zip -qrP "$(pbpaste)" $output $1;
echo -e "Archive password: \033[34m$(pbpaste)\033[0m"
echo "Password copied to clipboard"
}
# alternatively, this version will prompt you for a password
#
# > ezip [file/directory]
function ezip {
output=${1%/}
output=${output%.*}
echo -e "Making \033[32m$output.zip\033[0m from $1"
zip -qre $output $1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment