2017-09-11 14:23:28 +01:00
|
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
|
|
|
|
|
# Generate TLS certs using a local CA
|
|
|
|
|
gencert () {
|
|
|
|
|
DOMAIN=$1
|
|
|
|
|
|
|
|
|
|
test -d /usr/local/opt/openssl@1.1/bin && PATH='/usr/local/opt/openssl@1.1/bin':$PATH
|
2021-08-23 18:57:56 +01:00
|
|
|
|
test -d /opt/homebrew/opt/openssl@1.1/bin && PATH='/opt/homebrew/opt/openssl@1.1/bin':$PATH
|
2017-09-11 14:23:28 +01:00
|
|
|
|
test -f /usr/local/etc/openssl@1.1/openssl.cnf && SSLCNF='/usr/local/etc/openssl@1.1/openssl.cnf'
|
2021-08-23 18:57:56 +01:00
|
|
|
|
test -f /opt/homebrew/etc/openssl@1.1/openssl.cnf && SSLCNF='/opt/homebrew/etc/openssl@1.1/openssl.cnf'
|
2017-09-11 14:23:28 +01:00
|
|
|
|
test -f /etc/ssl/openssl.cnf && SSLCNF='/etc/ssl/openssl.cnf'
|
|
|
|
|
|
2018-06-23 20:28:58 +01:00
|
|
|
|
cd $HOME/git/ca
|
2017-09-11 14:23:28 +01:00
|
|
|
|
[[ ! -d $DOMAIN ]] && mkdir $DOMAIN
|
|
|
|
|
cd $DOMAIN
|
|
|
|
|
[[ -f key ]] && mv key key.bak
|
|
|
|
|
[[ -f csr ]] && mv csr csr.bak
|
|
|
|
|
[[ -f crt ]] && mv crt crt.bak
|
|
|
|
|
|
|
|
|
|
openssl ecparam -name secp384r1 -genkey -noout -out key
|
|
|
|
|
chmod 644 key
|
2020-11-16 17:39:32 +00:00
|
|
|
|
openssl req -new -sha256 -key key -subj "/C=UK/ST=England/L=Bury/O=JMB Dev Ltd/CN=$DOMAIN" -reqexts SAN -config <(cat $SSLCNF <(printf "[SAN]\nsubjectAltName=DNS:$DOMAIN")) -out csr
|
2017-09-11 14:23:28 +01:00
|
|
|
|
openssl x509 -req -in csr -extfile <(cat $SSLCNF <(printf "[SAN]\nsubjectAltName=DNS:$DOMAIN")) -extensions SAN -CA ../jmb-ca-ecc.pem -CAkey ../jmb-ca-ecc.key -CAcreateserial -days 90 -sha256 -out crt
|
|
|
|
|
|
2018-06-23 20:28:58 +01:00
|
|
|
|
cd $HOME/git/ca
|
2017-09-11 14:23:28 +01:00
|
|
|
|
echo 'Certs generated for $DOMAIN'
|
2018-06-23 20:23:05 +01:00
|
|
|
|
}
|
2019-08-23 12:18:49 +01:00
|
|
|
|
|
|
|
|
|
# Generate a random 7 digit number, used for CCL’s ImKeys
|
|
|
|
|
imkey () {
|
|
|
|
|
imkey=$(shuf -i 1111111-9999999 -n1)
|
|
|
|
|
|
|
|
|
|
echo $imkey
|
|
|
|
|
}
|
2021-07-17 18:07:14 +01:00
|
|
|
|
|
|
|
|
|
# Delete branches selected via fzf
|
|
|
|
|
delete-branches () {
|
|
|
|
|
git branch |
|
|
|
|
|
grep --invert-match '\*' | # Remove current branch
|
|
|
|
|
fzf --multi --preview="git log {..}" |
|
|
|
|
|
gxargs --no-run-if-empty git branch --delete
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Delete branches selected via fzf (force the deletion)
|
|
|
|
|
delete-branches-force () {
|
|
|
|
|
git branch |
|
|
|
|
|
grep --invert-match '\*' | # Remove current branch
|
|
|
|
|
fzf --multi --preview="git log {..}" |
|
|
|
|
|
gxargs --no-run-if-empty git branch --delete --force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Open a PR
|
|
|
|
|
function pr-checkout() {
|
|
|
|
|
local pr_number
|
|
|
|
|
|
|
|
|
|
pr_number=$(
|
|
|
|
|
gh api 'repos/:owner/:repo/pulls' --jq '.[] | "#\(.number) \(.title)"' |
|
|
|
|
|
fzf |
|
|
|
|
|
sd '^\#(\d+)\s.*' '$1'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if [ -n "$pr_number" ]; then
|
|
|
|
|
gh pr checkout "$pr_number"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function watch-file() {
|
|
|
|
|
tail -f $1 | bat --paging=never -l log
|
|
|
|
|
}
|