Base64 in NeoVim and Vim

At the moment, I use Astronvim as my NeoVim configuration. By default, key mappings for it are configured in ~/.config/nvim/lua/user/mappings.lua file.

The following snippet adds key mappings for inplace encoding and decoding base64 strings:

1
2
3
4
5
6
7
8
9
return {
  ...
  v = { -- Visual mode mappings
    ...
    ["<leader>64e"] = { "c<c-r>=system('base64 --wrap=0',          @\")<cr><esc>", desc = "Base64 encode" },
    ["<leader>64d"] = { "c<c-r>=system('base64 --wrap=0 --decode', @\")<cr><esc>", desc = "Base64 decode" },
  },
  ...
}

In the past I was using vanilla NeoVim and Vim, so I had the following lines in my ~/.config/nvim/init.vim:

1
2
vnoremap <leader>64e c<c-r>=system('base64 --wrap=0',          @")<cr><esc>
vnoremap <leader>64d c<c-r>=system('base64 --wrap=0 --decode', @")<cr><esc>

Read more

Mgitstatus

I’m working on several projects at the same time quite often and sometimes I’m loosing track of their states. Which one has uncommitted changes? Which one needs to be updated from an upstream?

It’s not difficult to write a bash oneliner to iterate over projects and run git status for each of them:

1
2
3
4
for project in development/projects/*;
do
    sh -c "cd $project; git status"
done

Well, it is not a oneliner, but just for readability. It might be invoked as a function or as a shell script. Here is an example output of the script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        public/

nothing added to commit but untracked files present (use "git add" to track)
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
fatal: not a git repository (or any of the parent directories): .git

As you can see, this output is hard to read. It’s too verbose and lack of colors. Actually, you can’t see for which repo the info is printed.

The script above definitely should be improved. Fortunately, it was done already. There are a couple of alternatives like mgitstatus, this script or gr (which, actually, can do much more than just status). Currently I’m using the first one. Here is an example output:

Look much better, doesn’t it?

Read more

Pipfile.lock → requirements.txt

TL;DR

Update

As it was pointed out in the comments, in the v2022.4.8 release a new command is added, which does the desired:

1
2
pipenv requirements > requirements.txt
pipenv requirements --dev-only > requirements-dev.txt

Here is the documentation for the command.

Old approach

For requirements.txt:

1
2
3
4
jq -r '.default
        | to_entries[]
        | .key + .value.version' \
    Pipfile.lock > requirements.txt

For requirements-dev.txt:

1
2
3
4
jq -r '.develop
        | to_entries[]
        | .key + .value.version' \
    Pipfile.lock > requirements-dev.txt

Read more