Skip to main content

Remove the currently opened file without leaving vim

1 min read

Vim Tip Of The Day : remove the currently opened file without leaving vim

:!rm %

Woodworking, vim, and OpenSCAD

3 min read

When I'm not coding, I like to spend time building stuff with my hands - I mean real, physical stuffs. I'm certainly not a fine woodworker but I enjoy spending time in my garage and put a few pieces of wood together and make something out of it.

So far I've build two play tables for my kids, a mallet, a stool, and a roman workbench, and all of that with little to no plan. I've been lucky and never really got into trouble by lack of planning, but with the next projects I have in mind, I feel like  I need to design a little bit beforehand just to be sure I'm not doing anything stupid.

A stool I built

The problem? I'm really bad at designing, and it's even worst when 3D is involved. One of the woodworker I follow on YouTube, Steve Ramsey, often says he uses Sketchup to plan his projects before going into his shop, so of course I tried it and failed it. I'm just not the graphical type, and I hate using a mouse on top of that - I don't even own one anymore.

Until a few days ago, where I stumble upon OpenSCAD, which seem to have been created for people just like me : OpenSCAD, as the name implies, is a CAD (Computer-aided design) program, but instead of using your mouse to move 3D objects on an plan, you use your keyboard and code your way out of it.

Of course I knew this was for me, so after installing it on my computer i ran openscad and read the doc but only a few minutes in, i felt the frustration growing inside me : vim has spoiled me, and writing in anything other than vim feels like a physical pain.

Fortunatelly, vim truely is awesome, and i managed to do exactly what i wanted to mimic from the OpenSCAD IDE : exporting a graphical version of my model as soon as i save the scad file and opening it in feh as soon as I open a .scad file.

vim editing an openscad file alongside feh displaying the rendered model

Here's how I did it :

" Compile openscad image on save
autocmd BufWritePost *.scad :silent !openscad -o %:r.png %
" Automatically open png version of a scad file with feh on opening
autocmd BufRead *.scad :silent !feh %:r.png&

If you're looking for a syntax highlightling plugin, you might find this one usefull : sirtaj/vim-openscad

Now I'm planning on building a shelf - once again for the little ones - and this is what i came up with so far. It's not much, but it made me realize that what I had in mind wasn't exactly realistic or aesthetic.

3D model of the shelf I'm about to build

For those interrested, the code is available on my GitHub.

Mutt + ProtonMail

4 min read

Il y a maintenant plusieurs semaines que j'utilise ProtonMail. Bien que rassembler mes 7 adresses précédentes sur une seule m'a grandement simplifié la vie, je ne suis toujours pas satisfait des clients disponibles. Sous Linux, seul Thunderbird est actuellement disponible, à moins d'utiliser de webmail - ce que je fais pour l'instant.

Il y a quelques années, j'avais testé Mutt un peu comme un jeu. La raison pour laquelle j'avais arrêté de l'utiliser était justement le nombre d'adresse que je devais gérer : l'outil était certes intéressant, mais difficile à utiliser avec autant de compte.

Maintenant que j'ai résolu ce problème, j'avais envie de redonner une chance à ce client minimaliste et, par la même occasion, voir s'il était possible de faire cohabiter Mutt et ProtonMail.

Installation et premier lancement

Pour installer mutt, il suffit d'installer le paquet du même nom :

sudo apt install mutt

En lancant pour la première fois la commande mutt, je reçois une erreur :

/var/mail/cedric: Aucun fichier ou dossier de ce type (errno = 2)

Je crée le fichier en question et je lui donne les permissions nécessaire à mon utilisateur :

sudo mkdir -p /var/mail/$(whoami)
sudo chown $(whoami):$(whoami) /var/mail/$(whoami)

J'en profite pour initialiser le fichier de configuration .muttrc

vim ~/.muttrc
set realname = "Your Name"
set header_cache =~/.mutt/cache/headers
set certificate_file =~/.mutt/certificates
set message_cachedir =~/.mutt/cache/bodies

Lancer une nouvelle fois la commande mutt, ne donne plus d'erreur.

[caption id="attachment_4409" align="alignnone" width="1024"] Premier écran du logiciel Mutt - un client mail en ligne de commande. Au moins, c'est épuré :-)[/caption]

Configuration de mutt

Note : je pars du principe que le Bridge pour Linux est installé et lancé.

J'ajoute au fichier de configuration .muttrc les lignes suivantes:

# "+" substitutes for `folder`
set mbox_type=Maildir
set folder=/var/mail/cedric/
set spoolfile=+INBOX
set record=+Sent
set postponed=+Drafts
set trash=+Trash
set mail_check=2 # seconds

# smtp
source ~/docs/keys/mail
set smtp_url=smtp://$my_user:$my_pass@
set ssl_force_tls
set ssl_starttls

Et dans le fichier ~/docs/keys/mail:

set my_user=EMAIL

Installation et configuration de OfflineIMAP

J'installe OfflineIMAP :

sudo pip install offlineimap

Puis je crée un fichier de configuration .offlineimaprc :

accounts = main

[Account main]
localrepository = main-local
remoterepository = main-remote

# full refresh, in min
autorefresh = 0.2

# quick refreshs between each full refresh
quick = 10

# update notmuch index after sync
postsynchook = notmuch new

[Repository main-local]
type = Maildir
localfolders = /var/mail/cedric

# delete remote mails that were deleted locally
sync_deletes = yes

[Repository main-remote]
type = IMAP
remoteport = 1143
remotehost =
remoteuser = EMAIL
keepalive = 60
holdconnectionopen = yes

# delete local mails that were deleted on the remote server
expunge = yes

# sync only these folders
folderfilter = lambda foldername: foldername in ['INBOX', 'Archive', 'Sent']

# is broken, but connecting locally to bridge so should be ok
ssl = no

On lance la commande offlineimap, et, si tout s'est bien passé, on peut commencer à voir la progression de la synchronisation avec ProtonMail :

OfflineIMAP 7.2.1
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
imaplib2 v2.57 (bundled), Python v2.7.14, OpenSSL 1.0.2g  1 Mar 2016
Account sync main:
 *** Processing account main
 Establishing connection to (main-remote)
 Creating folder INBOX[main-local]
 Creating new Local Status db for main-local:INBOX
 Creating folder Archive[main-local]
 Creating new Local Status db for main-local:Archive
 Creating folder Sent[main-local]
 Creating new Local Status db for main-local:Sent
Folder Archive [acc: main]:
 Syncing Archive: IMAP -> Maildir
Folder INBOX [acc: main]:
 Syncing INBOX: IMAP -> Maildir
Folder Archive [acc: main]:
 Copy message UID 1 (1/263) main-remote:Archive -> main-local:Archive
Folder INBOX [acc: main]:
 Copy message UID 1 (1/49) main-remote:INBOX -> main-local:INBOX
Folder Archive [acc: main]:
 Copy message UID 2 (2/263) main-remote:Archive -> main-local:Archive
Folder INBOX [acc: main]:
 Copy message UID 2 (2/49) main-remote:INBOX -> main-local:INBOX

Il ne reste plus maintenant qu'à relancer la commande mutt pour visualiser ses mails.

[caption id="attachment_4413" align="alignnone" width="1024"]Mutt est maintenant configuré pour fonctionner avec ProtonMail L'interface de Mutt une fois la configuration terminée[/caption]