Read file to console, automatically recognize file encoding, include ansi, utf16le, utf16be, utf8. Currently output ansi as gbk for chinese text search.

rgpre

A tool for rg --pre.

Read file to console, automatically recognize file encoding, include ansi, utf16le, utf16be, utf8. Currently output ansi as gbk for chinese text search.

Usage

rg --pre rgpre 中文

中文说明

rg有个问题是只能自动根据bom识别utf-8,utf16等,除此之外如gbk编码的文件,只能用rg -Egbk来搜索,这多少有点不方便。本工具根据rg提供的--pre参数说明编写而成,自动识别文件编码并把内容输出到console供rg搜索,支持编码有ansi,utf16le/be,utf8,目前ansi直接认为是gbk编码以方便中文搜索。参考了grepwin和ripgrep的源码。

输出到console会对rg速度有些影响,建议只在搜索中文时使用--pre参数。

emacs可以这样设置,只在搜索中文时开启--pre rgpre:

(defun chinese-char-p (char)
    (if (string-match "\\cC\\{1\\}" (string char))
    t
    nil)
)
(require 'cl-lib)
(defun chinese-word-chinese-string-p (string)
    "Return t if STRING is a Chinese string."
    (cl-find-if 'chinese-char-p (string-to-list string))
)

;; helm
(defadvice helm-grep-ag-prepare-cmd-line (around my-helm-grep-ag-prepare-cmd-line activate)
(if (chinese-word-chinese-string-p (ad-get-arg 0))
    (let ((helm-grep-ag-command (concat helm-grep-ag-command " --pre rgpre")))
    ad-do-it)
    ad-do-it)
)

;; rg.el
(defadvice rg-build-command (around my-rg-build-command activate)
    (if (chinese-word-chinese-string-p (ad-get-arg 0))
    (let ((rg-command-line-flags (list "--pre rgpre")))
    ad-do-it
    )
    ad-do-it)
)

调试

console窗口rgpre file就可以看到输出。

感谢

ripgrep, grepwin,rust,encoding_rs,they are all awesome!

Similar Resources

A program that read a program and output some shit-like code. /se

A program that read a program and output some shit-like code. /se

Jun 16, 2022

Lingo - Text encoding for modern C++

Lingo Lingo is an encoding aware string library for C++11 and up. It aims to be a drop in replacement for the standard library strings by defining new

Oct 18, 2022

Text utilities, including beam search decoding, tokenizing, and more, built for use in Flashlight.

Flashlight Text: Fast, Lightweight Utilities for Text Quickstart | Installation | Python Documentation | Citing Flashlight Text is a fast, minimal lib

Dec 15, 2022

A C program to strip comments from a c file and output the result to a new file.

Strip C-like Comments A C program to strip comments from a c file and output the result to a new file. Features Fast and Without any third-party libra

Feb 22, 2022

Protobuf for Proxyman app - Include Apple Silicon & Intel architecture

Protobuf for Proxyman macOS app Protobuf for Proxyman app - Include Apple Silicon & Intel architecture How to build Open the project on the latest Xco

Nov 29, 2021

A small and easy to use neural net implementation for C++. Just download and #include!

A small and easy to use neural net implementation for C++. Just download and #include!

NN++ A short, self-contained, and easy-to-use neural net implementation for C++. It includes the neural net implementation and a Matrix class for basi

Nov 11, 2022

Include binary files in C/C++

incbin Include binary and textual files in your C/C++ applications with ease Example #include "incbin.h" INCBIN(Icon, "icon.png"); // Re

Jan 4, 2023

Typewriter Effect with Rich Text + *Correct* Text Wrapping

Typewriter Effect with Rich Text + *Correct* Text Wrapping

Typewriter Effect with Rich Text + Correct Text Wrapping I've spent way too long getting this right. This is meant as a base class for a UMG dialogue

Nov 29, 2022

Text - A spicy text library for C++ that has the explicit goal of enabling the entire ecosystem to share in proper forward progress towards a bright Unicode future.

ztd.text Because if text works well in two of the most popular systems programming languages, the entire world over can start to benefit properly. Thi

Dec 25, 2022
Related tags
Recognize stairs with lidar. Project the laser points to X-Z plane and use least squares for linear fitting.
Recognize stairs with lidar. Project the laser points to X-Z plane and use least squares for linear fitting.

stairs_recogniton Recognize stairs with lidar. Project the laser points to X-Z plane and use least squares for linear fitting. Dependencies PCL 1.8 Ei

Nov 25, 2022
A collection of DLLs that use search order hijacking to automatically inject specified DLLs.

?? Koaloader ?? A collection of DLLs that use search order hijacking to automatically inject specified DLLs. ?? Usage Simply place one of the proxy dl

Jan 4, 2023
Typesense is a fast, typo-tolerant search engine for building delightful search experiences.
 Typesense is a fast, typo-tolerant search engine for building delightful search experiences.

Fast, typo tolerant, fuzzy search engine for building delightful search experiences ⚡ ??

Jan 2, 2023
Convenient, high-performance RGB color and position control for console output
Convenient, high-performance RGB color and position control for console output

Oof (omnipotent output friend) It's common for C++ programs to write output to the console. But consoles are far more capable than what they are usual

Dec 27, 2022
This is a library that can fix the crash on android 5.0 and 5.1 caused by modified utf8 converting.

FixModifiedUtf8ConvertError This is a library that can fix the crash on android 5.0 and 5.1 caused by modified utf8 converting. What's this On Android

Nov 23, 2021
A keyboard of chinese, with pinyin input method(IME)

适用于单片机的lvgl简单中文键盘拼音输入法,使用QT5.14创建,直接打开即可运行模拟器 如果QT编译提示有错误,尝试在构建设置中重设目录:QT的左边栏-"项目"->"Desktop QT5.14.2 MinGW 32-bit"->"构建设置"->"概要"->"构建目录",填入一个目录,比如“..

Dec 31, 2022
Simdutf - Unicode routines (UTF8, UTF16): billions of characters per second.
Simdutf - Unicode routines (UTF8, UTF16): billions of characters per second.

simdutf: Unicode validation and transcoding at billions of characters per second Most modern software relies on the Unicode standard. In memory, Unico

Jan 3, 2023
📚 single header utf8 string functions for C and C++

?? utf8.h A simple one header solution to supporting utf8 strings in C and C++. Functions provided from the C header string.h but with a utf8* prefix

Dec 28, 2022
Resources and forum for the Chinese community, maintained and moderated by CoinSummer & PL.

Awesome Filecoin 请注意:本文中的链接并非全部是官方链接,部分链接是第三方链接,有些甚至是收费链接,请大家注意区分。 1. Website 1.1 浏览器 FilFox - 6Block 团队开发的 Filecoin 浏览器 Filscan - IPFS原力团队开发的 Filecoi

Jan 4, 2023
Unofficial upload of ChinesePython, a translation of the Python programming language in Chinese [Provided by UrduPython engineers]

# Downloaded from SourceForge: https://sourceforge.net/projects/chinesepython/ # (Uploaded as is) ---------------------------------------------------

Feb 12, 2022