Posts tagged 'python'

Rewriting z from scratch, part 2

Last month I wrote about how I rewrote z from scratch after I started using fzf.

10 days later I posted the following toot on Mastodon:

There’s a problem with my implementation: ‘recent’ paths only get priority after they’ve been accessed enough times.

There’s an elegant solution for this, let’s see if you can find it!

There’s a clue on my github repo:

Answer on my blog soon.

PS: No spoil, please

Well, it’s time for me to give the answer.

Rewriting z from scratch

z is a tool that will remember all the directories you are visiting when using your terminal, and then make it possible to jump around those directories quickly.

Let’s try and rewrite this functionality from scratch, maybe we’ll learn a few things this way.

Interfaces and Annotations in Python3

TL;DR: Annotations in Python3 are very useful when declaring interfaces using abc metaclass.

If you want to stop reading here, I’m not going to stop you:)

If not, allow me to take you to on a small journey where I explain what all of this is about …

How I Lint My Python

This is a short post describing how I lint my Python code. You’ll see it’s a bit more than just installing some plug-ins in a IDE, instead it’s a little bit of scripting code.

symlinks made easier

For years I’ve been struggling with the ln command.

I never could remember how to use it, mixing the order of the parameters, and the man page did not help.

$ man ln

      ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
      ln [OPTION]... TARGET                  (2nd form)
      ln [OPTION]... TARGET... DIRECTORY     (3rd form)
      ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

So I thought, why not write a small wrapper around it?

docopt v argparse

Say you have a program named foo that is supposed to be used from the command line, written in Python.

It provides lots of various features, so you decide to group them into subcommands, like git or mercurial does for instance.

So your program can be called in the following ways:

$ foo bar --baz --num-jobs=4
runs bar(baz=True, num_jobs=4)

$ foo read --verbose
runs read("", verbose=True)

Assuming you are using Python for this, which library should you use to implement command line parsing?