Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the design of fzf?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people have no idea about what fzf design is like. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Fzf description

Fzf itself is a very fast, general-purpose, fuzzy / strict matching or case-sensitive command line matching tool, which can support not only file and history commands, but also any other general content matching.

problem

When fzf is used to match files, each startup rescanned the list of files on disk (and seems to be depth first), causing a problem: if the number of files is large, you often cannot search for files in a very shallow directory.

Fzf is currently mainly used by editors such as vim for project-level file matching, and it is not possible to match global / system-level files like everything. If you want to achieve the purpose of the latter, you can optimize it from the following points:

Run a daemon process in the background to cache the list of files

Cache the file list in the file to avoid the next large-scale scan of the disk

Monitor the real-time change of files through mechanisms such as inotify

2019-12-12 Supplementary

Fzf officially provides many useful methods that you can use on a case-by-case basis: https://github.com/junegunn/fzf/wiki/examples

For example:

# fd-cd to selected directoryfda () {local dir dir=$ (find ${local dir dir=$.}-path'* /\. *'- prune\-o-type d-print 2 > / dev/null | fzf + m) & & cd "$dir"} # Another fd-cd into the selected directory# This one differs from the above By only showing the sub directories and not# showing the directories within those.fd () {DIR= `find *-maxdepth 0-type d-print 2 > / dev/null | fzf- tmux`\ & & cd "$DIR"} # fe [FUZZY PATTERN]-Open the selected file with the default editor#-Bypass fuzzy finder if there's only one match (--select-1) #-Exit if there's no match (--exit-0) fe () {local files IFS=$'\ n' Files= ($(fzf-tmux-- query= "$1"-- multi-- select-1-- exit-0)) [- n "$files"] & & ${EDITOR:-vim} "${files [@]}"} # fkill-kill processes-list only the ones you can kill. Modified the earlier script.fkill () {local pid if ["$UID"! = "0"] Then pid=$ (ps-f-u $UID | sed 1d | fzf-m | awk'{print $2}') else pid=$ (ps-ef | sed 1d | fzf-m | awk'{print $2}') fi if ["x$pid"! = "x"] then echo $pid | xargs kill-${1VANT 9} fi} after reading the above, have you mastered the method of fzf design? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report