*nix tips & tricks

PUBLISHED ON MARCH 22, 2017 — *NIX, GIT

Rsync using .gitignore

rsync -aPh --delete --filter=":- .gitignore" ./ dest/

Git: apply .gitignore file to committed files

git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached

Git: find the parent branch of the current branch

parent_git_branch() {
	current_branch=$(git rev-parse --abbrev-ref HEAD)
	git show-branch -a 2>/dev/null | ack '\*' | ack -v "$current_branch" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'
}

Convert an SSL certificate from DER format to PEM format

der2pem() {
	TMPFILE="/tmp/cert"
	rm -f $TMPFILE
	openssl x509 -inform der -in "$1" -out $TMPFILE
	cat $TMPFILE
	rm -f $TMPFILE
}

Convert an SSL certificate from DER format to PEM format with escaped newlines

der2pemescaped() {
	TMPFILE="/tmp/cert"
	rm -f $TMPFILE
	openssl x509 -inform der -in "$1" -out $TMPFILE
	cat $TMPFILE | awk 1 ORS='\\n'
	rm -f $TMPFILE
}

Convert an SSL certificate from PEM format to DER format

pem2der() {
	openssl x509 -outform der -in "$1" -out "${1}.crt"
}

Test SSL connection to host

This is useful to inspect the SSL certificate chain sent by the server.

openssl_connect() {
	openssl s_client -showcerts -connect ${1}:443
}

SVN: add all new files and remove all missing files

svnaddall() {
	svn st | grep '^!' | awk -F'[[:space:]][[:space:]]+' '{print $2}' | xargs -I{} svn delete {}
	svn st | grep '^?' | awk -F'[[:space:]][[:space:]]+' '{print $2}' | xargs -I{} svn add {}
}