Casual cleanup

This commit is contained in:
FollieHiyuki 2021-03-22 18:01:49 +03:00
parent 71241ad12b
commit b1f816c916
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
7 changed files with 106 additions and 93 deletions

View File

@ -90,7 +90,6 @@ cp -rfv ./home/.local/bin/ ~/.local/bin/
# The bloated dotfiles itself
cp -rfv ./home/.mbsyncrc ~/.mbsyncrc
cp -rfv ./home/.rtorrent.rc ~/.rtorrent.rc
# cp -rfv ./home/.elvish/ ~/.elvish/
cp -rfv ./home/.config/alacritty/ ~/.config/alacritty/
cp -rfv ./home/.config/amfora/ ~/.config/amfora/
cp -rfv ./home/.config/anime-downloader/ ~/.config/anime-downloader/
@ -104,7 +103,6 @@ cp -rfv ./home/.config/gallery-dl/ ~/.config/gallery-dl/
cp -rfv ./home/.config/GIMP/ ~/.config/GIMP/
cp -rfv ./home/.config/git/ ~/.config/git/
cp -rfv ./home/.config/gtk-3.0/ ~/.config/gtk-3.0/
# cp -rfv ./home/.config/ion/ ~/.config/ion/
cp -rfv ./home/.config/mpd/ ~/.config/mpd/
cp -rfv ./home/.config/mpDris2/ ~/.config/mpDris2/
cp -rfv ./home/.config/ncmpcpp/ ~/.config/ncmpcpp/
@ -143,12 +141,13 @@ echo "
mkdir -pv ~/.local/share/bash
mkdir -pv ~/.local/share/mpd/playlists
mkdir -pv ~/.local/share/gallery-dl
# tridactyl needs `tridactylrc` to work
# touch ~/.config/tridactyl/tridactylrc
# gpg directory needs strict permissions
# Strict permissions
chmod -v 700 ~/.local/share/gnupg
chmod -v 600 ~/.local/share/gnupg/*
# Just to be safe
chmod -v 600 ~/.config/aria2/aria2.conf
# chsh -s /usr/bin/${shell} ${USER}

View File

@ -3,6 +3,7 @@
# Description: Terminal based file previewer
#
# Note: This plugin needs a "NNN_FIFO" to work. See man.
# For a more extended version of this script with additional optional dependencies, see preview-tui-ext.
#
# Dependencies:
# - Supports 3 independent methods to preview with:
@ -17,7 +18,7 @@
# - tar
# - man
# - optional: bat for code syntax highlighting
# - optional: kitty terminal or catimg for images
# - optional: ueberzug, kitty terminal, viu or catimg for images.
# - optional: scope.sh file viewer from ranger.
# To use:
# 1. drop scope.sh executable in $PATH
@ -57,13 +58,20 @@
# without extra dependencies.
#
# Shell: POSIX compliant
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
SPLIT="$SPLIT" # you can set a permanent split here
TERMINAL="$TERMINAL" # same goes for the terminal
USE_SCOPE="${USE_SCOPE:-0}"
USE_PISTOL="${USE_PISTOL:-0}"
PAGER="${PAGER:-less -R}"
PAGER="${PAGER:-less -P?n -R}"
TMPDIR="${TMPDIR:-/tmp}"
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
[ "$PAGER" = "most" ] && PAGER="less -R"
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
@ -81,7 +89,7 @@ elif [ "$SPLIT" != 'h' ]; then
fi
exists() {
command -v "$1" >/dev/null 2>&1
which "$1" >/dev/null 2>&1
}
fifo_pager() {
@ -113,9 +121,7 @@ print_bin_info() {
}
preview_file () {
kill %- %+ 2>/dev/null && wait %- %+ 2>/dev/null
clear
# Trying to use pistol if it's available.
if [ "$USE_PISTOL" -ne 0 ] && exists pistol; then
fifo_pager pistol "$1"
@ -131,46 +137,36 @@ preview_file () {
# Detecting the exact type of the file: the encoding, mime type, and
# extension in lowercase.
encoding="$(file -Lb --mime-encoding -- "$1")"
mimetype="$(file -Lb --mime-type -- "$1")"
encoding="$(file -bL --mime-encoding -- "$1")"
mimetype="$(file -bL --mime-type -- "$1")"
ext="${1##*.}"
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
lines=$(($(tput lines)-1))
lines=$(tput lines)
cols=$(tput cols)
# Otherwise, falling back to the defaults.
if [ -d "$1" ]; then
cd "$1" || return
if exists tree; then
fifo_pager tree -L 3 -F
fifo_pager tree -L 1 --dirsfirst -F -C
elif exists exa; then
fifo_pager exa -G --colour=always 2>/dev/null
else
fifo_pager ls --color=always
fi
elif [ "$encoding" = "binary" ]; then
if [ "${mimetype%%/*}" = "image" ] ; then
if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method.
kitty +kitten icat --silent --transfer-mode=stream --stdin=no \
"$1" &
elif exists catimg; then
catimg "$1"
elif exists viu; then
viu -t "$1"
else
fifo_pager print_bin_info "$1"
fi
elif [ "$mimetype" = "application/zip" ] ; then
if [ "${mimetype%%/*}" = "image" ]; then
image_preview "$cols" "$lines" "$1"
elif [ "$mimetype" = "application/zip" ]; then
fifo_pager unzip -l "$1"
elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ] ; then
elif [ "$ext" = "gz" ] || [ "$ext" = "bz2" ]; then
fifo_pager tar -tvf "$1"
else
fifo_pager print_bin_info "$1"
fi
elif [ "$mimetype" = "text/troff" ] ; then
elif [ "$mimetype" = "text/troff" ]; then
fifo_pager man -Pcat -l "$1"
else
if exists bat; then
@ -182,21 +178,80 @@ preview_file () {
fi
}
if [ "$PREVIEW_MODE" ] ; then
if [ ! -r "$NNN_FIFO" ] ; then
image_preview() {
if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method.
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no \
"$3"
elif exists ueberzug; then
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
catimg "$3" &
echo "$!" > "$GIFPID"
elif exists viu; then
viu -t "$3" &
echo "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$3"
fi
}
ueberzug_layer() {
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%s", "height": "%s", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
}
ueberzug_remove() {
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
}
ueberzug_refresh() {
clear
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
pkill -f -n preview-tui-ext >/dev/null 2>&1
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_file "$(cat "$CURSEL")"
echo > "$NNN_FIFO"
preview_fifo &
wait
}
if [ "$TERMINAL" != "kitty" ] && [ "$PREVIEW_MODE" ] && exists ueberzug; then
trap 'ueberzug_refresh' WINCH
trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID" "$CURSEL"' INT HUP EXIT
fi
preview_fifo() {
# use cat instead of 'exec <' to avoid issues with dash shell
# shellcheck disable=SC2002
cat "$NNN_FIFO" |\
while read -r selection; do
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
echo "$selection" > "$CURSEL"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
rm "$PAGERPID" "$GIFPID" "$CURSEL" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1
}
if [ "$PREVIEW_MODE" ]; then
if [ ! -r "$NNN_FIFO" ]; then
echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
read -r
exit 1
fi
preview_file "$1"
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
FIFO_UEBERZUG="$TMPDIR/nnn-ueberzug-fifo.$$"
mkfifo "$FIFO_UEBERZUG"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi
# use cat instead of 'exec <' to avoid issues with dash shell
# shellcheck disable=SC2002
cat "$NNN_FIFO" |\
while read -r selection ; do
preview_file "$selection"
done
preview_file "$1"
preview_fifo &
wait
# Restoring the previous layout for kitty users. This will only work for
# kitty >= 0.18.0.

View File

@ -1,9 +1,6 @@
" Basic settings
source $HOME/.config/nvim/general/basic-settings.vim
" polyglot_disabled needs to be set before polyglot being loaded (-_-)
source $HOME/.config/nvim/plug-config/polyglot.vim
" Now load plugins
source $HOME/.config/nvim/vim-plug/vim-plug.vim
@ -21,6 +18,7 @@ source $HOME/.config/nvim/plug-config/delimitMate.vim
source $HOME/.config/nvim/plug-config/doc.vim
source $HOME/.config/nvim/plug-config/doge.vim
source $HOME/.config/nvim/plug-config/easy-align.vim
source $HOME/.config/nvim/plug-config/editorconfig.vim
source $HOME/.config/nvim/plug-config/emmet.vim
source $HOME/.config/nvim/plug-config/far.vim
source $HOME/.config/nvim/plug-config/floaterm.vim
@ -31,6 +29,7 @@ source $HOME/.config/nvim/plug-config/illuminate.vim
source $HOME/.config/nvim/plug-config/indentline.vim
" source $HOME/.config/nvim/plug-config/nerdtree.vim
source $HOME/.config/nvim/plug-config/nnn.vim
source $HOME/.config/nvim/plug-config/polyglot.vim " Load this before using vim-plug if `polyglot_disabled` is set (-_-)
source $HOME/.config/nvim/plug-config/rainbow.vim
source $HOME/.config/nvim/plug-config/rnvimr.vim
source $HOME/.config/nvim/plug-config/rooter.vim

View File

@ -0,0 +1,3 @@
let g:EditorConfig_exclude_patterns = ['fugitive://.*', 'scp://.*']
autocmd FileType gitcommit let b:EditorConfig_disable = 1

View File

@ -1,4 +1,4 @@
let g:polyglot_disabled = ['csv']
" let g:polyglot_disabled = ['csv']
" Haskell
" let g:haskell_classic_highlighting = 1

View File

@ -61,7 +61,7 @@ Plug 'kristijanhusak/vim-dadbod-ui'
" Variables/Functions preview
Plug 'liuchengxu/vista.vim'
" Coding doc generator
Plug 'kkoomen/vim-doge'
Plug 'kkoomen/vim-doge', { 'do': { -> doge#install() } }
" Git
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
@ -85,7 +85,6 @@ Plug 'tpope/vim-commentary'
Plug 'mattn/emmet-vim'
Plug 'tpope/vim-surround'
Plug 'alvan/vim-closetag'
Plug 'AndrewRadev/tagalong.vim'
Plug 'Raimondi/delimitMate'
" Move around
Plug 'unblevable/quick-scope'
@ -102,6 +101,8 @@ Plug 'echuraev/translate-shell.vim'
" Plug 'ron89/thesaurus_query.vim'
" Align text
Plug 'junegunn/vim-easy-align'
" editorconfig
Plug 'editorconfig/editorconfig-vim'
"=================================================
" Fuzzy finder
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
@ -130,8 +131,7 @@ Plug 'Asheq/close-buffers.vim'
Plug 'dbeniamine/cheat.sh-vim'
"=================================================
" Live-server for html
" Run 'npm install --prefix server' in $HOME/.local/share/nvim/plugged/bracey.vim/ to install dependencies
Plug 'turbio/bracey.vim'
Plug 'turbio/bracey.vim', { 'do': 'npm install --prefix server' }
" Markdown
Plug 'mzlogin/vim-markdown-toc'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }

View File

@ -2,46 +2,11 @@
# Preview script for nnn
TMP="/tmp/nnn_thumb.png"
# Handy functions for convenience
preview_img() {
if [ "$TERM" = "xterm-kitty" ]
then
convert -- "$1" "$TMP"
kitty icat --silent "$1"
else
mediainfo "$1" || exiftool "$1" || identify "$1"
fi
}
preview_vid() {
if [ "$TERM" = "xterm-kitty" ]
then
ffmpegthumbnailer -i "$1" -o "$TMP" -s 0
kitty icat --silent "$TMP"
else
mediainfo "$1" || exiftool "$1" || fprobe -pretty "$1" 2>&1
fi
}
# Clear the old image before processing, otherwise shit will happen
if [ "$TERM" = "xterm-kitty" ]
then
kitty icat --silent --clear
fi
case "$1" in
# First check common extensions
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm)
if [ "$TERM" = "xterm-kitty" ]
then
kitty icat --silent "$1"
else
mediainfo "$1" || exiftool "$1" || identify "$1"
fi ;;
*.png|*.jpg|*.bmp|*.jpeg|*.gif|*.xpm) mediainfo "$1" || exiftool "$1" || identify "$1";;
*.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.og[agx]|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wvc?) mediainfo "$1" || 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) preview_vid "$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) mediainfo "$1" || exiftool "$1" || fprobe -pretty "$1" 2>&1;;
*.pdf) mutool draw -F txt -i -- "$1" 1-10 || pdftotext -l 10 -nopgbrk -q -- "$1" - ;;
*.ps) pstotext "$1" || ps2ascii "$1" ;;
*.epub|*.fb2) pandoc -s -t markdown -- "$1" ;;
@ -70,17 +35,9 @@ case "$1" in
image/vnd.djvu)
djvutxt "$1" || exiftool "$1" ;;
image/*)
preview_img "$1" ;;
application/font*|application/*opentype|font/*)
if [ "$TERM" = "xterm-kitty" ]
then
genfontimage "$1" "$TMP"
kitty icat --silent "$TMP"
else
echo '----- Font Classification -----' && file --dereference --brief -- "$1"
fi ;;
mediainfo "$1" || exiftool "$1" || identify "$1";;
video/*)
preview_vid "$1" ;;
mediainfo "$1" || exiftool "$1" || fprobe -pretty "$1" 2>&1;;
text/* | */xml)
bat --style plain --color=always "$1" ;;
*)