Today I Learned… vim, docker, entr

1 minute read

Vim sessions

Save the current session in a file with the mksession command:

:mksession session.vim

And then restore it the next time with:

:source session.vim

I’m going to have to use this a lot from now onwards.

entr command

Thanks to Julia’s post I learned a new thing. entr is a simple command line utility that runs any command that you want when a particular file(s) changes. This feels like a low-key hot-reloading stuff the javascript libraries have. Feels nice to be able to do this ourselves.

The basic format is:

ls *.rb | entr bash

This will run the script every time any of the ruby files in the current directory changes. If we are writing some simple script, then this is a very fast way to get feedback on the changes and see the program running without any extra effort!

We can use the -r flag to re-run any server process.

git ls-files | entr rails server

Any files that git tracks in the current folder, if any of them change, then rails server will be restarted.

Docker - How to attach to the same container’s process in a new terminal session?

With this docker run command, I was in the bash prompt of the ubuntu system:

docker run --rm -it ubuntu bash

Once in, I wanted to test the entr command. So I installed it and ran this command:

ls tmp.txt  | entr bash

The script was just echoing some string. This command made the process run in the foreground. So I couldn’t test it in the same session.

In my local laptop, in another terminal session, I ran this command to login to the same docker container process:

docker exec -it 12c5eb238406 bash

where 12c5eb238406 is the container id I got from docker ps. Now I was able to add lines to the tmp.txt file and see entr running the script in the other terminal window.