From 45c3bfe4d484ad40967052873b3aa3c942f5e27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sun, 14 Oct 2018 16:59:49 +0200 Subject: [PATCH] Lotsofstuf --- config/autorandr/bg | 3 +- config/i3/config | 10 +- config/khard/khard.conf | 4 +- config/lemonbar/display.py | 5 +- config/lemonbar/providers.py | 6 +- config/lemonbar/requirements.txt | 13 ++ config/lemonbar/updaters.py | 5 + .../default.target.wants/syncthing.service | 1 + config/systemd/user/melfetch.service | 6 + config/systemd/user/melfetch.timer | 10 ++ .../user/timers.target.wants/melfetch.timer | 1 + scripts/install-prefs | 22 +++- scripts/mel | 26 +--- scripts/melConf | 115 +++++++++++++++++- scripts/rankmirrors | 2 + scripts/showKeyboardLayout | 4 + 16 files changed, 190 insertions(+), 43 deletions(-) create mode 100644 config/lemonbar/requirements.txt create mode 120000 config/systemd/user/default.target.wants/syncthing.service create mode 100644 config/systemd/user/melfetch.service create mode 100644 config/systemd/user/melfetch.timer create mode 120000 config/systemd/user/timers.target.wants/melfetch.timer create mode 100644 scripts/rankmirrors create mode 100755 scripts/showKeyboardLayout diff --git a/config/autorandr/bg b/config/autorandr/bg index a23f010..e1bcee1 100644 --- a/config/autorandr/bg +++ b/config/autorandr/bg @@ -1,3 +1,4 @@ +https://i.imgur.com/yVtVucs.jpg # Doctor Who Series 11 # Derivate of these ones https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-230622.png -https://geoffrey.frogeye.fr/files/backgrounds/VertBleu.png +# https://geoffrey.frogeye.fr/files/backgrounds/VertBleu.png # https://geoffrey.frogeye.fr/files/backgrounds/BleuVert.png diff --git a/config/i3/config b/config/i3/config index db37a6f..d21d640 100644 --- a/config/i3/config +++ b/config/i3/config @@ -61,6 +61,7 @@ bindsym $mod+F7 exec pactl suspend-sink @DEFAULT_SINK@ 1; exec pactl suspend-sin bindsym XF86AudioPrev exec mpc prev bindsym XF86AudioPlay exec mpc toggle bindsym XF86AudioNext exec mpc next +bindsym $mod+F10 exec ~/.scripts/showKeyboardLayout bindsym $mod+F11 exec urxvtc -e 'pacmixer' bindsym $mod+F12 exec urxvtc -e 'pacmixer' @@ -252,6 +253,13 @@ bindsym $mod+Shift+r restart # exit i3 (logs you out of your X session) bindsym $mod+Shift+e exit +# Set shut down, restart and locking features +set $mode_kblock Keyboard lock +mode "$mode_kblock" { + bindsym $mod+Shift+Escape mode "$mode_kblock" +} +bindsym $mod+Shift+Escape mode "$mode_kblock" + # Set shut down, restart and locking features set $locker $HOME/.config/i3/lock set $mode_system [L] Vérouillage [E] Déconnexion [S] Veille [H] Hibernation [R] Redémarrage [P] Extinction @@ -347,7 +355,7 @@ set_from_resource $color15 i3wm.color15 #cfd0c2 # Inactivity settings exec --no-startup-id xautolock -time 10 -locker 'xset dpms force standby' -killtime 1 -killer '$locker' -bindsym $mod+F1 exec --no-startup-id xset dpms force off +bindsym $mod+F1 exec --no-startup-id sh -c "sleep .25 && xset dpms force off" bindsym $mod+F4 exec --no-startup-id xautolock -disable bindsym $mod+F5 exec --no-startup-id xautolock -enable diff --git a/config/khard/khard.conf b/config/khard/khard.conf index eee27d6..9c00adc 100644 --- a/config/khard/khard.conf +++ b/config/khard/khard.conf @@ -8,8 +8,8 @@ path = ~/.vdirsyncer/contacts/contacts/ [general] debug = no default_action = list -editor = vim -merge_editor = vimdiff +editor = nvim +merge_editor = nvim [contact table] # display names by first or last name: first_name / last_name diff --git a/config/lemonbar/display.py b/config/lemonbar/display.py index 5e597f6..17de09e 100755 --- a/config/lemonbar/display.py +++ b/config/lemonbar/display.py @@ -9,6 +9,7 @@ import signal import subprocess import logging import coloredlogs +import updaters coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s') log = logging.getLogger() @@ -23,6 +24,7 @@ log = logging.getLogger() # TODO Use default colors of lemonbar sometimes # TODO Adapt bar height with font height # TODO OPTI Static text objects that update its parents if modified +# TODO OPTI Updater locks, do not LB screen util every updater finished class BarGroupType(enum.Enum): @@ -118,7 +120,6 @@ class Bar: Bar.actionsF2H[function] = handle Bar.actionsH2F[handle] = function - log.debug("Registered action {} → {}".format(handle, function)) return handle @staticmethod @@ -292,8 +293,10 @@ class SectionThread(threading.Thread): ANIMATION_START = 0.025 ANIMATION_STOP = 0.001 ANIMATION_EVOLUTION = 0.9 + def run(self): while Section.somethingChanged.wait(): + updaters.notBusy.wait() Section.updateAll() animTime = self.ANIMATION_START frameTime = time.perf_counter() diff --git a/config/lemonbar/providers.py b/config/lemonbar/providers.py index a7aec71..f572b28 100755 --- a/config/lemonbar/providers.py +++ b/config/lemonbar/providers.py @@ -488,10 +488,14 @@ class NotmuchUnreadProvider(ColorCountsSection, InotifyUpdater): queryStr = 'folder:/{}/ and tag:unread'.format(account) query = notmuch.Query(db, queryStr) nbMsgs = query.count_messages() + if account == 'frogeye': + global q + q = query + print(489, self.dir, queryStr, nbMsgs) if nbMsgs < 1: continue counts.append((nbMsgs, self.colors[account])) - db.close() + # db.close() return counts def __init__(self, dir='~/.mail/', theme=None): diff --git a/config/lemonbar/requirements.txt b/config/lemonbar/requirements.txt new file mode 100644 index 0000000..0ed8bd4 --- /dev/null +++ b/config/lemonbar/requirements.txt @@ -0,0 +1,13 @@ +coloredlogs==10.0 +enum-compat==0.0.2 +humanfriendly==4.16.1 +i3ipc==1.6.0 +ifaddr==0.1.4 +ipaddress==1.0.22 +psutil==5.4.7 +pulsectl==18.8.0 +pyinotify==0.9.6 +python-mpd2==1.0.0 +python-uinput==0.11.2 +yoke==0.1.1 +zeroconf==0.21.3 diff --git a/config/lemonbar/updaters.py b/config/lemonbar/updaters.py index 083cae5..b8c4ae6 100755 --- a/config/lemonbar/updaters.py +++ b/config/lemonbar/updaters.py @@ -16,12 +16,14 @@ log = logging.getLogger() # TODO Sync bar update with PeriodicUpdater updates +notBusy = threading.Event() class Updater: @staticmethod def init(): PeriodicUpdater.init() InotifyUpdater.init() + notBusy.set() def updateText(self, text): print(text) @@ -49,15 +51,18 @@ class PeriodicUpdaterThread(threading.Thread): # TODO Sync with system clock counter = 0 while True: + notBusy.set() if PeriodicUpdater.intervalsChanged \ .wait(timeout=PeriodicUpdater.intervalStep): # ↑ sleeps here + notBusy.clear() PeriodicUpdater.intervalsChanged.clear() counter = 0 for providerList in PeriodicUpdater.intervals.copy().values(): for provider in providerList.copy(): provider.refreshData() else: + notBusy.clear() counter += PeriodicUpdater.intervalStep counter = counter % PeriodicUpdater.intervalLoop for interval in PeriodicUpdater.intervals.keys(): diff --git a/config/systemd/user/default.target.wants/syncthing.service b/config/systemd/user/default.target.wants/syncthing.service new file mode 120000 index 0000000..d55cc27 --- /dev/null +++ b/config/systemd/user/default.target.wants/syncthing.service @@ -0,0 +1 @@ +/usr/lib/systemd/user/syncthing.service \ No newline at end of file diff --git a/config/systemd/user/melfetch.service b/config/systemd/user/melfetch.service new file mode 100644 index 0000000..fb05ad3 --- /dev/null +++ b/config/systemd/user/melfetch.service @@ -0,0 +1,6 @@ +[Unit] +Description=Meh mail client new mail fetcher + +[Service] +Type=oneshot +ExecStart=/home/geoffrey/.scripts/mel fetch diff --git a/config/systemd/user/melfetch.timer b/config/systemd/user/melfetch.timer new file mode 100644 index 0000000..13acbc4 --- /dev/null +++ b/config/systemd/user/melfetch.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Meh mail client fetcher timer + +[Timer] +OnBootSec=2m +OnUnitActiveSec=5m +Unit=melfetch.service + +[Install] +WantedBy=timers.target diff --git a/config/systemd/user/timers.target.wants/melfetch.timer b/config/systemd/user/timers.target.wants/melfetch.timer new file mode 120000 index 0000000..820abac --- /dev/null +++ b/config/systemd/user/timers.target.wants/melfetch.timer @@ -0,0 +1 @@ +/home/geoffrey/.config/systemd/user/melfetch.timer \ No newline at end of file diff --git a/scripts/install-prefs b/scripts/install-prefs index 3c6ea44..d5eadee 100755 --- a/scripts/install-prefs +++ b/scripts/install-prefs @@ -233,10 +233,10 @@ if [ $GUI == 1 ]; then # Desktop manager inst dunst feh i3-wm i3lock numlockx qutebrowser rofi rxvt-unicode scrot trayer unclutter xautolock xclip if [ $ARCH == 1 ]; then - inst xorg-xinit xorg-xbacklight + inst xorg-xinit xorg-xbacklight ttf-dejavu altInst lemonbar-xft-git autorandr-git keynav-enhanced pacmixer rofi-pass elif [ $DEBIAN == 1 ]; then - # TODO autorandr pacmixer rofi-pass + # TODO autorandr pacmixer rofi-pass ttf-dejavu inst lemonbar keynav xbacklight fi @@ -257,12 +257,13 @@ fi if [ $EXTRA == 1 ]; then # Extra dev (not on mobile though ^^) if [ $TERMUX == 0 ]; then - inst cmake clang llvm ccache python-pip + inst cmake clang llvm ccache python-pip gdb fi # Extra CLI - inst ffmpeg optipng syncthing mutt notmuch mbsync jq - inst unzip unrar jdupes bedup + inst ffmpeg optipng syncthing mutt notmuch mbsync jq lynx + inst unzip unrar jdupes bedup p7zip + inst youtube-dl megatools speedtest-cli systemdUserUnit syncthing if [ $ARCH == 1 ]; then insta pandoc youtube-dl translate-shell imagemagick @@ -282,13 +283,22 @@ if [ $EXTRA == 1 ]; then # TODO Others fi + # FPGA goodness + if [ $ARCH == 1 ]; then + inst iverilog + altInst ghdl + fi + # Extra GUI if [ $GUI == 1 ]; then - inst vlc gimp mpd thunar musescore evince pdfpc texlive-{most,lang} + inst vlc gimp inkscape mpd thunar musescore evince pdfpc texlive-{most,lang} if [ $ARCH == 1 ]; then inst simplescreenrecorder mpc altInst vimpc-git ashuffle-git ttf-emojione-color + + # FPGA goodness + inst gtkwave fi # TODO Others diff --git a/scripts/mel b/scripts/mel index 037e345..99cb44c 100755 --- a/scripts/mel +++ b/scripts/mel @@ -313,29 +313,6 @@ def applyMsgs(queryStr, action, *args, showProgress=False, write=False, closeDb= return nbMsgs -# def update_polybar_status(): -def update_polybar_status(*args, **kwargs): - log.info("Updating polybar status") - accountsList = sorted(ACCOUNTS.keys()) - print(accountsList) - open_database() - statusArr = [] - for account in accountsList: - queryStr = 'folder:/{}/ and tag:unread'.format(account) - query = notmuch.Query(db, queryStr) - nbMsgs = query.count_messages() - if nbMsgs < 1: - continue - color = config[account]['color'] - statusAccStr = '%{F' + color + '}' + str(nbMsgs) + '%{F-}' - statusArr.append(statusAccStr) - close_database() - statusStr = ('_' + ' '.join(statusArr)) if len(statusArr) else '\n' - statusPath = os.path.expanduser("~/.cache/mutt/status") # TODO Better - with open(statusPath, 'w') as f: - f.write(statusStr) - # statusPath = os.path.expanduser("~/.cache/mel/polybarstatus") # TODO Better - def notify_msg(msg): log.info("Sending notification for {}".format(msg)) subject = msg.get_header("subject") @@ -448,7 +425,7 @@ def read_msg(msg): # Headers - for key in INTERESTING_HEADERS: + for key in INTERESTING_HEADERS: val = mail.get(key) if val: val = format_header_value(val) @@ -560,7 +537,6 @@ if __name__ == "__main__": # Notify notify_all() - update_polybar_status() # Tag new mails applyMsgs('tag:unprocessed', retag_msg, showProgress=True, write=True) diff --git a/scripts/melConf b/scripts/melConf index c46e30e..9e45784 100755 --- a/scripts/melConf +++ b/scripts/melConf @@ -11,6 +11,7 @@ import sys # TODO Find config file from XDG # TODO Signature file # TODO Write ~/.mail/[mailbox]/color file if required by sth? +# TODO Write in .config or .cache /mel # TODO Fix IMAPS with mbsync configPath = os.path.join(os.path.expanduser('~'), '.config', 'mel', 'accounts.conf') @@ -26,6 +27,17 @@ SERVER_DEFAULTS = { "smtp": {"port": 587, "starttls": True}, } SERVER_ITEMS = {"host", "port", "user", "pass", "starttls"} +ACCOUNT_DEFAULTS = { + "color": "#FFFFFF", + "color16": "0", + # "colormutt": "white", + "inboxfolder": "INBOX", + "archivefolder": "Archive", + "draftsfolder": "Drafts", + "sentfolder": "Sent", + "spamfolder": "Spam", + "trashfolder": "Trash", +} # Reading sections accounts = dict() @@ -59,6 +71,14 @@ for name in config.sections(): continue data[key] = section[key] + for k, v in config['DEFAULT'].items(): + if k not in data: + data[k] = v + + for k, v in ACCOUNT_DEFAULTS.items(): + if k not in data: + data[k] = v + mails.add(section["from"]) if "alternatives" in section: for alt in section["alternatives"].split(";"): @@ -163,8 +183,8 @@ for name, account in accounts.items(): secconf += "\nCertificateFile {certificate}".format(**account) imappassEscaped = account["imappass"].replace("\\", "\\\\") mbsyncStr += MBSYNC_ACCOUNT.format(**account, secconf=secconf, imappassEscaped=imappassEscaped) -msbsyncFilepath = os.path.join(os.path.expanduser('~'), '.mbsyncrc') -with open(msbsyncFilepath, 'w') as f: +mbsyncFilepath = os.path.join(os.path.expanduser('~'), '.mbsyncrc') +with open(mbsyncFilepath, 'w') as f: f.write(mbsyncStr) # msmtp @@ -188,8 +208,8 @@ tls on msmtpStr = MSMTP_BEGIN for name, account in accounts.items(): msmtpStr += MSMTP_ACCOUNT.format(**account) -msbsyncFilepath = os.path.join(os.path.expanduser('~'), '.msmtprc') -with open(msbsyncFilepath, 'w') as f: +mbsyncFilepath = os.path.join(os.path.expanduser('~'), '.msmtprc') +with open(mbsyncFilepath, 'w') as f: f.write(msmtpStr) @@ -221,7 +241,90 @@ other_email = mails.copy() other_email.remove(general["main"]["from"]) other_email = ";".join(other_email) notmuchStr = NOTMUCH_BEGIN.format(**general, other_email=other_email) -msbsyncFilepath = os.path.join(os.path.expanduser('~'), '.notmuchrc') -with open(msbsyncFilepath, 'w') as f: +mbsyncFilepath = os.path.join(os.path.expanduser('~'), '.notmuchrc') +with open(mbsyncFilepath, 'w') as f: f.write(notmuchStr) +# mutt (temp) + +## mailboxes +MAILBOXES_BEGIN = "mailboxes" + +mailboxesStr = MAILBOXES_BEGIN +for name, account in accounts.items(): + lines = "-" * (20 - len(name)) + mailboxesStr += f' "+{name}{lines}"' + for root, dirs, files in os.walk(account['storage']): + if "cur" not in dirs or "new" not in dirs or "tmp" not in dirs: + continue + assert root.startswith(storageFull) + path = root[len(storageFull)+1:] + mailboxesStr += f' "+{path}"' +mailboxesStr += "\n" +mailboxesFilepath = os.path.join(os.path.expanduser('~'), '.mutt/mailboxes') +with open(mailboxesFilepath, 'w') as f: + f.write(mailboxesStr) + +## accounts +# TODO html mails + +MUTT_ACCOUNT = """set from = "{from}" +set sendmail = "/usr/bin/msmtp -a {account}" +set realname = "{name}" +set spoolfile = "+{account}/{inboxfolder}" +set mbox = "+{account}/{archivefolder}" +set postponed = "+{account}/{draftsfolder}" +set record = "+{account}/{sentfolder}" +set trash = "+{account}/{trashfolder}" +set signature = "~/.mutt/accounts/{account}.sig" +set content_type = "text/plain" +set sig_dashes = yes + +color status {colormutt} default + +macro index D \\ + "N+{account}/{trashfolder}" \\ + "move message to the trash" + +macro index S \\ + "N+{account}/{spamfolder}" \\ + "mark message as spam" +# vim: syntax=muttrc +""" + +for name, account in accounts.items(): + muttStr = MUTT_ACCOUNT.format(**account) + + # Config + muttFilepath = os.path.join(os.path.expanduser('~'), f'.mutt/accounts/{name}') + with open(muttFilepath, 'w') as f: + f.write(muttStr) + + # Signature + sigStr = account.get("sig", account.get("name", "")) + sigFilepath = os.path.join(os.path.expanduser('~'), f'.mutt/accounts/{name}.sig') + with open(sigFilepath, 'w') as f: + f.write(sigStr) + +MUTT_SELECTOR = """ +set folder = "{storage}" +source ~/.mutt/mailboxes + +source ~/.mutt/accounts/{main[account]} + +{hooks} + +source ~/.mutt/custom + +# vim: syntax=muttrc +""" + +selectStr = "" +hooks = "" +for name, account in accounts.items(): + hooks += f"folder-hook {name}/* source ~/.mutt/accounts/{name}\n" +selectStr += MUTT_SELECTOR.format(**general, hooks=hooks) +selectFilepath = os.path.join(os.path.expanduser('~'), '.mutt/muttrc') +with open(selectFilepath, 'w') as f: + f.write(selectStr) + diff --git a/scripts/rankmirrors b/scripts/rankmirrors new file mode 100644 index 0000000..e2d63f3 --- /dev/null +++ b/scripts/rankmirrors @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +egrep -o 'Server = .+' /etc/pacman.d/mirrorlist.pacnew | /usr/bin/rankmirrors-n6 - > /etc/pacman.d/mirrorlist diff --git a/scripts/showKeyboardLayout b/scripts/showKeyboardLayout new file mode 100755 index 0000000..379ca37 --- /dev/null +++ b/scripts/showKeyboardLayout @@ -0,0 +1,4 @@ +#!/usr/bin/bash +layout=`setxkbmap -query | grep layout | tr -s ' ' | cut -d ' ' -f2` +variant=`setxkbmap -query | grep variant | tr -s ' ' | cut -d ' ' -f2` +gkbd-keyboard-display -l ${layout}$'\t'${variant}