Skip to content

Commit 117e8df

Browse files
committed
add rga-fzf, rgi-fzf
1 parent b20a3f1 commit 117e8df

File tree

8 files changed

+195
-5
lines changed

8 files changed

+195
-5
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ go: gopls(可以通过vim-go下载后,配置环境变量)
5151
sudo apt install wslu
5252
```
5353

54-
## 远程开发
54+
## 远程开发环境对比
5555

56-
本地开发环境+远程文件系统:sshfs
56+
**本地开发环境+远程文件系统:sshfs**
57+
适用于本地有开发环境,远程没有搭开发环境的场景
58+
59+
**vscode+neovim插件 ssh remote**
60+
优点:无需在服务器安装高版本(neo)vim、无需OSC就可以复制粘贴远程服务器上的文本,方便查看渲染后的pdf/网页/markdown
61+
缺点:面对跳板机环境不方便
62+
63+
**(neo)vim**
64+
优点:在跳板机环境、临时服务器环境(无插件配置)下比较方便
65+
缺点:在低版本操作系统中编译安装高版本(neo)vim和插件比较麻烦,不用sshfs时,查看渲染后的pdf/网页/markdown比较麻烦

root/.vim/doc/mydoc.txt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ CTRL-SHIFT-V paste
128128

129129
-------------------------------------------------------------------------------
130130

131-
*WSL创建软链接文件夹* mklinkd 2023-03-07-1 /mnt/d/doc2/group-meeting/readinggroup/2023-03-07-1
132-
133-
134131
*git提交把作者改成自己* git commit --amend --reset-author --no-edit
135132
*ssh生成key* 1) ssh-keygen -t rsa -C '邮件地址@youremail.com' 2) cat ~/.ssh/id_rsa.pub
136133
*git回退版本* git reset --soft 需要回退的commit hash
@@ -198,3 +195,45 @@ blob代表文件,tree代表文件夹。后者文件大小似乎略小一点。
198195
-------------------------------------------------------------------------------
199196

200197
*打开所有折叠* zR
198+
199+
-------------------------------------------------------------------------------
200+
201+
*bash-help*
202+
203+
*start* WSL用windows打开文件
204+
*WSL创建软链接文件夹* mklinkd 2023-03-07-1 /mnt/d/doc2/group-meeting/readinggroup/2023-03-07-1
205+
206+
*z* 模糊跳转autojump
207+
208+
*vimt* tex
209+
*vimhelp* help
210+
*vimdf* diff
211+
212+
-------------------------------------------------------------------------------
213+
214+
*bash-fzf*
215+
216+
*fzf跳转* fzfcd ALT-C
217+
*fzf补全* CTRL-T:递归搜索当前文件夹下文件
218+
CTRL-R:历史命令
219+
220+
*fzf查找文件夹并跳转* cd ** <TAB>
221+
*rfv* ripgrep grep找文件,fzf模糊查找,最后vim打开文件
222+
*rffv* ripgrep搜索文件,fzf模糊查找,最后vim打开文件
223+
*rga* *rgi* ripgrep查找各种类型的文件
224+
*rga-fzf* ripgrep查找各种类型的文件(不支持pptx),fzf模糊查找,最后打开文件
225+
*rgi-fzf* ripgrep查找各种类型的文件(支持pptx),fzf模糊查找,最后打开文件
226+
227+
-------------------------------------------------------------------------------
228+
229+
*junegunn/fzf-git.sh* https://github.com/junegunn/fzf-git.sh/
230+
231+
CTRL-G CTRL-F for Files
232+
CTRL-G CTRL-B for Branches
233+
CTRL-G CTRL-T for Tags
234+
CTRL-G CTRL-R for Remotes
235+
CTRL-G CTRL-H for commit Hashes
236+
CTRL-G CTRL-S for Stashes
237+
CTRL-G CTRL-E for Each ref (git for-each-ref)
238+
239+
-------------------------------------------------------------------------------

root/.vim/doc/unused.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Awesome Plugins/Scripts~
44
=======================================================================================
55

6+
*glepnir/dashboard-nvim* neovim's dashboard plugin
67
*mhinz/vim-startify* beautify dashboard, see >
78
git show v0.2.1:root/vimrc.d/startify.vim
89
<

root/bashrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ alias vimhelp='vim -c ":Lines!" ~/.vim/doc/mydoc.txt'
2121
source ~/vimrc/root/fzf/fzf.bash
2222
source ~/vimrc/root/vimdf
2323

24+
alias rgpipe='~/vimrc/root/rgpipe'
25+
RGPIPE='~/vimrc/root/rgpipe'
26+
alias rgi="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
27+
'*.{pdf,xl[tas][bxm],xl[wsrta],do[ct],do[ct][xm],p[po]t[xm],p[op]t,html,htm,xhtm,xhtml,epub,chm,od[stp]}' --pre ${RGPIPE}"
28+
2429
export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"

root/fzf/fzf.bash

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,35 @@ rffv() {
9898
[ -n "${selected[0]}" ] && vim "${selected[0]}" "+${selected[1]}"
9999
}
100100

101+
# https://github.com/ColonelBuendia/rgpipe
102+
rgi-fzf() {
103+
RG_PREFIX="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
104+
'*.{pdf,xl[tas][bxm],xl[wsrta],do[ct],do[ct][xm],p[po]t[xm],p[op]t,html,htm,xhtm,xhtml,epub,chm,od[stp]}' --pre ~/vimrc/root/rgpipe --files-with-matches $@"
105+
local file
106+
file="$(
107+
RIPGREP_CONFIG_PATH='' \
108+
FZF_DEFAULT_COMMAND="$RG_PREFIX . " \
109+
fzf --sort --preview="[[ ! -z {} ]] && rg -iz --pretty --pre ~/vimrc/root/rgpipe {q} {} | head -n 100" \
110+
--phony -q "" \
111+
--bind "change:reload:$RG_PREFIX {q}" \
112+
--preview-window="70%:wrap"
113+
)" &&
114+
echo "opening $file" &&
115+
start "$file"
116+
}
117+
118+
# https://github.com/phiresky/ripgrep-all
119+
rga-fzf() {
120+
echo $@
121+
RG_PREFIX="RIPGREP_CONFIG_PATH='' rga --no-ignore --files-with-matches $@"
122+
local file
123+
file="$(
124+
FZF_DEFAULT_COMMAND="$RG_PREFIX . " \
125+
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
126+
--phony -q "" \
127+
--bind "change:reload:$RG_PREFIX {q}" \
128+
--preview-window="70%:wrap"
129+
)" &&
130+
echo "opening $file" &&
131+
start "$file"
132+
}

root/rgpipe

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/sh
2+
#
3+
# thisdoes: working version of rgpre
4+
# ColonelBuendia was here, 2019-11-20, also later
5+
#
6+
# ubuntu wants: poppler-utils p7zip w3m
7+
# termux wants: poppler p7zip w3m
8+
#
9+
# alias rgi="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
10+
# '*.{pdf,xl[tas][bxm],xl[wsrta],do[ct],do[ct][xm],p[po]t[xm],p[op]t,html,htm,xhtm,xhtml,epub,chm,od[stp]}' --pre rgpipe"
11+
#
12+
# note to self re: less usage
13+
# export LESSOPEN="|/home/sanchopanda/scripts/rgpipe %s"
14+
# LESSOPEN="|lesspipe.sh %s"
15+
#
16+
# note to self re: fzf usage
17+
# f-cd() { cd $( dirname "$(locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100')") ; }
18+
# f-less() { less `locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100'`; }
19+
# f-subl() { subl `locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100'`; }
20+
#
21+
# note to self re: mobi files
22+
# A simple way is to use [this script](https://github.com/kevinhendricks/KindleUnpack/archive/v032.zip) but it writes to disk so I don't really.
23+
# Any notes on how to do this using the existing tools here would be highly appreciated.
24+
#
25+
# note to self re: key files as in apple keynote
26+
# Use someting like Snzip to do it right. Note the format has varied over time without changing extension, and that key files are often otherwise greppable text files in other contexts.
27+
# garbage methord: unzip -qc "$1" */Slide* */*/Data | strings -n 13
28+
#Some [notes](https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#snappy-compression) on [keynote files](https://github.com/kubo/snzip/issues/14)
29+
#
30+
# Superior tools for more robust usage when doing that
31+
# catdoc, catppt, xls2csv, xlsx2csv, ods2txt, ebook-convert, ssconvert, in2csv, html2csv(pip3 html-to-csv), psc
32+
#
33+
34+
case "$1" in
35+
*.pdf)
36+
# exec pdftotext -q -layout "$1" -
37+
exec rga-preproc "$1"
38+
;;
39+
*.xl[ast][xmt])
40+
exec unzip -qc "$1" *.xml | sed -e 's/<\/[vft]>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
41+
;;
42+
*.xlsb)
43+
unzip -qc "$1" *.bin | strings -e l
44+
;;
45+
*.xl[wsrta])
46+
exec strings "$1"
47+
;;
48+
*.do[ct])
49+
exec strings -d -15 "$1"
50+
;;
51+
*.do[tc][xm])
52+
exec unzip -qc "$1" word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
53+
;;
54+
*.p[po]t)
55+
exec strings -d "$1"
56+
;;
57+
*.p[po]t[xm])
58+
exec unzip -qc "$1" ppt/slides/*.xml | sed -e 's/<\/a:t>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
59+
;;
60+
*.xhtm)
61+
w3m -T text/html -dump -cols 120 "$1"
62+
;;
63+
*.xhtml)
64+
w3m -T text/html -dump -cols 120 "$1"
65+
;;
66+
*.htm)
67+
w3m -T text/html -dump -cols 120 "$1"
68+
;;
69+
*.html)
70+
exec cat "$1" | w3m -T text/html -dump -cols 120
71+
;;
72+
*.epub)
73+
exec unzip -qc "$1" "*.*htm*" | w3m -T text/html -dump -cols 120
74+
;;
75+
*.chm)
76+
exec 7z e -r -so "$1" *.htm *.xml *.htm *.html *.xhtm *.xhtml | w3m -T text/html -dump -cols 120
77+
;;
78+
*.od[stp])
79+
exec unzip -qc "$1" *.xml | sed -e 's/<\/text:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
80+
;;
81+
*)
82+
case $(file "$1") in
83+
*Zstandard*)
84+
exec pzstd -cdq "$1"
85+
;;
86+
*)
87+
exec cat "$1"
88+
;;
89+
esac
90+
;;
91+
esac

root/vimrc.d/fzf.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ command! -bang -nargs=? -complete=custom,ListDocs HelpRg
8282
\ {}, <bang>0) |
8383
\ end
8484

85+
function! RipgrepFzf(query, fullscreen)
86+
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
87+
let initial_command = printf(command_fmt, shellescape(a:query))
88+
let reload_command = printf(command_fmt, '{q}')
89+
let spec = {'options': ['--disabled', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
90+
let spec = fzf#vim#with_preview(spec, 'right', 'ctrl-/')
91+
call fzf#vim#grep(initial_command, 1, spec, a:fullscreen)
92+
endfunction
93+
94+
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

setup-ubuntu2204.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ n latest
1010
# npm i -g vscode-langservers-extracted
1111

1212
apt install -y ripgrep fzf fd-find tree bat clangd
13+
14+
# ripgrep-all(master分支)
15+
# apt install ripgrep pandoc poppler-utils ffmpeg

0 commit comments

Comments
 (0)