FZF and PowerShell: The Ultimate Combo for File Management
FZF (Fuzzy Finder) is a powerful command-line tool that allows you to search and filter through lists of items interactively. Originally designed for Unix-like systems, it can also be effectively used in Windows PowerShell.
You can download the latest release of FZF from its GitHub repository
After downloading, extract the contents of the ZIP file:
Expand-Archive -Path "fzf-0.54.3-windows_armv7.zip" -DestinationPath "C:\...\your toolbox\bin"
You can also add the FZF directory to your system PATH so that you can run it from anywhere. You can do this by modifying your PowerShell profile.
In the video below a compiled C program lists all the files in the current working directory. When executed with the --text option, the program will output only the filenames of editable text files to the standard output.
This C program has been compiled with the MINGW-W64 GCC compiler, a versatile toolchain that enables developers to create native Windows applications. MINGW-W64 is an extension of the original MINGW (Minimalist GNU for Windows) project, which provides a comprehensive set of GNU utilities and libraries tailored for Windows environments.
gcc listfiles.c -o listfiles.exe
The resulting list of filenames can then be piped to the FZF fuzzy finder tool, enabling the user to easily select a file from the list. Once a file is selected, it can be opened with the vim editor.
vim (listfiles.exe | fzf.exe --preview 'bat.exe {}')
The bat.exe command-line utility serves as a modern alternative to the traditional cat command found in Unix-like operating systems.
Additionally, we have compiled another C program that traverses all subdirectories from the working directory and displays the most recently modified files. This command has been included in the PowerShell user’s profile as a function to facilitate its usage.
function Open-MRUFile {
vim (listmru.exe | fzf.exe --preview 'bat --color=always {}')
}
This setup allows for a seamless and efficient workflow, making file selection and editing much simpler. Also, restarting work with the most recently used files becomes easier with this approach.
Fzf (fuzzy finder) is a powerful command-line tool that allows you to search and filter through lists of items interactively. While it was originally designed for Unix-like systems, it can be used effectively in Windows PowerShell as well.
Despite some limitations when using FZF in Windows PowerShell, it can be a very useful tool for quickly searching and filtering through lists. With its interactive interface and powerful features like previews, FZF can significantly enhance your command-line experience.