Fully transit to chafa

- vifm, fzf: revise preview script, update mime types

- nvim: use yaml ft for ansiblels (nvim-lspconfig default is
  yaml.ansible). Also disable codespell
This commit is contained in:
Hoang Nguyen 2022-02-19 20:27:46 +07:00
parent 3498a5a351
commit 3551a249c1
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
15 changed files with 114 additions and 217 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 FollieHiyuki
Copyright (c) 2021-2022 FollieHiyuki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -87,11 +87,17 @@ function M.filetype()
['nftables.conf'] = 'nftables'
},
complex = {
['*_log'] = 'log',
['*_LOG'] = 'log',
['.*waybar/config'] = 'jsonc',
['.*sway/config'] = 'config',
['.*fontconfig/fonts.conf'] = 'xml'
['.*_log$'] = 'log',
['.*_LOG$'] = 'log',
['.*%.config/waybar/config$'] = 'jsonc',
['.*%.config/sway/config$'] = 'config',
['.*%.config/fontconfig/fonts.conf$'] = 'xml',
-- ['.*tasks/.*%.ya?ml$'] = 'yaml.ansible',
-- ['.*roles/.*%.ya?ml$'] = 'yaml.ansible',
-- ['.*playbooks/.*%.ya?ml$'] = 'yaml.ansible',
-- ['.*handlers/.*%.ya?ml$'] = 'yaml.ansible',
-- ['.*group_vars/.*%.ya?ml$'] = 'yaml.ansible',
-- ['.*host_vars/.*%.ya?ml$'] = 'yaml.ansible'
},
shebang = {
nft = 'nftables'

View File

@ -189,6 +189,7 @@ lspconf.gopls.setup {
lspconf.ansiblels.setup {
cmd = {servers_path .. '/ansiblels/node_modules/.bin/ansible-language-server', '--stdio'},
filetypes = {'yaml'},
on_attach = on_attach,
capabilities = capabilities,
single_file_support = false,

View File

@ -41,15 +41,15 @@ local sources = {
-- null_ls.builtins.formatting.stylelint.with {
-- command = linters_path .. '/stylelint/node_modules/.bin/stylelint'
-- },
null_ls.builtins.formatting.codespell.with {
command = linters_path .. '/codespell/venv/bin/codespell'
},
-- null_ls.builtins.formatting.codespell.with {
-- command = linters_path .. '/codespell/venv/bin/codespell'
-- },
-- null_ls.builtins.diagnostics.yamllint,
null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.diagnostics.codespell.with {
command = linters_path .. '/codespell/venv/bin/codespell'
},
-- null_ls.builtins.diagnostics.codespell.with {
-- command = linters_path .. '/codespell/venv/bin/codespell'
-- },
null_ls.builtins.diagnostics.cspell.with {
command = linters_path .. '/cspell/node_modules/.bin/cspell',
extra_args = extra_cspell_args(),

View File

@ -3,11 +3,11 @@
prog=${0##*/}
if [ "$1" = "-a" ]; then
apk list -a | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --multi --prompt "Packages: " --preview 'apk info -a {}'
apk list -a | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --prompt "Packages: " --preview 'apk info -a {}'
elif [ "$1" = "-i" ]; then
apk list -I | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --multi --prompt "Packages: " --preview 'apk info -a {}'
apk list -I | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --prompt "Packages: " --preview 'apk info -a {}'
elif [ "$1" = "-m" ]; then
fzf --multi --prompt "Packages: " --preview 'apk info -a {}' < /etc/apk/world
fzf --prompt "Packages: " --preview 'apk info -a {}' < /etc/apk/world
else
echo "Usage: $prog -a: list all packages
$prog -i: list all installed packages

View File

@ -2,10 +2,10 @@
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm|*.webp) exiftool "$1" || identify "$1" ;;
*.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.og[agx]|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wvc?) exiftool "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpe?g|*.fl[icv]|*.m2v|*.webm|*.m?ts|*.r[am]|*.qt|*.divx|*.as[fx]|*.m4v|*.mov)
exiftool "$1" || fprobe -pretty "$1" 2>&1 ;;
*.png|*.PNG|*.jpg|*.JPG|*.bmp|*.jpeg|*.gif|*.xpm|*.webp|*.WEBP) exiftool "$1" || identify "$1" ;;
*.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.oga|*.ogg|*.ogx|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wv|*.wvc) exiftool "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpeg|*.mpg|*.fli|*.flc|*.flv|*.m2v|*.webm|*.mts|*.qt|*.divx|*.asf|*.asx|*.m4v|*.mov)
exiftool "$1" || fprobe -pretty "$1" 2>&1 ;;
*.pdf) mutool draw -F txt -i -- "$1" 1-10 || pdftotext -l 10 -nopgbrk -q -- "$1" - || exiftool "$1" ;;
*.ps) pstotext "$1" || ps2ascii "$1" ;;
*.epub|*.fb2) pandoc -s -t markdown -- "$1" ;;
@ -24,26 +24,30 @@ case "$1" in
*.iso) isoinfo -l -i "$1" ;;
*.doc) catdoc -- "$1" || pandoc -s -t markdown -- "$1" ;;
*.docx) pandoc -s -t markdown -- "$1" ;;
*.odt|*.ott|*.s[xt]w|*.sxc) pandoc -s -t markdown -- "$1" || odt2txt "$1" ;;
*.odt|*.ott|*.stw|*.sxc) pandoc -s -t markdown -- "$1" || odt2txt "$1" ;;
*.xls) xls2csv -- "$1" ;;
*.xlsx) xlsx2csv -- "$1" ;;
*.ods|*.odp|*.sxw) pandoc -s -t markdown -- "$1" ;;
*.json) jq --color-output . "$1" || python -m json.tool -- "$1" ;;
*.json|*.jsonc) jq --color-output . "$1" || python -m json.tool -- "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
inode/directory)
exa -1a --sort=type --color always --icons "$1" ;;
application/zip|application/x-tar|application/x-gzip)
application/zip|application/x-tar*|application/*-compressed-tar\
|application/vnd.rar|application/x-7z-compressed|application/x-xz*\
|application/x-bzip|application/gzip|application/zstd|application/zlib\
|application/x-lzma|application/x-lzip|application/x-lha|application/x-lhz\
|application/x-lzop|application/x-lz4|application/x-lrzip)
atool -l -q "$1" ;;
image/vnd.djvu)
image/vnd.djvu*)
djvutxt "$1" || exiftool "$1" ;;
image/*)
exiftool "$1" || identify "$1" ;;
exiftool "$1" || identify "$1" ;;
video/*)
exiftool "$1" || fprobe -pretty "$1" 2>&1 ;;
text/*|*/xml)
exiftool "$1" || fprobe -pretty "$1" 2>&1 ;;
text/*)
bat --style plain --color=always "$1" ;;
*)
echo '----- File Type Classification -----' && file --dereference --brief -- "$1" ;;

View File

@ -14,7 +14,7 @@ abbr tmux 'TERM=screen-256color command tmux'
# neovim
abbr v nvim
abbr vi 'fzf --prompt "Edit files: " | xargs -r nvim'
abbr vi 'fzf --prompt "Edit files: " --preview "$HOME/.local/libexec/preview {} 2>/dev/null" | xargs -r nvim'
# emacs
alias doom='$HOME/.config/emacs/bin/doom'

View File

@ -79,7 +79,7 @@ set -gx FZF_DEFAULT_OPTS "--multi --layout=reverse --inline-info
--color info:{{ green }},prompt:{{ blue }},pointer:{{ red }},marker:{{ yellow }},spinner:{{ blue }},header:{{ blue }}"
{% endif %}
set -gx FZF_DEFAULT_COMMAND "fd --type f --follow --hidden --exclude .git --color never"
set -gx FZF_CTRL_T_OPTS "--no-height --preview-window 'left:60%' --preview '$HOME/.local/libexec/preview {} 2>/dev/null'"
set -gx FZF_CTRL_T_OPTS "--no-height --preview '$HOME/.local/libexec/preview {} 2>/dev/null'"
set -gx FZF_CTRL_T_COMMAND "fd . \$dir --follow --hidden --exclude .git --color never"
set -gx FZF_ALT_C_OPTS "--preview 'exa -1a --sort=type --color always --icons {} 2>/dev/null'"
set -gx FZF_ALT_C_COMMAND "fd --type d --follow --hidden --exclude .git --color never"

View File

@ -0,0 +1,55 @@
#!/bin/sh
# https://github.com/eylles/vifm-sixel-preview/pull/2
# https://github.com/vifm/vifm/issues/419#issuecomment-485918513
# require ImageMagick, chafa
thumbnail_dir="$HOME/.cache/vifm/thumbnails"
[ ! -d "${thumbnail_dir}" ] && mkdir -p "${thumbnail_dir}"
WIDTH="$2"
HEIGHT="$3"
TMP="${thumbnail_dir}/thumbnail.$(stat -c '%n%i%F%s%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
_show_graphics() {
exec chafa -s "${WIDTH}x${HEIGHT}" "$1"
}
_preview_video() {
[ ! -f "${TMP}.jpg" ] && ffmpegthumbnailer -i "$1" -o "${TMP}.jpg" -s 0
_show_graphics "${TMP}.jpg"
}
_preview_image() {
[ ! -f "${TMP}.jpg" ] && convert -- "$1"'[0]' "${TMP}.jpg"
_show_graphics "${TMP}.jpg"
}
_preview_font() {
[ ! -f "${TMP}.jpg" ] && ~/.local/libexec/genfontimage "$1" "${TMP}.jpg"
_show_graphics "${TMP}.jpg"
}
case "$1" in
# First check common extensions
*.png|*.PNG|*.jpg|*.JPG|*.bmp|*.jpeg|*.gif|*.xpm|*.webp|*.WEBP) _show_graphics "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpg|*.mpeg|*.fli|*.flc|*.flv|*.m2v|*.webm|*.mts|*.qt|*.divx|*.asf|*.asx|*.m4v|*.mov)
_preview_video "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
image/vnd.djvu*)
djvutxt "$1" || exiftool "$1" ;;
image/*)
_preview_image "$1" ;;
application/x-font*|font/*)
_preview_font "$1" ;;
video/*)
_preview_video "$1" ;;
*)
exit 1 ;;
esac ;;
esac

View File

@ -1,49 +0,0 @@
#!/bin/sh
# require ImageMagick, chafa
[ ! -d "$HOME/.cache/vifm" ] && mkdir -p ~/.cache/vifm
WIDTH="$2"
HEIGHT="$3"
TMP="$HOME/.cache/vifm/thumbnail.$(stat -c '%n%i%F%s%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
_show_kitty() {
exec chafa -f kitty -s "${WIDTH}x${HEIGHT}" "$1"
}
_preview_video() {
[ ! -f "${TMP}.jpg" ] && ffmpegthumbnailer -i "$1" -o "${TMP}.jpg" -s 0
_show_kitty "${TMP}.jpg"
}
_preview_image() {
[ ! -f "${TMP}.jpg" ] && convert -- "$1"'[0]' "${TMP}.jpg"
_show_kitty "${TMP}.jpg"
}
_preview_font() {
[ ! -f "${TMP}.jpg" ] && ~/.local/libexec/genfontimage "$1" "${TMP}.jpg"
_show_kitty "${TMP}.jpg"
}
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm) _show_kitty "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpe?g|*.fl[icv]|*.m2v|*.webm|*.m?ts|*.r[am]|*.qt|*.divx|*.as[fx]|*.m4v|*.mov) _preview_video "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
image/vnd.djvu)
djvutxt "$1" || exiftool "$1" ;;
image/*)
_preview_image "$1" ;;
application/font*|application/*opentype|font/*)
_preview_font "$1" ;;
video/*)
_preview_video "$1" ;;
*)
exit 1 ;;
esac ;;
esac

View File

@ -1,49 +0,0 @@
#!/bin/sh
# require ImageMagick, chafa
[ ! -d "$HOME/.cache/vifm" ] && mkdir -p ~/.cache/vifm
WIDTH="$2"
HEIGHT="$3"
TMP="$HOME/.cache/vifm/thumbnail.$(stat -c '%n%i%F%s%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
_show_symbols() {
exec chafa -f symbols -s "${WIDTH}x${HEIGHT}" "$1"
}
_preview_video() {
[ ! -f "${TMP}.jpg" ] && ffmpegthumbnailer -i "$1" -o "${TMP}.jpg" -s 0
_show_symbols "${TMP}.jpg"
}
_preview_image() {
[ ! -f "${TMP}.jpg" ] && convert -- "$1"'[0]' "${TMP}.jpg"
_show_symbols "${TMP}.jpg"
}
_preview_font() {
[ ! -f "${TMP}.jpg" ] && ~/.local/libexec/genfontimage "$1" "${TMP}.jpg"
_show_symbols "${TMP}.jpg"
}
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm) _show_symbols "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpe?g|*.fl[icv]|*.m2v|*.webm|*.m?ts|*.r[am]|*.qt|*.divx|*.as[fx]|*.m4v|*.mov) _preview_video "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
image/vnd.djvu)
djvutxt "$1" || exiftool "$1" ;;
image/*)
_preview_image "$1" ;;
application/font*|application/*opentype|font/*)
_preview_font "$1" ;;
video/*)
_preview_video "$1" ;;
*)
exit 1 ;;
esac ;;
esac

View File

@ -2,7 +2,7 @@
case "$1" in
# First check common extensions
*.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.og[agx]|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wvc?) exiftool "$1" ;;
*.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.oga|*.ogg|*.ogx|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wvc|*.wv) exiftool "$1" ;;
*.pdf) mutool draw -F txt -i -- "$1" 1-10 || pdftotext -l 10 -nopgbrk -q -- "$1" - || exiftool "$1" ;;
*.ps) pstotext "$1" || ps2ascii "$1" ;;
*.epub|*.fb2) pandoc -s -t markdown -- "$1" ;;
@ -16,11 +16,11 @@ case "$1" in
*.iso) isoinfo -l -i "$1" ;;
*.doc) catdoc -- "$1" || pandoc -s -t markdown -- "$1" ;;
*.docx) pandoc -s -t markdown -- "$1" ;;
*.odt|*.ott|*.s[xt]w|*.sxc) pandoc -s -t markdown -- "$1" || odt2txt "$1" ;;
*.odt|*.ott|*.stw|*.sxc) pandoc -s -t markdown -- "$1" || odt2txt "$1" ;;
*.xls) xls2csv -- "$1" ;;
*.xlsx) xlsx2csv -- "$1" ;;
*.ods|*.odp|*.sxw) pandoc -s -t markdown -- "$1" ;;
*.json) jq --color-output . "$1" || python -m json.tool -- "$1" ;;
*.json|*.jsonc) jq --color-output . "$1" || python -m json.tool -- "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
@ -33,9 +33,13 @@ case "$1" in
else
exa -1a --sort=type --color always --icons "$1"
fi ;;
application/zip|application/x-tar|application/x-rar|application/x-7z-compressed|application/x-xz|application/x-bzip2|application/x-gzip)
application/zip|application/x-tar*|application/*-compressed-tar\
|application/vnd.rar|application/x-7z-compressed|application/x-xz*\
|application/x-bzip|application/gzip|application/zstd|application/zlib\
|application/x-lzma|application/x-lzip|application/x-lha|application/x-lhz\
|application/x-lzop|application/x-lz4|application/x-lrzip)
atool -l -q "$1" ;;
text/*|*/xml)
text/*)
bat --style=plain --color=always "$1" ;;
*)
echo '----- File Type Classification -----' && file --dereference --brief -- "$1" ;;

View File

@ -143,7 +143,7 @@ command! exif exiftool -all= -overwrite_original %f
" fzf file
command! FZFfile : set noquickview
\| let $FZF_RES = term('fzf --prompt "File: " --no-multi --preview-window left --preview "$HOME/.local/libexec/preview {} 2>/dev/null" 2>&0')
\| let $FZF_RES = term('fzf --prompt "File: " --no-multi --preview "$HOME/.local/libexec/preview {} 2>/dev/null" 2>&0')
\| if $FZF_RES != ''
\| execute 'goto' fnameescape($FZF_RES)
\| endif
@ -321,22 +321,19 @@ filextype *.pro qtcreator %f &
" ------------------------------------------------------------------------------
let $GRAPHICS_PREVIEW_MODE = ''
if $TERM == 'foot' || $TERM == 'xterm-256color'
let $GRAPHICS_PREVIEW_MODE = 'sixel'
elseif $TERM == 'xterm-kitty'
let $GRAPHICS_PREVIEW_MODE = 'kitty'
let $GRAPHICS_PREVIEW_MODE = 'ansi'
if $TERM == 'foot'
\ || $TERM == 'wezterm'
\ || $TERM == 'xterm-kitty'
let $GRAPHICS_PREVIEW_MODE = 'graphics'
endif
if $GRAPHICS_PREVIEW_MODE == 'sixel'
fileviewer <image/*>,<video/*>,<application/font*>,<application/*opentype>,<font/*>
\ preview_sixel %c:p %pw %ph %pd 2>/dev/null
elseif $GRAPHICS_PREVIEW_MODE == 'kitty'
fileviewer <image/*>,<video/*>,<application/font*>,<application/*opentype>,<font/*>
\ preview_kitty %c:p %pw %ph %pd %N 2>/dev/null
if $GRAPHICS_PREVIEW_MODE == 'graphics'
fileviewer <image/*>,<video/*>,<application/x-font*>,<font/*>
\ preview_graphics %c:p %pw %ph %pd %N 2>/dev/null
else
fileviewer <image/*>,<video/*>,<application/font*>,<application/*opentype>,<font/*>
\ preview_symbols %c:p %pw %ph 2>/dev/null
fileviewer <image/*>,<video/*>,<application/x-font*>,<font/*>
\ preview_graphics %c:p %pw %ph 2>/dev/null
endif
fileviewer <*> preview_vifm %c:p 2>/dev/null

View File

@ -10,10 +10,3 @@
dest: ~/.config/vifm/
recursive: yes
delete: yes
- name: Copy sixel preview script
template:
src: preview_sixel.j2
dest: ~/.config/vifm/scripts/preview_sixel
force: yes
mode: 0755

View File

@ -1,65 +0,0 @@
#!/bin/sh
# https://github.com/eylles/vifm-sixel-preview/pull/2
# https://github.com/vifm/vifm/issues/419#issuecomment-485918513
# require ImageMagick, chafa
[ ! -d "$HOME/.cache/vifm" ] && mkdir -p ~/.cache/vifm
WIDTH="$2"
HEIGHT="$3"
TMP="$HOME/.cache/vifm/thumbnail.$(stat -c '%n%i%F%s%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
_show_sixel() {
# Default Iosevka specs:
# - The height of letter 'H': 735
# - The height of parentheses '()': 966
# The parentheses cover most distance from the top of 'H' to the bottom of 'j'.
# Therefore, we count it roughly as the height of 1 cell.
# Round the result up to be more accurate.
# Also blindly use 2:1 ratio for characters' height:width.
pixel_width={{ (font_size_px | float / 2.0) | int }}
pixel_height={{ (font_size_px | float / 735.0 * 966.0) | round(0, 'ceil') | int }}
pw=$((WIDTH*pixel_width))
ph=$((HEIGHT*pixel_height))
exec montage "$1" -background "{{ background }}" -geometry "${pw}x${ph}" sixel:-
# exec chafa -f sixel -s "${WIDTH}x${HEIGHT}" "$1"
}
_preview_video() {
[ ! -f "${TMP}.jpg" ] && ffmpegthumbnailer -i "$1" -o "${TMP}.jpg" -s 0
_show_sixel "${TMP}.jpg"
}
_preview_image() {
[ ! -f "${TMP}.jpg" ] && convert -- "$1"'[0]' "${TMP}.jpg"
_show_sixel "${TMP}.jpg"
}
_preview_font() {
[ ! -f "${TMP}.jpg" ] && ~/.local/libexec/genfontimage "$1" "${TMP}.jpg"
_show_sixel "${TMP}.jpg"
}
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm) _show_sixel "$1" ;;
*.avi|*.mp4|*.wmv|*.dat|*.3gp|*.vob|*.ogv|*.mkv|*.mpe?g|*.fl[icv]|*.m2v|*.webm|*.m?ts|*.r[am]|*.qt|*.divx|*.as[fx]|*.m4v|*.mov) _preview_video "$1" ;;
# Then fallback to mimetypes
*)
mimetype=$(file --dereference --brief --mime-type -- "$1")
case "$mimetype" in
image/vnd.djvu)
djvutxt "$1" || exiftool "$1" ;;
image/*)
_preview_image "$1" ;;
application/font*|application/*opentype|font/*)
_preview_font "$1" ;;
video/*)
_preview_video "$1" ;;
*)
exit 1 ;;
esac ;;
esac