Skip to content

Instantly share code, notes, and snippets.

@taikedz
Created May 4, 2018 13:33
Show Gist options
  • Save taikedz/1ec81daed066433dbfce94aa2162437f to your computer and use it in GitHub Desktop.
Save taikedz/1ec81daed066433dbfce94aa2162437f to your computer and use it in GitHub Desktop.
View a java keystore contents with some colorization for easier reading.
#!/bin/bash
main() {
if [[ -z "$*" ]] || [[ "$*" =~ --help ]]; then
echo "Provide the path to a keystore to colorize its output"
else
keystore="$1"
dump_keystore | colorize_keystore_stream | c_less
fi
}
cred="$(echo -e "\033[31;1m")"
cgrn="$(echo -e "\033[32;1m")"
cyel="$(echo -e "\033[33;1m")"
cdef="$(echo -e "\033[0m")"
c_less() {
/bin/less -R
}
dump_keystore() {
keytool -list -v -keystore "$keystore"
}
colorize_keystore_stream() {
# The order of the steps is important
sed -r "
s/^Alias name:/${cred}Alias name:${cdef}/
s/^([a-zA-Z0-9 -]+:)/${cgrn}\1${cdef}/
s/^(#[0-9]:)/${cyel}\1${cdef}/
"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment