From: Andre Ramnitz Date: Fri, 29 Dec 2023 02:29:37 +0000 (+0100) Subject: lf: add config X-Git-Tag: v0.2~262 X-Git-Url: https://git.ramnitz.eu/?a=commitdiff_plain;h=a33831eceeb18059639a86e0a0966b7bef9f7d28;p=dotfiles.git lf: add config ranger-inspired filemanager written in go reminder: image preview with ueberzugpp --- diff --git a/config/lf/clear_img.sh b/config/lf/clear_img.sh new file mode 100755 index 00000000..0402ed3a --- /dev/null +++ b/config/lf/clear_img.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ -n "$FIFO_UEBERZUG" ]; then + printf '{"action": "remove", "identifier": "preview"}\n' >"$FIFO_UEBERZUG" +fi + diff --git a/config/lf/colors b/config/lf/colors new file mode 100644 index 00000000..b65d3f0e --- /dev/null +++ b/config/lf/colors @@ -0,0 +1,174 @@ +# vim:ft=dircolors +# (This is not a dircolors file but it helps to highlight colors and comments) + +# default values from dircolors +# (entries with a leading # are not implemented in lf) +# #no 00 # NORMAL +# fi 00 # FILE +# #rs 0 # RESET +# di 01;34 # DIR +# ln 01;36 # LINK +# #mh 00 # MULTIHARDLINK +# pi 40;33 # FIFO +# so 01;35 # SOCK +# #do 01;35 # DOOR +# bd 40;33;01 # BLK +# cd 40;33;01 # CHR +# or 40;31;01 # ORPHAN +# #mi 00 # MISSING +# su 37;41 # SETUID +# sg 30;43 # SETGID +# #ca 30;41 # CAPABILITY +# tw 30;42 # STICKY_OTHER_WRITABLE +# ow 34;42 # OTHER_WRITABLE +# st 37;44 # STICKY +# ex 01;32 # EXEC + +# default values from lf (with matching order) +# ln 01;36 # LINK +# or 31;01 # ORPHAN +# tw 01;34 # STICKY_OTHER_WRITABLE +# ow 01;34 # OTHER_WRITABLE +# st 01;34 # STICKY +# di 01;34 # DIR +# pi 33 # FIFO +# so 01;35 # SOCK +# bd 33;01 # BLK +# cd 33;01 # CHR +# su 01;32 # SETUID +# sg 01;32 # SETGID +# ex 01;32 # EXEC +# fi 00 # FILE + +# file types (with matching order) +ln 01;36 # LINK +or 31;01 # ORPHAN +tw 34 # STICKY_OTHER_WRITABLE +ow 34 # OTHER_WRITABLE +st 01;34 # STICKY +di 01;34 # DIR +pi 33 # FIFO +so 01;35 # SOCK +bd 33;01 # BLK +cd 33;01 # CHR +su 01;32 # SETUID +sg 01;32 # SETGID +ex 01;32 # EXEC +fi 00 # FILE + +# archives or compressed (dircolors defaults) +*.tar 01;31 +*.tgz 01;31 +*.arc 01;31 +*.arj 01;31 +*.taz 01;31 +*.lha 01;31 +*.lz4 01;31 +*.lzh 01;31 +*.lzma 01;31 +*.tlz 01;31 +*.txz 01;31 +*.tzo 01;31 +*.t7z 01;31 +*.zip 01;31 +*.z 01;31 +*.dz 01;31 +*.gz 01;31 +*.lrz 01;31 +*.lz 01;31 +*.lzo 01;31 +*.xz 01;31 +*.zst 01;31 +*.tzst 01;31 +*.bz2 01;31 +*.bz 01;31 +*.tbz 01;31 +*.tbz2 01;31 +*.tz 01;31 +*.deb 01;31 +*.rpm 01;31 +*.jar 01;31 +*.war 01;31 +*.ear 01;31 +*.sar 01;31 +*.rar 01;31 +*.alz 01;31 +*.ace 01;31 +*.zoo 01;31 +*.cpio 01;31 +*.7z 01;31 +*.rz 01;31 +*.cab 01;31 +*.wim 01;31 +*.swm 01;31 +*.dwm 01;31 +*.esd 01;31 + +# image formats (dircolors defaults) +*.jpg 01;35 +*.jpeg 01;35 +*.mjpg 01;35 +*.mjpeg 01;35 +*.gif 01;35 +*.bmp 01;35 +*.pbm 01;35 +*.pgm 01;35 +*.ppm 01;35 +*.tga 01;35 +*.xbm 01;35 +*.xpm 01;35 +*.tif 01;35 +*.tiff 01;35 +*.png 01;35 +*.svg 01;35 +*.svgz 01;35 +*.mng 01;35 +*.pcx 01;35 +*.mov 01;35 +*.mpg 01;35 +*.mpeg 01;35 +*.m2v 01;35 +*.mkv 01;35 +*.webm 01;35 +*.ogm 01;35 +*.mp4 01;35 +*.m4v 01;35 +*.mp4v 01;35 +*.vob 01;35 +*.qt 01;35 +*.nuv 01;35 +*.wmv 01;35 +*.asf 01;35 +*.rm 01;35 +*.rmvb 01;35 +*.flc 01;35 +*.avi 01;35 +*.fli 01;35 +*.flv 01;35 +*.gl 01;35 +*.dl 01;35 +*.xcf 01;35 +*.xwd 01;35 +*.yuv 01;35 +*.cgm 01;35 +*.emf 01;35 +*.ogv 01;35 +*.ogx 01;35 + +# audio formats (dircolors defaults) +*.aac 00;36 +*.au 00;36 +*.flac 00;36 +*.m4a 00;36 +*.mid 00;36 +*.midi 00;36 +*.mka 00;36 +*.mp3 00;36 +*.mpc 00;36 +*.ogg 00;36 +*.ra 00;36 +*.wav 00;36 +*.oga 00;36 +*.opus 00;36 +*.spx 00;36 +*.xspf 00;36 diff --git a/config/lf/draw_img.sh b/config/lf/draw_img.sh new file mode 100755 index 00000000..ff61491b --- /dev/null +++ b/config/lf/draw_img.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ -n "$FIFO_UEBERZUG" ]; then + path="$(printf '%s' "$1" | sed 's/\\/\\\\/g;s/"/\\"/g')" + printf '{"action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' \ + "$4" "$5" "$2" "$3" "$1" >"$FIFO_UEBERZUG" +fi + diff --git a/config/lf/icons b/config/lf/icons new file mode 100644 index 00000000..92bee5ab --- /dev/null +++ b/config/lf/icons @@ -0,0 +1,357 @@ +#vim:ft=conf + +# These examples require Nerd Fonts or a compatible font to be used. +# See https://www.nerdfonts.com for more information. + +# default values from lf (with matching order) +# ln l # LINK +# or l # ORPHAN +# tw t # STICKY_OTHER_WRITABLE +# ow d # OTHER_WRITABLE +# st t # STICKY +# di d # DIR +# pi p # FIFO +# so s # SOCK +# bd b # BLK +# cd c # CHR +# su u # SETUID +# sg g # SETGID +# ex x # EXEC +# fi - # FILE + +# file types (with matching order) +ln  # LINK +or  # ORPHAN +tw t # STICKY_OTHER_WRITABLE +ow  # OTHER_WRITABLE +st t # STICKY +di  # DIR +pi p # FIFO +so s # SOCK +bd b # BLK +cd c # CHR +su u # SETUID +sg g # SETGID +ex  # EXEC +fi  # FILE + +# file extensions (vim-devicons) +*.styl  +*.sass  +*.scss  +*.htm  +*.html  +*.slim  +*.haml  +*.ejs  +*.css  +*.less  +*.md  +*.mdx  +*.markdown  +*.rmd  +*.json  +*.webmanifest  +*.js  +*.mjs  +*.jsx  +*.rb  +*.gemspec  +*.rake  +*.php  +*.py  +*.pyc  +*.pyo  +*.pyd  +*.coffee  +*.mustache  +*.hbs  +*.conf  +*.ini  +*.yml  +*.yaml  +*.toml  +*.bat  +*.mk  +*.jpg  +*.jpeg  +*.bmp  +*.png  +*.webp  +*.gif  +*.ico  +*.twig  +*.cpp  +*.c++  +*.cxx  +*.cc  +*.cp  +*.c  +*.cs 󰌛 +*.h  +*.hh  +*.hpp  +*.hxx  +*.hs  +*.lhs  +*.nix  +*.lua  +*.java  +*.sh  +*.fish  +*.bash  +*.zsh  +*.ksh  +*.csh  +*.awk  +*.ps1  +*.ml λ +*.mli λ +*.diff  +*.db  +*.sql  +*.dump  +*.clj  +*.cljc  +*.cljs  +*.edn  +*.scala  +*.go  +*.dart  +*.xul  +*.sln  +*.suo  +*.pl  +*.pm  +*.t  +*.rss  +'*.f#'  +*.fsscript  +*.fsx  +*.fs  +*.fsi  +*.rs  +*.rlib  +*.d  +*.erl  +*.hrl  +*.ex  +*.exs  +*.eex  +*.leex  +*.heex  +*.vim  +*.ai  +*.psd  +*.psb  +*.ts  +*.tsx  +*.jl  +*.pp  +*.vue  +*.elm  +*.swift  +*.xcplayground  +*.tex 󰙩 +*.r 󰟔 +*.rproj 󰗆 +*.sol 󰡪 +*.pem  + +# file names (vim-devicons) (case-insensitive not supported in lf) +*gruntfile.coffee  +*gruntfile.js  +*gruntfile.ls  +*gulpfile.coffee  +*gulpfile.js  +*gulpfile.ls  +*mix.lock  +*dropbox  +*.ds_store  +*.gitconfig  +*.gitignore  +*.gitattributes  +*.gitlab-ci.yml  +*.bashrc  +*.zshrc  +*.zshenv  +*.zprofile  +*.vimrc  +*.gvimrc  +*_vimrc  +*_gvimrc  +*.bashprofile  +*favicon.ico  +*license  +*node_modules  +*react.jsx  +*procfile  +*dockerfile  +*docker-compose.yml  +*rakefile  +*config.ru  +*gemfile  +*makefile  +*cmakelists.txt  +*robots.txt 󰚩 + +# file names (case-sensitive adaptations) +*Gruntfile.coffee  +*Gruntfile.js  +*Gruntfile.ls  +*Gulpfile.coffee  +*Gulpfile.js  +*Gulpfile.ls  +*Dropbox  +*.DS_Store  +*LICENSE  +*React.jsx  +*Procfile  +*Dockerfile  +*Docker-compose.yml  +*Rakefile  +*Gemfile  +*Makefile  +*CMakeLists.txt  + +# file patterns (vim-devicons) (patterns not supported in lf) +# .*jquery.*\.js$  +# .*angular.*\.js$  +# .*backbone.*\.js$  +# .*require.*\.js$  +# .*materialize.*\.js$  +# .*materialize.*\.css$  +# .*mootools.*\.js$  +# .*vimrc.*  +# Vagrantfile$  + +# file patterns (file name adaptations) +*jquery.min.js  +*angular.min.js  +*backbone.min.js  +*require.min.js  +*materialize.min.js  +*materialize.min.css  +*mootools.min.js  +*vimrc  +Vagrantfile  + +# archives or compressed (extensions from dircolors defaults) +*.tar  +*.tgz  +*.arc  +*.arj  +*.taz  +*.lha  +*.lz4  +*.lzh  +*.lzma  +*.tlz  +*.txz  +*.tzo  +*.t7z  +*.zip  +*.z  +*.dz  +*.gz  +*.lrz  +*.lz  +*.lzo  +*.xz  +*.zst  +*.tzst  +*.bz2  +*.bz  +*.tbz  +*.tbz2  +*.tz  +*.deb  +*.rpm  +*.jar  +*.war  +*.ear  +*.sar  +*.rar  +*.alz  +*.ace  +*.zoo  +*.cpio  +*.7z  +*.rz  +*.cab  +*.wim  +*.swm  +*.dwm  +*.esd  + +# image formats (extensions from dircolors defaults) +*.jpg  +*.jpeg  +*.mjpg  +*.mjpeg  +*.gif  +*.bmp  +*.pbm  +*.pgm  +*.ppm  +*.tga  +*.xbm  +*.xpm  +*.tif  +*.tiff  +*.png  +*.svg  +*.svgz  +*.mng  +*.pcx  +*.mov  +*.mpg  +*.mpeg  +*.m2v  +*.mkv  +*.webm  +*.ogm  +*.mp4  +*.m4v  +*.mp4v  +*.vob  +*.qt  +*.nuv  +*.wmv  +*.asf  +*.rm  +*.rmvb  +*.flc  +*.avi  +*.fli  +*.flv  +*.gl  +*.dl  +*.xcf  +*.xwd  +*.yuv  +*.cgm  +*.emf  +*.ogv  +*.ogx  + +# audio formats (extensions from dircolors defaults) +*.aac  +*.au  +*.flac  +*.m4a  +*.mid  +*.midi  +*.mka  +*.mp3  +*.mpc  +*.ogg  +*.ra  +*.wav  +*.oga  +*.opus  +*.spx  +*.xspf  + +# other formats +*.pdf  diff --git a/config/lf/lfrc b/config/lf/lfrc new file mode 100644 index 00000000..f76c9284 --- /dev/null +++ b/config/lf/lfrc @@ -0,0 +1,141 @@ +#vim: noai:ft=conf:ts=4:sw=4 + +set previewer ~/.config/lf/previewer.sh +set cleaner ~/.config/lf/clear_img.sh + +# interpreter for shell commands +set shell bash + +# set '-eu' options for shell commands +# These options are used to have safer shell commands. Option '-e' is used to +# exit on error and option '-u' is used to give error for unset variables. +# Option '-f' disables pathname expansion which can be useful when $f, $fs, and +# $fx variables contain names with '*' or '?' characters. However, this option +# is used selectively within individual commands as it can be limiting at +# times. +set shellopts '-eu' + +# set internal field separator (IFS) to "\n" for shell commands +# This is useful to automatically split file names in $fs and $fx properly +# since default file separator used in these variables (i.e. 'filesep' option) +# is newline. You need to consider the values of these options and create your +# commands accordingly. +set ifs "\n" + +# leave some space at the top and the bottom of the screen +set scrolloff 10 + +# use enter for shell commands +# map shell + +# execute current file (must be executable) +# map x $$f +# map X !$f + +# dedicated keys for file opener actions +# map o &mimeopen $f +# map O $mimeopen --ask $f + +# mkdir command. See wiki if you want it to select created dir +# map a :push %mkdir + +# make sure trash folder exists +# %mkdir -p ~/.trash + +# use '' key for either 'trash' or 'delete' command +# map trash +# map delete + +# extract the current file with the right command +# (xkcd link: https://xkcd.com/1168/) +cmd extract ${{ + set -f + case $f in + *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;; + *.tar.gz|*.tgz) tar xzvf $f;; + *.tar.xz|*.txz) tar xJvf $f;; + *.zip) unzip $f;; + *.rar) unrar x $f;; + *.7z) 7z x $f;; + esac +}} + +# compress current file or selected files with tar and gzip +cmd tgz ${{ + set -f + mkdir $1 + cp -r $fx $1 + tar czf $1.tar.gz $1 + rm -rf $1 +}} + +# compress current file or selected files with zip +cmd zip ${{ + set -f + mkdir $1 + cp -r $fx $1 + zip -r $1.zip $1 + rm -rf $1 +}} + +cmd on-select &{{ + lf -remote "send $id set statfmt \"$(eza -ld --color=always "$f")\"" +}} + +cmd fzf_jump ${{ + res="$(find . -maxdepth 1 | fzf --reverse --header='Jump to location')" + if [ -n "$res" ]; then + if [ -d "$res" ]; then + cmd="cd" + else + cmd="select" + fi + res="$(printf '%s' "$res" | sed 's/\\/\\\\/g;s/"/\\"/g')" + lf -remote "send $id $cmd \"$res\"" + fi +}} + +cmd fzf_search ${{ + RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case " + res="$( + FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \ + fzf --bind "change:reload:$RG_PREFIX {q} || true" \ + --ansi --layout=reverse --header 'Search in files' \ + | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g' + )" + [ -n "$res" ] && lf -remote "send $id select \"$res\"" +}} + +# edit config +cmd edit-config ${{ + $EDITOR ~/.config/lf/lfrc + lf -remote "send $id source ~/.config/lf/lfrc" +}} + +cmd toggle_preview %{{ + if [ "$lf_preview" = "true" ]; then + lf -remote "send $id :set preview false; set ratios 1:5" + else + lf -remote "send $id :set preview true; set ratios 1:2:3" + fi +}} + +# go commands +map gc cd ~/.config +map gm cd /mnt +map gM cd /media +map ge bottom +map go :fzf_jump +map gs :fzf_search + +# sort commands} +map sa +map st :{{set sortby time; reverse; set info time;}} +map sT :{{set sortby time; set info time;}} +map ss :{{set sortby size; reverse; set info size;}} +map sS :{{set sortby size; set info size;}} + +# various commands +map zp toggle_preview +map C edit-config + diff --git a/config/lf/previewer.sh b/config/lf/previewer.sh new file mode 100755 index 00000000..a38e527a --- /dev/null +++ b/config/lf/previewer.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +draw() { + ~/.config/lf/draw_img.sh "$@" + exit 1 +} + +hash() { + printf '%s/.cache/lf/%s' "$HOME" \ + "$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')" +} + +cache() { + if [ -f "$1" ]; then + draw "$@" + fi +} + +file="$1" +shift + +if [ -n "$FIFO_UEBERZUG" ]; then + case "$(file -Lb --mime-type -- "$file")" in + image/*) + orientation="$(identify -format '%[EXIF:Orientation]\n' -- "$file")" + if [ -n "$orientation" ] && [ "$orientation" != 1 ]; then + cache="$(hash "$file").jpg" + cache "$cache" "$@" + convert -- "$file" -auto-orient "$cache" + draw "$cache" "$@" + else + draw "$file" "$@" + fi + ;; + video/*) + cache="$(hash "$file").jpg" + cache "$cache" "$@" + ffmpegthumbnailer -i "$file" -o "$cache" -s 0 + draw "$cache" "$@" + ;; + application/pdf) + thumbnail="$LF_TEMPDIR/thumbnail.png" + gs -o "$thumbnail" -sDEVICE=pngalpha -dLastPage=1 "$file" >/dev/null + preview "$thumbnail" "$@" + ;; + application/tar*) + tar tf "$file" + ;; + application/zip) + unzip -l "$file" + ;; + application/7z) + 7z l "$file" + ;; + *) + bat -f --style plain "$file" + ;; + esac +fi + +# shellcheck disable=SC2154 +file -Lb -- "$1" | fold -s -w "$width" +exit 0 + diff --git a/config/lf/scope-lf-wrapper.sh b/config/lf/scope-lf-wrapper.sh new file mode 100755 index 00000000..dbb7d794 --- /dev/null +++ b/config/lf/scope-lf-wrapper.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +"$HOME/.config/ranger/scope.sh" "${1}" "${2}" "${3}" "" "" || true +