Introduction
fzf is a versatile fuzzy finder for various command-line interfaces. It allows users to quickly search and interact with files, directories, text, and even processes. This article will cover how to use fzf to find and kill processes in the Windows Command Prompt (CMD).
Installing fzf on Windows with Chocolatey
Before we dive into using fzf to find and kill processes, let's make sure you have it installed. First, you need to have Chocolatey, a package manager for Windows, installed. If you don't have it yet, follow the instructions on their official website: https://chocolatey.org/install
Once Chocolatey is installed, open a new Command Prompt window and run:
> choco install fzf
Finding Processes with fzf
To find processes using fzf, you'll need to install an additional package called "fzf-bin" which provides the necessary functionality. Run the following command:
> git clone --depth=1 https://github.com/junegunn/fzf.git ~/.fzf
> ~/.fzf/install --bin
Now, you can use fzf to find processes by typing:
> tasklist | fzf
Killing Processes with fzf
To kill a process using fzf, you'll need to modify the "taskkill" command to accept the output of fzf as its argument. Create a new batch file called "kill.bat" with the following content:
@echo off
for /f "tokens=1" %%a in (%*) do (
taskkill /F /IM %%a
)
Save the file in a convenient location, such as "%USERPROFILE%\AppData\Local\fzf\bin\". Now, you can create an alias for this batch file in your Command Prompt:
> setx PROMPT=$P$G> tasklist | fzf --ansi --multi --bind="enter:kill %i\r" --bind="up:history-search-back:5:tasklist | fzf --ansi --multi --bind="enter:kill %i\r"
This command sets up an alias called "kill" that runs the "kill.bat" file with the selected process name as its argument. The "tasklist" command is piped to fzf with the "--ansi", "--multi", and "--bind" options to enable multi-selection and custom keyboard bindings.
- Install fzf using Chocolatey.
- Install the "fzf-bin" package for process management.
- Create a batch file called "kill.bat" to kill processes.
- Set up an alias called "kill" to run the "kill.bat" file with the selected process name as its argument.