feat: added lf
parent
f0c5c90942
commit
aee2aa3461
|
@ -0,0 +1,7 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let printf = "${pkgs.coreutils-full}/bin/printf";
|
||||
in
|
||||
pkgs.writeShellScript "lf-cleaner.sh" ''
|
||||
[ -n "$FIFO_UEBERZUG" ] && ${printf} '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
|
||||
''
|
|
@ -0,0 +1,18 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
pv = pkgs.callPackage ./pv.nix { inherit config pkgs; };
|
||||
lf-wrapper = pkgs.callPackage ./lf-wrapper.nix { inherit config pkgs; };
|
||||
cleaner = pkgs.callPackage ./cleaner.nix { inherit config pkgs; };
|
||||
|
||||
in {
|
||||
home.packages = [ lf-wrapper ];
|
||||
programs.lf = {
|
||||
enable = true;
|
||||
previewer.source = pv;
|
||||
settings.icons = true;
|
||||
extraConfig = ''
|
||||
set cleaner ${cleaner}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
shell = "${pkgs.dash}/bin/dash";
|
||||
lf = "${pkgs.lf}/bin/lf";
|
||||
rm = "${pkgs.coreutils-full}/bin/rm";
|
||||
mkdir = "${pkgs.coreutils-full}/bin/mkdir";
|
||||
mkfifo = "${pkgs.coreutils-full}/bin/mkfifo";
|
||||
ueberzug = "${pkgs.ueberzug}/bin/ueberzug";
|
||||
lfcache = "${config.home.homeDirectory}/.cache/lf";
|
||||
in pkgs.writeScriptBin "lf-wrapper" ''
|
||||
#!${shell}
|
||||
|
||||
set -e
|
||||
|
||||
export LF_ICONS="\
|
||||
tw=:\
|
||||
st=:\
|
||||
ow=:\
|
||||
dt=:\
|
||||
di=:\
|
||||
fi=:\
|
||||
ln=:\
|
||||
or=:\
|
||||
ex=:\
|
||||
*.c=:\
|
||||
*.cc=:\
|
||||
*.clj=:\
|
||||
*.coffee=:\
|
||||
*.cpp=:\
|
||||
*.css=:\
|
||||
*.d=:\
|
||||
*.dart=:\
|
||||
*.erl=:\
|
||||
*.exs=:\
|
||||
*.fs=:\
|
||||
*.go=:\
|
||||
*.h=:\
|
||||
*.hh=:\
|
||||
*.hpp=:\
|
||||
*.hs=:\
|
||||
*.html=:\
|
||||
*.java=:\
|
||||
*.jl=:\
|
||||
*.js=:\
|
||||
*.json=:\
|
||||
*.lua=:\
|
||||
*.md=:\
|
||||
*.php=:\
|
||||
*.pl=:\
|
||||
*.pro=:\
|
||||
*.py=:\
|
||||
*.rb=:\
|
||||
*.rs=:\
|
||||
*.scala=:\
|
||||
*.ts=:\
|
||||
*.vim=:\
|
||||
*.cmd=:\
|
||||
*.ps1=:\
|
||||
*.sh=:\
|
||||
*.bash=:\
|
||||
*.zsh=:\
|
||||
*.fish=:\
|
||||
*.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=:\
|
||||
*.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=:\
|
||||
*.aac=:\
|
||||
*.au=:\
|
||||
*.flac=:\
|
||||
*.m4a=:\
|
||||
*.mid=:\
|
||||
*.midi=:\
|
||||
*.mka=:\
|
||||
*.mp3=:\
|
||||
*.mpc=:\
|
||||
*.ogg=:\
|
||||
*.ra=:\
|
||||
*.wav=:\
|
||||
*.oga=:\
|
||||
*.opus=:\
|
||||
*.spx=:\
|
||||
*.xspf=:\
|
||||
*.pdf=:\
|
||||
*.nix=:\
|
||||
"
|
||||
|
||||
cleanup () {
|
||||
exec 3>&-
|
||||
rm "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
${lf} "$@"
|
||||
else
|
||||
[ ! -d "${lfcache}" ] && ${mkdir} -p "${lfcache}"
|
||||
export FIFO_UEBERZUG="${lfcache}/ueberzug-''$''$"
|
||||
${mkfifo} "$FIFO_UEBERZUG"
|
||||
${ueberzug} layer -s <"$FIFO_UEBERZUG" -p json &
|
||||
exec 3>"$FIFO_UEBERZUG"
|
||||
trap cleanup HUP INT QUIT TERM PWR EXIT
|
||||
${lf} "$@"
|
||||
fi
|
||||
''
|
|
@ -0,0 +1,63 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
file = "${pkgs.file}/bin/file";
|
||||
lynx = "${pkgs.lynx}/bin/lynx";
|
||||
man = "${pkgs.man}/bin/man";
|
||||
col = "${pkgs.util-linux}/bin/col";
|
||||
bat = "${pkgs.bat}/bin/bat";
|
||||
atool = "${pkgs.atool}/bin/atool";
|
||||
odt2txt = "${pkgs.odt2txt}/bin/odt2txt";
|
||||
gpg = "${pkgs.gnupg}/bin/gpg";
|
||||
mediainfo = "${pkgs.mediainfo}/bin/mediainfo";
|
||||
printf = "${pkgs.coreutils-full}/bin/printf";
|
||||
lfcache = "${config.home.homeDirectory}/.cache/lf";
|
||||
stat = "${pkgs.coreutils-full}/bin/stat";
|
||||
readlink = "${pkgs.coreutils-full}/bin/readlink";
|
||||
sha256sum = "${pkgs.coreutils-full}/bin/sha256sum";
|
||||
awk = "${pkgs.gawk}/bin/awk";
|
||||
ffmpegthumbnailer = "${pkgs.ffmpegthumbnailer}/bin/ffmpegthumbnailer";
|
||||
pdftoppm = "${pkgs.poppler_utils}/bin/pdftoppm";
|
||||
in pkgs.writeShellScript "pv.sh" ''
|
||||
|
||||
image() {
|
||||
if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && [ -n "$FIFO_UEBERZUG" ]; then
|
||||
${printf} '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$4" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG"
|
||||
else
|
||||
${mediainfo} "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
get_cache_file () {
|
||||
abs_path=$(${readlink} -f "$1")
|
||||
postfix=$(${stat} --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$abs_path" | ${sha256sum} | ${awk} '{print $1}')
|
||||
echo "${lfcache}/thumb.$postfix"
|
||||
}
|
||||
|
||||
video () {
|
||||
cache=$(get_cache_file "$1")
|
||||
[ ! -f "$cache" ] && ${ffmpegthumbnailer} -i "$1" -o "$cache" -s 0
|
||||
image "$cache" "$2" "$3" "$4" "$5"
|
||||
}
|
||||
|
||||
pdf () {
|
||||
cache=$(get_cache_file "$1")
|
||||
[ ! -f "$cache.jpg" ] && ${pdftoppm} -jpeg -f 1 -singlefile "$1" "$cache"
|
||||
image "$cache.jpg" "$2" "$3" "$4" "$5"
|
||||
}
|
||||
|
||||
case "$(${file} --dereference --brief --mime-type -- "$1")" in
|
||||
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
||||
video/*) video "$1" "$2" "$3" "$4" "$5" ;;
|
||||
*/pdf) pdf "$1" "$2" "$3" "$4" "$5" ;;
|
||||
text/html) ${lynx} -width="$4" -display_charset=utf-8 -dump "$1" ;;
|
||||
text/troff) ${man} ./ "$1" | ${col} -b ;;
|
||||
text/* | */xml) ${bat} --terminal-width "$4" -f "$1" ;;
|
||||
application/zip) ${atool} --list -- "$1" ;;
|
||||
*opendocument*) ${odt2txt} "$1" ;;
|
||||
audio/* | application/octet-stream) ${mediainfo} "$1" || exit 1 ;;
|
||||
application/pgp-encrypted) ${gpg} -d -- "$1" ;;
|
||||
esac
|
||||
|
||||
exit 1
|
||||
''
|
|
@ -22,6 +22,7 @@
|
|||
./gotify
|
||||
./gpg
|
||||
./idasen
|
||||
./lf
|
||||
./mail
|
||||
./maker
|
||||
./minidisc
|
||||
|
|
Loading…
Reference in New Issue