Skip to content

Commit

Permalink
add rga-fzf, rgi-fzf
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Mar 14, 2023
1 parent b20a3f1 commit 117e8df
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 5 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ go: gopls(可以通过vim-go下载后,配置环境变量)
sudo apt install wslu
```

## 远程开发
## 远程开发环境对比

本地开发环境+远程文件系统:sshfs
**本地开发环境+远程文件系统:sshfs**
适用于本地有开发环境,远程没有搭开发环境的场景

**vscode+neovim插件 ssh remote**
优点:无需在服务器安装高版本(neo)vim、无需OSC就可以复制粘贴远程服务器上的文本,方便查看渲染后的pdf/网页/markdown
缺点:面对跳板机环境不方便

**(neo)vim**
优点:在跳板机环境、临时服务器环境(无插件配置)下比较方便
缺点:在低版本操作系统中编译安装高版本(neo)vim和插件比较麻烦,不用sshfs时,查看渲染后的pdf/网页/markdown比较麻烦
45 changes: 42 additions & 3 deletions root/.vim/doc/mydoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ CTRL-SHIFT-V paste

-------------------------------------------------------------------------------

*WSL创建软链接文件夹* mklinkd 2023-03-07-1 /mnt/d/doc2/group-meeting/readinggroup/2023-03-07-1


*git提交把作者改成自己* git commit --amend --reset-author --no-edit
*ssh生成key* 1) ssh-keygen -t rsa -C '邮件地址@youremail.com' 2) cat ~/.ssh/id_rsa.pub
*git回退版本* git reset --soft 需要回退的commit hash
Expand Down Expand Up @@ -198,3 +195,45 @@ blob代表文件,tree代表文件夹。后者文件大小似乎略小一点。
-------------------------------------------------------------------------------

*打开所有折叠* zR

-------------------------------------------------------------------------------

*bash-help*

*start* WSL用windows打开文件
*WSL创建软链接文件夹* mklinkd 2023-03-07-1 /mnt/d/doc2/group-meeting/readinggroup/2023-03-07-1

*z* 模糊跳转autojump

*vimt* tex
*vimhelp* help
*vimdf* diff

-------------------------------------------------------------------------------

*bash-fzf*

*fzf跳转* fzfcd ALT-C
*fzf补全* CTRL-T:递归搜索当前文件夹下文件
CTRL-R:历史命令

*fzf查找文件夹并跳转* cd ** <TAB>
*rfv* ripgrep grep找文件,fzf模糊查找,最后vim打开文件
*rffv* ripgrep搜索文件,fzf模糊查找,最后vim打开文件
*rga* *rgi* ripgrep查找各种类型的文件
*rga-fzf* ripgrep查找各种类型的文件(不支持pptx),fzf模糊查找,最后打开文件
*rgi-fzf* ripgrep查找各种类型的文件(支持pptx),fzf模糊查找,最后打开文件

-------------------------------------------------------------------------------

*junegunn/fzf-git.sh* https://github.com/junegunn/fzf-git.sh/

CTRL-G CTRL-F for Files
CTRL-G CTRL-B for Branches
CTRL-G CTRL-T for Tags
CTRL-G CTRL-R for Remotes
CTRL-G CTRL-H for commit Hashes
CTRL-G CTRL-S for Stashes
CTRL-G CTRL-E for Each ref (git for-each-ref)

-------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions root/.vim/doc/unused.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Awesome Plugins/Scripts~
=======================================================================================

*glepnir/dashboard-nvim* neovim's dashboard plugin
*mhinz/vim-startify* beautify dashboard, see >
git show v0.2.1:root/vimrc.d/startify.vim
<
Expand Down
5 changes: 5 additions & 0 deletions root/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ alias vimhelp='vim -c ":Lines!" ~/.vim/doc/mydoc.txt'
source ~/vimrc/root/fzf/fzf.bash
source ~/vimrc/root/vimdf

alias rgpipe='~/vimrc/root/rgpipe'
RGPIPE='~/vimrc/root/rgpipe'
alias rgi="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
'*.{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}"

export RIPGREP_CONFIG_PATH="$HOME/.ripgreprc"
32 changes: 32 additions & 0 deletions root/fzf/fzf.bash
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,35 @@ rffv() {
[ -n "${selected[0]}" ] && vim "${selected[0]}" "+${selected[1]}"
}

# https://github.com/ColonelBuendia/rgpipe
rgi-fzf() {
RG_PREFIX="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
'*.{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 $@"
local file
file="$(
RIPGREP_CONFIG_PATH='' \
FZF_DEFAULT_COMMAND="$RG_PREFIX . " \
fzf --sort --preview="[[ ! -z {} ]] && rg -iz --pretty --pre ~/vimrc/root/rgpipe {q} {} | head -n 100" \
--phony -q "" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
start "$file"
}

# https://github.com/phiresky/ripgrep-all
rga-fzf() {
echo $@
RG_PREFIX="RIPGREP_CONFIG_PATH='' rga --no-ignore --files-with-matches $@"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX . " \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
start "$file"
}
91 changes: 91 additions & 0 deletions root/rgpipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/sh
#
# thisdoes: working version of rgpre
# ColonelBuendia was here, 2019-11-20, also later
#
# ubuntu wants: poppler-utils p7zip w3m
# termux wants: poppler p7zip w3m
#
# alias rgi="rg -i -z --max-columns-preview --max-columns 500 --hidden --no-ignore --pre-glob \
# '*.{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"
#
# note to self re: less usage
# export LESSOPEN="|/home/sanchopanda/scripts/rgpipe %s"
# LESSOPEN="|lesspipe.sh %s"
#
# note to self re: fzf usage
# f-cd() { cd $( dirname "$(locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100')") ; }
# f-less() { less `locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100'`; }
# f-subl() { subl `locate -i "$1" | fzf --preview 'rg -iz --pre rgpipe . {} | head -n 100'`; }
#
# note to self re: mobi files
# 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.
# Any notes on how to do this using the existing tools here would be highly appreciated.
#
# note to self re: key files as in apple keynote
# 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.
# garbage methord: unzip -qc "$1" */Slide* */*/Data | strings -n 13
#Some [notes](https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#snappy-compression) on [keynote files](https://github.com/kubo/snzip/issues/14)
#
# Superior tools for more robust usage when doing that
# catdoc, catppt, xls2csv, xlsx2csv, ods2txt, ebook-convert, ssconvert, in2csv, html2csv(pip3 html-to-csv), psc
#

case "$1" in
*.pdf)
# exec pdftotext -q -layout "$1" -
exec rga-preproc "$1"
;;
*.xl[ast][xmt])
exec unzip -qc "$1" *.xml | sed -e 's/<\/[vft]>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.xlsb)
unzip -qc "$1" *.bin | strings -e l
;;
*.xl[wsrta])
exec strings "$1"
;;
*.do[ct])
exec strings -d -15 "$1"
;;
*.do[tc][xm])
exec unzip -qc "$1" word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.p[po]t)
exec strings -d "$1"
;;
*.p[po]t[xm])
exec unzip -qc "$1" ppt/slides/*.xml | sed -e 's/<\/a:t>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*.xhtm)
w3m -T text/html -dump -cols 120 "$1"
;;
*.xhtml)
w3m -T text/html -dump -cols 120 "$1"
;;
*.htm)
w3m -T text/html -dump -cols 120 "$1"
;;
*.html)
exec cat "$1" | w3m -T text/html -dump -cols 120
;;
*.epub)
exec unzip -qc "$1" "*.*htm*" | w3m -T text/html -dump -cols 120
;;
*.chm)
exec 7z e -r -so "$1" *.htm *.xml *.htm *.html *.xhtm *.xhtml | w3m -T text/html -dump -cols 120
;;
*.od[stp])
exec unzip -qc "$1" *.xml | sed -e 's/<\/text:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
;;
*)
case $(file "$1") in
*Zstandard*)
exec pzstd -cdq "$1"
;;
*)
exec cat "$1"
;;
esac
;;
esac
10 changes: 10 additions & 0 deletions root/vimrc.d/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ command! -bang -nargs=? -complete=custom,ListDocs HelpRg
\ {}, <bang>0) |
\ end

function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--disabled', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
let spec = fzf#vim#with_preview(spec, 'right', 'ctrl-/')
call fzf#vim#grep(initial_command, 1, spec, a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
3 changes: 3 additions & 0 deletions setup-ubuntu2204.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ n latest
# npm i -g vscode-langservers-extracted

apt install -y ripgrep fzf fd-find tree bat clangd

# ripgrep-all(master分支)
# apt install ripgrep pandoc poppler-utils ffmpeg

0 comments on commit 117e8df

Please sign in to comment.