dotfiles/dot_bashrc.d/executable_09.functions
2021-06-28 12:47:32 +02:00

56 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Bash Functions sourced by .bashrc / .sshrc
#
# Get SSL Certificate information
# Based on https://serverfault.com/questions/661978/displaying-a-remote-ssl-certificate-details-using-cli-tools
function getCertInfo() {
local myServer=${1:?a Servername is required}
local myPort=${2:-443}
echo | openssl s_client -showcerts -servername "$myServer" -connect "$myServer":"$myPort" 2>/dev/null | openssl x509 -inform pem -noout -text
}
#
# Some functions (some by c't magazine)
#
# change directory and list
cdl() {
if cd "$@"; then
ls
fi
}
backup() {
# local @files = "$@"
for f in "$@"
do
if [ -d "$f" ]; then
cp -p -r "$f" "$f".backup-"$(date +%Y-%m-%d_%H_%M_%S)"
else
cp -p "$f" "$f".backup-"$(date +%Y-%m-%d_%H_%M_%S)"
fi
done
}
extract() {
case $1 in
*.tar.bz2) tar xvjf "$1";;
*.tar.gz|*.tgz) tar xvfz "$1";;
*.zip) unzip "$1";;
*) echo "Not supported: $1";;
esac
}
# Misc functions
# convert epoch timestamp to human readable date
epoch2date() {
local string="${1:-0}"
date -d "@$string"
}
PATH=$PATH:$HOME/bin