Skip to content

Automating gmail check in your shell

It you are just like me, who likes doing almost everything through the shell scripts rather than fancy UI apps, then here is a nice and easy way of checking a new emails in your gmail account:

function gmail(){
	emails=$(curl -s -u $1:$2 ""\
	 | egrep -o '<fullcount>[0-9]*' | cut -c 12-)
	if [ "$emails" -gt 0 ] ; then echo "You have ${emails} emails in your $1 account"; fi
gmail daenerys.targaryen $(vault read -field=value secret/GPASSWORD)
gmail simply.dany $(vault read -field=value secret/G2PASSWORD)

Simply add this to your .zshrc/.bashrc and you are done, next time you open a new tab you might get this:

Last login: Mon Feb  5 21:27:39 on ttys006
You have 1 emails in your daenerys.targaryen account
➜  ~ 

If you don’t bother with secutiry, just replace

$(vault read -field=value secret/GPASSWORD)

with your password, otherwise, here is an example how to install vault, it is straightforward, in dev mode it will keep passwords in memory, so next time you if restar you would need to run it again and add your passwords.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *