1
0
Fork 0
uvgotmail/uvgotmail.py

40 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import sys
import os
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--daemon", help="run in daemon mode (put this at end of .bashrc)", action="store_true")
parser.add_argument("--config", help="specify config file in muttrc format")
parser.add_argument("--check", help="run in check mode (put this in PS1)", action="store_true")
parser.add_argument("--no-count", help="don't display how many unread messages there are", action="store_false")
parser.add_argument("--mailbox-char", help="specify a character instead of the mailbox emoji",default="📬")
args = parser.parse_args()
global mailchar, countmail;
mailchar = args.mailbox_char
countmail = args.no_count;
if(args.daemon == args.check):
parser.print_help()
sys.exit(0)
if(args.daemon):
daemon()
else:
check()
def check():
filename = '/tmp/uvgotmail/'+os.getlogin()+'/unread'
if os.path.exists(filename):
with open(filename) as f:
unread = int(f.read());
if unread == 0:
sys.exit(0)
pre = ""
if(unread > 1 and countmail):
pre = "("+str(unread)+") "
print(pre+mailchar,end=' ')
main();