Pathaction | A universal Makefile for any file in the filesystem: Rule-driven commands for any file or directory

The pathaction tool is a flexible command-line utility for running commands on files and directories. Pass a file path as an argument, and the tool handles the rest, whether you are working with code, media, or configurations. Think of pathaction like a Makefile for any file or directory in the filesystem. It uses a .pathaction.yaml file to determine which command to run, and you can use Jinja2 templating to make those commands dynamic. You can also use tags to define multiple actions for the exact same file type. For example, you can set up one tag to run a script, … Continue reading

Python: How to clear stdin before using the input() function

In Python, the input() function is commonly used to capture input from the user. However, issues may arise when unwanted or unexpected data is present in the stdin, leading to incorrect or incomplete results when calling input(). A reliable approach to address this issue is to clear the stdin buffer before invoking input(). This article discusses why discarding the stdin buffer is necessary and how to implement it correctly to ensure accurate and clean input handling on both POSIX systems (such as Unix, Linux, and macOS) and Windows. Why does stdin need to be cleared? When working with user input, … Continue reading

Emacs: Maintaining proper indentation in indentation-sensitive programming languages

As codebases grow, maintaining proper indentation becomes increasingly difficult, especially in languages like Python or YAML, where indentation is not just a matter of style but an important part of the syntax. When working with large code blocks or deeply nested structures, it’s easy to lose track of the correct indentation level, leading to errors and decreased readability. In this post, we’ll explore Emacs packages and an Elisp code snippet that can help manage indentation in these indentation-sensitive languages. Code snippet: Indenting new lines based on previous non-blank line The following code snippet configures Emacs to indent based on the … Continue reading

Emacs .dir-locals.el - Add project path to $PYTHONPATH (Python Development in Emacs)

In order to ensure that the processes executed by Emacs and its packages, such as Flycheck or Flymake, can access the Python modules of a project, it is essential to correctly configure the $PYTHONPATH environment variable. This article provides a solution by introducing a .dir-locals.el file that adds the directory path of .dir-locals.el to the $PYTHONPATH environment variable. The .dir-locals.el file should be placed in the root directory of a Python project. File name: .dir-locals.el

A Git Tool that can decide whether to use 'git mv' or 'mv' to move files and/or directories

The git-smartmv command-line tool, written by James Cherti, allows moving files and/or directories without having to worry about manually choosing whether to use mv or git mv. Installation Shell alias To simplify the usage of this tool, you can add the following line to your ~/.bashrc: Usage The git-smartmv command-line tool accepts similar arguments as the mv command, including the source file or directory to be moved, and the destination file or directory. Example: Second example (rename): Links related to git-smartmv

Helper script to upgrade Arch Linux

In this article, we will be sharing a Python script, written by James Cherti, that can be used to upgrade Arch Linux. It is designed to make the process of upgrading the Arch Linux system as easy and efficient as possible. The helper script to upgrade Arch Linux can: The script provides a variety of options and is perfect for those who want to automate the process of upgrading their Arch Linux system (e.g. execute it from cron) and ensure that their system is always up to date. Requirements: psutilPython script name: archlinux-update.py

A tool to Execute a Command in a new Tmux Window

The Python script tmux-run.py allows executing a command in a new tmux window. A tmux window is similar to a tab in other software. If the script is executed from within a tmux session, it creates a tmux window in the same tmux session. However, if the script is executed from outside of a tmux session, it creates a new tmux window in the first available tmux session. (Requirement: libtmux) The Python script: tmux-run.py

vim-client - send commands to the Vim editor

The vim-client command-line tools vim-client-edit, vim-client-diff and the Python module vim_client will allow you to connect to a Vim server and make it: - Edit files or directories in new tabs, - Compare files (similar to vimdiff), - Evaluate expressions and return their result, - Send commands to Vim. It will allow you, for example, to make Vim edit or diff files from outside of Vim (e.g. from a shell like Bash, Zsh, etc.). License Copyright (C) 2022-2026 James Cherti. Distributed under terms of the MIT license. Requirements Python >= 3.0 The Vim editor ('vim' or 'gvim' in $PATH. Vim … Continue reading

Vim: Open documentation in a new tab for the word under the cursor (Vim help, Python, man pages, Markdown, Ansible...)

The following Vim script (VimL) function can be used to make Vim open the documentation of the word under the cursor in a new tab for various languages and tools such as Vim help (:help), Python (Pydoc), Markdown (sdcv dictionary), man pages (Vim's built-in ':Man'), and Ansible (ansible-doc). The VimL function is also extensible, meaning that you can adapt it to work with any other documentation tool. By default, the key mapping upper-case "K" can be used to open the documentation for the word under the cursor in a new tab.