5.2 KiB
translating by lujun9972 A Commandline Fuzzy Search Tool For Linux
Today, we will be discussing about an Interesting commandline utility called " Pick". It allows users to select from a set of choices using an ncurses(3X) interface with fuzzy search functionality. The Pick utility can be helpful in certain situations where you wanted to search for a folder or file that contains a non-English characters in their name. You don't have to learn how to type the non-english characters. Using Pick, you can easily search them, select them and view or cd into them easily. You don't even have to type any characters to search a file or folder. It's good for those working with large pile of directories and files.
Pick - A Commandline Fuzzy Search Tool For Linux
Installing Pick
For Arch Linux and its derivatives, Pick is available in AUR. So, the Arch users can install it using AUR helper tools such as Pacaur, Packer, and Yaourt etc.
pacaur -S pick
Or,
packer -S pick
Or,
yaourt -S pick
The Debian , Ubuntu , Linux Mint users run the following command to install Pick.
sudo apt-get install pick
For other distributions, download the latest release from here and follow the below instructions to install Pick. As of writing this guide, the latest version was 1.9.0.
wget https://github.com/calleerlandsson/pick/releases/download/v1.9.0/pick-1.9.0.tar.gz
tar -zxvf pick-1.9.0.tar.gz
cd pick-1.9.0/
Configure it using command:
./configure
Finally, build and install pick:
make
sudo make install
Usage
By combining it with other commands will make your commandline life much easier. I will show some examples, so you can understand how it works.
Let me create a stack of directories.
mkdir -p abcd/efgh/ijkl/mnop/qrst/uvwx/yz/
Now, you want to go the directory /ijkl/ directory. You have two choice. You can either use cd command like below:
cd abcd/efgh/ijkl/
Or, create a shortcut or an alias to that directory, so you can switch to the directory in no time.
Alternatively, just use "pick" command to switch a particular directory more easily. Have a look at the below example.
cd $(find . -type d | pick)
This command will list all directories and its sub-directories in the current working directory, so you can just select any directory you'd like to cd into using Up/Down arrows, and hit ENTER key.
Sample output:
Also, it will suggest the directories or files that contains a specific letters as you type them. For example, the following output shows the list of suggestions when I type "or".
It's just an example. You can use "pick" command along with other commands as well.
Here is an another example.
find -type f | pick | xargs less
This command will allow you to select any file in the current directory to view in less.
Care to learn another example? Here you go. The following command will allow you to select individual files or folders in the current directory you want to move to any destination of your choice, for example /home/sk/ostechnix.
mv "$(find . -maxdepth 1 |pick)" /home/sk/ostechnix/
Choose the file(s) by using Up/Down arrows and hit ENTER to move them to /home/sk/ostechnix/ directory.
As you see in the above output, I have moved the folder called "abcd" to "ostechnix" directory.
The use cases are unlimited. There is also a plugin called pick.vim for Vim editor to make your searches much easier inside Vim editor.
For more details, refer man pages.
man pick
That's all for now folks. Hope this utility helps. If you find our guides useful, please share them on your social, professional networks and recommended OSTechNix blog to all your contacts.
via: https://www.ostechnix.com/pick-commandline-fuzzy-search-tool-linux/