Skip to content

Commit

Permalink
refactor: custom fzf.vim preview script
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Feb 9, 2024
1 parent 79336d3 commit fa2a97d
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 54 deletions.
8 changes: 8 additions & 0 deletions root/.config/nvim/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ local fb_actions = require "telescope._extensions.file_browser.actions"
local telescope = require("telescope")
telescope.setup({
extensions = {
media_files = {
-- filetypes whitelist
-- defaults to {"png", "jpg", "mp4", "webm", "pdf"}
filetypes = {"png", "webp", "jpg", "jpeg"},
-- find command (defaults to `fd`)
find_cmd = "fd"
},
file_browser = {
hijack_netrw = false,
depth = false,
Expand Down Expand Up @@ -52,6 +59,7 @@ telescope.setup({
-- To get telescope-file-browser loaded and working with telescope,
-- you need to call load_extension, somewhere after setup function:
telescope.load_extension "file_browser"
telescope.load_extension "media_files"

require("mason").setup {
ui = {
Expand Down
39 changes: 36 additions & 3 deletions root/.vim/doc/command-line-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,37 @@ pdf转text: pdftotext

json: jq
补全父目录 -> bd
终端查看图片:
- timg
- echo "set terminal png; plot sin(x);" | gnuplot | timg -pi -

-------------------------------------------------------------------------------
*image* 终端查看图片

- *timg*
>
echo "set terminal png; plot sin(x);" | gnuplot | timg -pi -
timg -pi kiga.jpg
<
- cmd.exe /c wezterm imgcat

*wezterm-ssh*
Sixel协议: 在WSL中,需要wezterm ssh [email protected],才能让sixel协议生效
- img2sixel kiga.jpg

wayland:
- swayimg kiga.jpg (https://github.com/artemsen/swayimg)

X11:
- feh kiga.jpg
- sxiv kiga.jpg

uwberzug:
- https://github.com/jstkdng/ueberzugpp
- https://github.com/ueber-devel/ueberzug

*chafa* https://hpjansson.org/chafa/
- chafa kiga.jpg

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

翻译 https://github.com/afc163/fanyi#error-spawn-festival-enoent

>
Expand All @@ -180,6 +206,13 @@ json: jq
|clang-format|

*neofetch* 查看系统信息
*onefetch* 查看git项目信息
https://github.com/o2sh/onefetch
https://onefetch.dev/
>
onefetch --include-hidden
<

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

*github-copilot-cli*
Expand Down
1 change: 1 addition & 0 deletions root/.vim/vimrc.d/floaterm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Plug 'voldikss/fzf-floaterm'
let g:floaterm_opener = 'vsplit'
let g:floaterm_width = 0.8
let g:floaterm_height = 0.8
" imap中F12被映射为UltiSnipsExpandTrigger, see plugin.vim
let g:floaterm_keymap_toggle = '<F12>'
let g:floaterm_title='<F8> kill | <F9> new | <F10> prev | <F11> next | <F12> toggle ($1/$2)'
" 在floaterm中才会生效的快捷键
Expand Down
16 changes: 15 additions & 1 deletion root/.vim/vimrc.d/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ function! s:find_git_root()
return system('git rev-parse --show-toplevel 2> /dev/null')[:-2]
endfunction

" 不要让fzf.vim帮我们定义:Files, :History
command -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--info=inline', '--preview', '$VIMRC_ROOT/scripts/preview.sh {}']}, <bang>0)
function! s:history(arg, bang)
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
if a:arg[0] == ':'
call fzf#vim#command_history(bang)
elseif a:arg[0] == '/'
call fzf#vim#search_history(bang)
else
call fzf#vim#history({'options': ['--info=inline', '--preview', '$VIMRC_ROOT/scripts/preview.sh {}']}, bang)
endif
endfunction
command -bang -nargs=* History call s:history(<q-args>, <bang>0)
" [[palette]]FZF搜索当前项目目录下的文件并打开 :Files
command! ProjectFiles execute 'Files' asyncrun#current_root()
command -nargs=0 ProjectFiles execute 'Files' asyncrun#current_root()

command! -nargs=0 GitUnmergedRaw call fzf#run(fzf#wrap({'source': 'git diff --name-only --diff-filter=U', 'sink': 'e'}))
command! -nargs=0 GitUnmerged call fzf#run(fzf#wrap({'source': 'git diff --name-only --diff-filter=U', 'sink': function('fzf_custom#fzf#mergetool_start')}))
Expand Down
64 changes: 16 additions & 48 deletions root/.vim/vimrc.d/plugin.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""""""""""""""""""""""""" Plugin Config """""""""""""""""""""""""""""

function Cond(cond, ...)
let opts = get(a:000, 0, {})
return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })
Expand All @@ -13,15 +11,6 @@ endfunction
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin(g:vim_plug_dir)

" Test framework
" Plug 'junegunn/vader.vim'

" Test wrapper
Plug 'vim-test/vim-test'
let test#strategy = "asyncrun_background_term"
let test#python#pytest#executable = 'python3 -m pytest'
let test#rust#cargotest#test_options = { 'nearest': ['--', '--nocapture', '--exact'], 'file': [] }

" similar Plugin: Plug 'easymotion/vim-easymotion'
Plug 'justinmk/vim-sneak'
let g:sneak#label = 1
Expand Down Expand Up @@ -64,6 +53,15 @@ if has('nvim') || v:version >= 801
endif

if !exists('g:vscode')
" Test framework
" Plug 'junegunn/vader.vim'

" Test wrapper
Plug 'vim-test/vim-test'
let test#strategy = "asyncrun_background_term"
let test#python#pytest#executable = 'python3 -m pytest'
let test#rust#cargotest#test_options = { 'nearest': ['--', '--nocapture', '--exact'], 'file': [] }

Plug 'mbbill/undotree'
Plug 'aperezdc/vim-template'
let g:templates_no_builtin_templates = 1
Expand Down Expand Up @@ -111,6 +109,7 @@ if !exists('g:vscode')
Plug 'SirVer/ultisnips'
" 大多数情况下使用coc-ultisnips的回车键补全,若遇到tb23
" 这样的补全,使用F12
" nmap中F12被映射为打开终端, see floaterm.vim
let g:UltiSnipsExpandTrigger="<f12>"

" modify some snippets
Expand Down Expand Up @@ -153,41 +152,7 @@ if !exists('g:vscode')
let g:typst_pdf_viewer = 'SumatraPDF.exe'

if has('nvim') && !g:nvim_compatibility_with_vim
" Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

Plug 'nvim-lualine/lualine.nvim'
" If you want to have icons in your statusline choose one of these
Plug 'kyazdani42/nvim-web-devicons'
Plug 'linrongbin16/lsp-progress.nvim'

Plug 'williamboman/mason.nvim'
Plug 'neovim/nvim-lspconfig'
" JSON schema
" Plug 'b0o/schemastore.nvim'
" Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'simrat39/rust-tools.nvim'
Plug 'p00f/clangd_extensions.nvim'
Plug 'simrat39/symbols-outline.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'theHamsta/nvim-dap-virtual-text'
Plug 'folke/neodev.nvim'

Plug 'SmiteshP/nvim-navic'

Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
Plug 'nvim-telescope/telescope-file-browser.nvim'

" completion(use ultisnips)
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'

Plug 'quangnguyen30192/cmp-nvim-ultisnips'
source ~/.vim/vimrc.d/plugin_nvim.vim
else
Plug 'nordtheme/vim', { 'as': 'nordtheme' }
Plug 'dracula/vim', { 'as': 'dracula' }
Expand Down Expand Up @@ -263,6 +228,10 @@ if !exists('g:vscode')
let g:quickui_color_scheme = 'system'
let g:quickui_context = [['hello', 'echo "hello world!"']]
Plug 'pechorin/any-jump.vim'
" Alternative? https://github.com/jasonccox/vim-wayland-clipboard
" See:
" https://github.com/vim/vim/pull/9639
" https://github.com/vim/vim/releases/tag/v9.1.0064
Plug 'ojroques/vim-oscyank', {'branch': 'main'}
" vnoremap <leader>c :OSCYank<CR>

Expand Down Expand Up @@ -335,8 +304,7 @@ if !exists('g:vscode')
" [[palette]]DuckDB执行文件里的SQL,输出到terminal :DuckDBExec foo.sql
command -nargs=1 -complete=file DuckDBExecFile call duckdb#DuckDBExec('.read ' . <q-args>)
"""

endif
endif " !exists('g:vscode')

" Initialize plugin system
call plug#end()
Expand Down
36 changes: 36 additions & 0 deletions root/.vim/vimrc.d/plugin_nvim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
" Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

Plug 'nvim-lualine/lualine.nvim'
" If you want to have icons in your statusline choose one of these
Plug 'kyazdani42/nvim-web-devicons'
Plug 'linrongbin16/lsp-progress.nvim'

Plug 'williamboman/mason.nvim'
Plug 'neovim/nvim-lspconfig'
" JSON schema
" Plug 'b0o/schemastore.nvim'
" Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'simrat39/rust-tools.nvim'
Plug 'p00f/clangd_extensions.nvim'
Plug 'simrat39/symbols-outline.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'theHamsta/nvim-dap-virtual-text'
Plug 'folke/neodev.nvim'

Plug 'SmiteshP/nvim-navic'

Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
Plug 'nvim-telescope/telescope-file-browser.nvim'
Plug 'nvim-telescope/telescope-media-files.nvim'

" completion(use ultisnips)
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'

Plug 'quangnguyen30192/cmp-nvim-ultisnips'
18 changes: 16 additions & 2 deletions root/scripts/preview.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
#!/bin/bash
# Used by `fzf.vim`, `fm`

# Run
# `xdg-mime query filetype <filename>` or
# `file --mime-type -b <filename>`
# to get mime type
case `file --mime-type -b $1` in
inode/directory)
ls --color=always $1 ;;
application/pdf)
pdftotext $1 - ;;
text/*)
bat -p --color=always $1 ;;
if command -v batcat >/dev/null 2>&1; then
catcmd="batcat -p --color=always"
else
catcmd=cat
fi
$catcmd $1 ;;
application/postscript)
timg -g 60x80 $1 ;;
timg -g 60x80 "$1" ;;
application/vnd.openxmlformats-officedocument.presentationml.presentation)
extract-pptx.py "$1" ;;
image/*)
# img2sixel "$1" ;;
# chafa "$1" ;;
timg -g 60x80 "$1" ;;
esac

0 comments on commit fa2a97d

Please sign in to comment.