This commit is contained in:
Sebastian Moser
2023-11-29 09:56:23 +01:00
parent 1aba4bff44
commit 3726e3ff6d
21 changed files with 1843 additions and 73 deletions

View File

@@ -46,7 +46,7 @@
style = "Bold Italic";
};
size = 9;
size = 8;
};
# Dracula theme for alacritty

View File

@@ -1,4 +1,4 @@
{ persistentDir, confDir, hostname, self, ... }:
{ persistentDir, confDir, hostname, self, pkgs, config, ... }:
{
programs.bash = {
@@ -42,6 +42,8 @@
};
shellAliases = {
cdd = "/sdcard";
n = "${pkgs.python3} ${self}/scripts/nav/main.py";
shutdown = "echo try harder.... xD";
npw = "nmcli c up pw";
flex = "neofetch | lolcat";
@@ -75,16 +77,21 @@
export TERM="xterm-color"
# my prompt
if [[ "$(hostname)" == "main" ]]
if [[ "${config.hostname}" == "main" ]]
then
export PS1="\[\033[01;34m\]\W\[\033[00m\]\[\033[01;32m\]\[\033[00m\] "
else
export PS1="\033[1;32m$(hostname) \[\033[01;34m\]\W\[\033[00m\]\[\033[01;32m\]\[\033[00m\] "
export PS1="\033[1;32m${config.hostname} \[\033[01;34m\]\W\[\033[00m\]\[\033[01;32m\]\[\033[00m\] "
fi
# source lfcd
source ${pkgs.lf.src}/etc/lfcd.sh
alias lf="lfcd"
# so that programms i spawn from my shell don't have so high cpu priority
renice -n 9 $$ > /dev/null
[[ which renice 2>/dev/null ]] && renice -n 9 $$ > /dev/null
# If not running interactively, don't do anything
@@ -103,6 +110,38 @@
#################### functions ####################
# shortcut for copying over to tab
tta(){
if [[ "$1" == "" ]]
then
scp -O ~/work/priv-share/fast tab:/sdcard/fast
elif [[ "$1" == "p" ]]
then
scp -O tab:/sdcard/fast ~/work/priv-share/fast
elif [[ "$1" == "k" ]]
then
scp -O "$1" tab:/sdcard/keep
else
scp -O "$1" tab:/sdcard/fast/
fi
}
tph(){
if [[ "$1" == "" ]]
then
scp ~/work/priv-share/fast phone:/sdcard/fast
elif [[ "$1" == "p" ]]
then
scp phone:/sdcard/fast ~/work/priv-share/fast
elif [[ "$1" == "k" ]]
then
scp -O "$1" tab:/sdcard/keep
else
scp "$1" phone:/sdcard/fast/
fi
}
# A shortcut function that simplifies usage of xclip.
# - Accepts input from either stdin (pipe), or params.
# ------------------------------------------------
@@ -139,12 +178,12 @@
# a little programm, that changes the ssh config to always be able to acces rpi
function rpi(){
sudo rm /etc/hosts
sudo su -c "cat ${self}/misc/my-hosts > /etc/hosts"
sudo su -c "cat ${self}/misc/my-hosts-$1 >> /etc/hosts"
sudo su -c "echo -en "$1" > /etc/current_hosts"
}
#function rpi(){
##sudo rm /etc/hosts
#sudo su -c "cat ${self}/misc/my-hosts > /etc/hosts"
#sudo su -c "cat ${self}/misc/my-hosts-$1 >> /etc/hosts"
#sudo su -c "echo -en "$1" > /etc/current_hosts"
#}
# git commit func

4
programs/lf/cleaner Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
if [ -n "$FIFO_UEBERZUG" ]; then
printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG"
fi

200
programs/lf/colors Normal file
View File

@@ -0,0 +1,200 @@
# Colors for filenames in lf
# file types (with matching order)
ln 01;36 # LINK
or 31;01 # ORPHAN
tw 38;5;47 # STICKY_OTHER_WRITABLE
ow 38;5;47 # 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
*.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
*.xpi 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
*.jpg 38;5;202
*.JPG 38;5;202
*.jpeg 38;5;202
*.mjpg 38;5;202
*.mjpeg 38;5;202
*.jxl 38;5;202
*.JXL 38;5;202
*.webp 38;5;202
*.gif 38;5;202
*.bmp 38;5;202
*.pbm 38;5;202
*.pgm 38;5;202
*.ppm 38;5;202
*.tga 38;5;202
*.xbm 38;5;202
*.xpm 38;5;202
*.tif 38;5;202
*.tiff 38;5;202
*.png 38;5;202
*.svg 38;5;202
*.svgz 38;5;202
*.mng 38;5;202
*.odg 38;5;202
*.pcx 38;2;218;8;255
*.mov 38;2;218;8;255
*.mpg 38;2;218;8;255
*.mpeg 38;2;218;8;255
*.m2v 38;2;218;8;255
*.mkv 38;2;218;8;255
*.webm 38;2;218;8;255
*.ogm 38;2;218;8;255
*.mp4 38;2;218;8;255
*.m4v 38;2;218;8;255
*.mp4v 38;2;218;8;255
*.vob 38;2;218;8;255
*.qt 38;2;218;8;255
*.nuv 38;2;218;8;255
*.wmv 38;2;218;8;255
*.asf 38;2;218;8;255
*.rm 38;2;218;8;255
*.rmvb 38;2;218;8;255
*.flc 38;2;218;8;255
*.avi 38;2;218;8;255
*.fli 38;2;218;8;255
*.flv 38;2;218;8;255
*.gl 38;2;218;8;255
*.dl 38;2;218;8;255
*.xcf 38;2;218;8;255
*.xwd 38;2;218;8;255
*.yuv 38;2;218;8;255
*.cgm 38;2;218;8;255
*.emf 38;2;218;8;255
*.ogv 38;2;218;8;255
*.ogx 38;2;218;8;255
# audio formats
*.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
# other formats
*.pdf 38;2;249;46;73
*.PDF 38;2;249;46;73
*.ps 38;2;249;46;73
*.epub 38;2;249;46;73
*.mobi 38;2;249;46;73
*.ods 92
*.xls 92
*.XLS 92
*.xlsx 92
*.XLSX 92
*.odt 94
*.doc 94
*.DOC 94
*.docx 94
*.DOCX 94
*.odp 38;2;249;62;0
*.ppt 38;2;249;62;0
*.PPT 38;2;249;62;0
*.pptx 38;2;249;62;0
*.PPTX 38;2;249;62;0
*.iso 38;5;221
*.img 38;5;221
*.py 38;5;220
*.lua 38;5;39
*.js 38;5;226
*.htm 38;5;202
*.html 38;5;202
*.shtml 38;5;202
*.xhtml 38;5;202
*.css 38;5;39
*.go 38;5;39
*.php 38;5;75
*.tex 38;5;36
*.c 38;2;121;168;244
*.cpp 38;2;141;116;244
*.cs 38;2;203;121;244
*.nim 38;5;220
*.nims 38;5;220
*.r 38;5;39
*.R 38;5;39
*.rs 38;2;225;105;0
*.pl 38;2;0;115;255
*.raku 38;2;225;0;221
*.m 38;2;225;43;7
*.java 38;2;225;136;0
*.scala 38;5;196
*.rb 38;5;196
*.vim 32
*.sql 38;5;249
*.sqlite 38;5;249
*.db 38;5;249
*.odb 38;5;249
*.apk 38;5;82
*.apk 38;5;82
*.jl 38;5;147
*.hs 38;5;133
*.lhs 38;5;133
*.blend 38;5;208

View File

@@ -1,12 +1,84 @@
{ pkgs, ... }:
{ pkgs, self, confDir, ... }@params:
{
programs.lf = {
package = pkgs.lf.overrideAttrs (final: prev: {
patches = (prev.patches or [ ]) ++ [
./lf-filter.patch
];
checkPhase = "";
});
home.file.".config/lf/icons".source = "${self}/programs/lf/icons";
programs.lf = let
mylf = pkgs.lf.overrideAttrs (final: prev: {
patches = (prev.patches or [ ]) ++ [
./lf-filter.patch
];
checkPhase = "";
});
myPreviewer = pkgs.writeShellApplication {
name = "myPreviewer";
runtimeInputs = with pkgs; [
file
bat # (text)
ueberzug # (images, videos, pdf, fonts)
ffmpegthumbnailer # (videos)
exiftool # (metadata/audio, and file detection for .webm files)
jq # (json and metadata)
lynx # (html/web pages)
poppler_utils # pdftoppm # (pdf)
odt2txt # (odt)
imagemagick # convert from imagemagick (fonts)
atool # (archives)
gnupg # (PGP encrypted files)
man # (troff manuals)
busybox # other
];
text = builtins.readFile "${self}/programs/lf/previewer";
};
mylfWrapper = pkgs.writeShellApplication {
name = "lf";
#runtimeInputs = with pkgs; [ curl w3m ];
text = ''
# got it FROM: https://codeberg.org/tplasdio/lf-config/src/branch/main/.local/bin/lfub
# Envolvedor de lf, que permite crear previsualizaciones de imágenes
# con ueberzug, en conjunto con mi configuración 'previewer' y 'cleaner' para lf
# Taken from: https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/lfub
# TODO:
# - Capturar cuando se cierre/mate la ventana conteniendo la terminal que corre
# este script, pues si no se quedarán procesos huérfanos 'lf' 'lfub' 'ueberzug'
set -e
set +u
: "''${XDG_CACHE_HOME:="''${HOME}/.cache"}"
cleanup() {
exec 3>&-
# FIXME:
# after SIGINT commands that expected some arguments, previews for that directory
# are stuck in "loading", because there's no fifo file to remove or something
# Example:
# gpg -d # Forgot to type $f for decrypting a file
# Ctrl-C # Back to lf, previews are stuck
rm "$FIFO_UEBERZUG"
}
main() {
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
${mylf}/bin/lf "$@"
else
[ -d "''${XDG_CACHE_HOME}/lf" ] || mkdir -p "''${XDG_CACHE_HOME}/lf"
export FIFO_UEBERZUG="''${XDG_CACHE_HOME}/lf/ueberzug-$$"
mkfifo "$FIFO_UEBERZUG"
${pkgs.ueberzug}/bin/ueberzug layer -s < "$FIFO_UEBERZUG" -p json &
exec 3> "$FIFO_UEBERZUG"
trap cleanup HUP INT QUIT TERM PWR EXIT
${mylf}/bin/lf "$@" 3>&-
fi
}
main "$@" || exit $?
'';
};
in
{
package = mylfWrapper;
enable = true;
commands = {
@@ -19,13 +91,33 @@
mkdir $DIR
}}
'';
nav = ''
%{{${pkgs.python3}/bin/python3 ${confDir}/scripts/nav/main.py --mode lf}}
'';
nav-home = ''
%{{
${pkgs.python3}/bin/python3 ${confDir}/scripts/nav/main.py --mode lf --char H
}}
'';
nav-work = ''
%{{
${pkgs.python3}/bin/python3 ${confDir}/scripts/nav/main.py --mode lf --char W
}}
'';
};
settings = {
preview = true;
icons = true;
drawbox = true;
icons = true;
};
keybindings = {
F = "setfilter";
P = "%pwd";
W = "nav-work";
H = "nav-home";
n = "nav";
"." = "set hidden!";
"<enter>" = "open";
do = "dragon-out";
@@ -34,5 +126,38 @@
ee = "editor-open";
V = ''$${pkgs.bat}/bin/bat --paging=always --theme=gruvbox "$f"'';
};
extraConfig = ''
%test $LF_LEVEL -eq 1 || >&2 printf "Warning: You're in a nested lf instance!"
# export pid and ppid
''${{
myPID=$(ps -j | grep lf | tail -n 1 | awk '{print $1}')
myPGID=$(ps -j | grep lf | tail -n 1 | awk '{print $2}')
lf -remote "send $id set user_pid $myPID"
lf -remote "send $id set user_pgid $myPGID"
}}
source ${self}/programs/lf/opener
set cleaner "${self}/programs/lf/cleaner"
set cursorpreviewfmt "\033[7m"
set previewer "${myPreviewer}/bin/myPreviewer"
set period "1"
#set promptfmt "
#\033[48;2;35;38;39;38;2;28;220;156m
#\033[38;2;35;38;39;48;2;202;31;31m
#\033[38;2;202;31;31;48;2;40;47;62m
#\033[38;2;255;255;255m %w
#\033[38;2;40;47;62;48;2;58;67;89m
#\033[38;2;255;255;255m %f
#\033[;38;2;58;67;89;49m\033[m"
set timefmt "2023-11-28 15:04:05 "
set waitmsg "\033[1;31m\033[m"
set tabstop 4
set shellopts "-eu"
set ifs "\n"
set shell "bash"
set ruler "df:acc:progress:selection:filter:ind"
'';
};
}

455
programs/lf/icons Normal file
View File

@@ -0,0 +1,455 @@
# Icons for lf
# These icons require Nerd Fonts and emojis in a compatible font for terminals
# See https://www.nerdfonts.com for more information.
# Note: some double space emojis/icons render as 1-character width in some
# terminals and as 2-character width in others. I'm adjusting them to make
# them look aligned in the 'Alacritty' terminal
# file types (with matching order)
ln 🔗 # LINK
or ❌ # ORPHAN
tw 🍃 # STICKY_OTHER_WRITABLE
ow 📂 # OTHER_WRITABLE
st 🔖 # STICKY
di 📁 # DIR
pi " " # FIFO
so 🔌 # SOCK
bd 🧱 # BLK
cd " " # CHR
su 🦸 # SETUID
sg 👥 # SETGID
ex 🎯 # EXEC
fi 📄 # FILE
# file extensions (vim-devicons)
*.styl " "
*.sass " "
*.scss " "
*.htm " "
*.html " "
*.xhtml " "
*.shtml " "
*.slim " "
*.haml " "
*.ejs " "
*.css " "
*.qss " "
*.rasi " "
*.less " "
*.wiki " "
*.md " "
*.mdx " "
*.markdown " "
*.rmd " "
*.Rmd " "
*.xml " "
*.json " "
*.bson " "
*.webmanifest " "
*.js " "
*.mjs " "
*.jsx " "
*.rb " "
*.gemspec " "
*.rake " "
*.php " "
*.py " "
*.pyc " "
*.pyo " "
*.pyd " "
*.ipynb " "
*.nim "👑"
*.nims "👑"
*.coffee " "
*.mustache " "
*.hbs " "
*.conf "⚙ "
*.ini "⚙ "
*.yml "⚙ "
*.yaml "⚙ "
*.toml "⚙ "
*.mk "⚙ "
*.twig " "
*.cpp " "
*.c++ " "
*.cxx " "
*.cc " "
*.cp " "
*.c " "
*.cs " "
*.h " "
*.hh " "
*.hpp " "
*.hxx " "
*.hs " "
*.lhs " "
*.nix " "
*.lua " "
*.java " "
*.sh " "
*.fish " "
*.bash " "
*.zsh " "
*.ksh " "
*.csh " "
*.awk " "
*.sed " "
*.m4 " "
*.cmd " "
*.bat " "
*.ps1 " "
*.ml " λ"
*.mli " λ"
*.diff " "
*.db " "
*.odb " "
*.sql " "
*.sqlite " "
*.dump " "
*.mongo " "
*.rdb " "
*.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 " ﳒ"
*.R " ﳒ"
*.rproj "鉶"
*.sol " ﲹ"
*.apk " "
*.xapk " "
*.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 "⚙ "
*.git " "
*.gitconfig " "
*.gitignore " "
*.gitattributes " "
*.gitlab-ci.yml " "
*bashrc "⚙ "
*.zshrc "⚙ "
*.zshenv "⚙ "
*.zprofile "⚙ "
*.vimrc " "
*.gvimrc " "
*_vimrc " "
*_gvimrc " "
*.bashprofile "⚙ "
*favicon.ico " "
*license "📜"
*licence "📜"
*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 "📜"
*LICENCE "📜"
*COPYING "📜"
*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
*.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 📦
*.xpi 📦
# image and video extensions
*.jpg 📸
*.JPG 📸
*.jpeg 📸
*.JPEG 📸
*.jpe 📸
*.mjpg 📸
*.mjpeg 📸
*.jxl "🖼 "
*.JXL "🖼 "
*.svg "🗺 "
*.svgz "🗺 "
*.bmp "🖼 "
*.pbm "🖼 "
*.pgm "🖼 "
*.ppm "🖼 "
*.tga "🖼 "
*.xbm "🖼 "
*.xpm "🖼 "
*.tif "🖼 "
*.tiff "🖼 "
*.png "🖼 "
*.PNG "🖼 "
*.webp "🖼 "
*.mng "🖼 "
*.pcx "🖼 "
*.ico "🖼 "
*.gif "🎞 "
*.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 🎥
*.kdenlive 🎬
*.prproj 🎬
# audio extensions
*.wav 🎼
*.aac 🎵
*.au 🎵
*.flac 🎵
*.m4a 🎵
*.mid 🎵
*.midi 🎵
*.mka 🎵
*.mp3 🎵
*.mpc 🎵
*.ogg 🎵
*.ra 🎵
*.oga 🎵
*.opus 🎵
*.spx 🎵
*.xspf 🎵
# other extensions
*.elf " "
*.exe " "
*.appx " "
*.msi " "
*.app " "
*.pdf " "
*.PDF " "
*.ps " "
*.txt 📝
*.TXT 📝
*.csv 📓
*.CSV 📓
*.tsv 📓
*.djvu 📚
*.epub 📚
*.torrent 📥
*.magnet 🧲
*.lrc 🎤
*.kar 🎤
*.src 💬
*.gpg 🔐
*.ssh 🔑
*.key 🔑
*.rsa 🔑
*.pem 🔑
*.sig 🪪
*.asc "🕵 "
*.manifest 📜
*.log 📙
*.xopp 📔
*.iso 📀
*.img 📀
*.bib 🎓
*.nfo " "
*.info " "
*.m 📊
*.ods 📗
*.xls 📗
*.XLS 📗
*.xlsx 📗
*.XLSX 📗
*.odt 📘
*.doc 📘
*.DOC 📘
*.docx 📘
*.DOCX 📘
*.odp 📕
*.ppt 📕
*.PPT 📕
*.pptx 📕
*.PPTX 📕
*.odg "🖼 "
*.krita "🖌 "
*.kra "🖌 "
*.xcf "🖌 "
*.eml 📧
*.mom "✍ "
*.me "✍ "
*.ms "✍ "
*.groff "✍ "
*.tbl "✍ "
*.pic "✍ "
*.blend " "
*.ffpreset " "
*.bak "🗃 "
*.desktop "🖥 "
*.z64 🎮
*.v64 🎮
*.n64 🎮
*.gba 🎮
*.nes 🎮
*.gdi 🎮
*.gam 🎮
*.sav 🎮
*.scm 🎮
*.bin 🎮
*.psv 🎮
*.rom 🎮
*.xex 🎮
*.jrz 🎮
*.efi " "
# vim:ft=conf

1
programs/lf/lf-config Submodule

Submodule programs/lf/lf-config added at 1c295ce7bc

242
programs/lf/opener Normal file
View File

@@ -0,0 +1,242 @@
# Opener for lf
# En general, deberías delegar la apertura de ficheros a tu abridor de
# recursos (e.g. xdg-open, mimeo), recomiendo ponerlo en la variable de
# entorno $OPENER y luego configurar sus reglas de asociaciones entre tipos
# MIME y lanzadores .desktop (e.g. ~/.config/applications/mimeapps.list)
# Sin embargo, acá se puede programar comportamiento más avanzado basado
# en más características de los ficheros y/o específicamente para lf
# Tipos MIME IANA oficiales: https://www.iana.org/assignments/media-types/media-types.xhtml
cmd open ${{
# Demonizador de comandos, en orden de preferencia
dem() {
{ setsid -f "$@" >/dev/null 2>&1& } \
|| ({ nohup "$@" >/dev/null 2>&1& } &) \
|| (exec "$@" >/dev/null 2>&1&)
}
real_f="$(readlink -f $f || realpath $f)" \
mime_type="$(\
exiftool -s3 -MIMEType "$real_f" 2>/dev/null \
|| file --dereference -b --mime-type -- "$real_f" 2>/dev/null
)"
case "$mime_type" in
(application/pdf | application/postscript | image/vnd.djvu | application/epub*)
dem "${READER:-zathura}" $fx
;;
(text/html)
case "${f##*.}" in
(xls) dem localc $f ;;
(*) "${EDITOR:-nvim}" $fx
esac
;;
(text/troff)
case "${f##*.}" in
([0-9] | [01]p | [23]*) man $fx ;;
(*) "${EDITOR:-nvim}" $fx
esac
;;
( text/* | application/json | application/javascript | \
application/pgp-encrypted | inode/x-empty | application/octet-stream | \
application/x-gettext-translation )
"${EDITOR:-nvim}" $fx
;;
(image/x-*)
dem "${IMAGE_EDITOR:-gimp}" $fx
;;
(image/* )
case "$(tty)" in
("/dev/tty"*) # En tty imágenes pueden ser mostradas con mpv
"${MPV:-mpv}" --keep-open $fx
;;
(*) dem "${IMAGE_VIEWER:-vimiv}" $fx
esac
;;
(audio/*)
case "$(tty)" in
("/dev/tty"*) # No demonizar en tty
"${AUDIO_PLAYER:-"${MPV:-mpv}"}" --audio-display=no $fx
;;
(*) dem "${TERMINAL:-alacritty}" -e "${AUDIO_PLAYER:-"${MPV:-mpv}"}" --audio-display=no $fx
esac
;;
(video/*)
case "$(tty)" in
("/dev/tty"*) # No demonizar en tty
"${VIDEO_PLAYER:-"${MPV:-mpv}"}" $fx
;;
# TODO: handle video/webm like previewer
(*) dem "${VIDEO_PLAYER:-"${MPV:-mpv}"}" $fx
esac
;;
(application/vnd.sqlite3)
sqlite3 $fx
;;
# text/xml)
# ;;
(application/zip)
case "${f##*.}" in
(kra) dem krita $f ;;
(*)
for f in $fx; do
"${OPENER:-xdg-open}" $f
done
esac
;;
(*)
case "$f" in
# TODO: redo this with mime types, not extensions
( *.tar.bz | *.tar.bz2 | *.tbz | \
*.tbz2 | *.tar.gz | *.tgz | *.tar.lzma | \
*.tar.xz | *.txz | *.zip | *.rar | *.iso)
mntdir="$f-archivemount"
if ! [ -d "$mntdir" ]; then
mkdir -- "$mntdir"
archivemount "$f" "$mntdir"
printf -- "%s\n" "$mntdir" >> "/tmp/__lf_archivemount_$id"
fi
lf -remote "send $id cd '$mntdir'"
lf -remote "send $id reload"
;;
esac
# Delegate opening to resource opener
#pwhich() {
# hash "$1" >/dev/null 2>&1 && command -v -- "$1"
#}
#[ "$OPENER" ] || OPENER=$(pwhich xdg-open)
for f in $fx; do
dem "${OPENER:-xdg-open}" $f
#"${OPENER:-"${EDITOR:-nvim}"}" $f
# ${OPENER:-"xdg-open"} $f || "${EDITOR:-"nvim"}" $f
done
;;
esac
}}
# Bug: In my AwesomeWM some JPGs or webm don't show the window until is tiled
cmd openwith ${{
dem() {
{ setsid -f "$@" >/dev/null 2>&1& } \
|| ({ nohup "$@" >/dev/null 2>&1& } &) \
|| (exec "$@" >/dev/null 2>&1&)
}
real_f="$(readlink -f $f || realpath $f)" \
mime_type="$(\
exiftool -s3 -MIMEType "$real_f" \
|| file --dereference -b --mime-type -- "$real_f"
)"
menu_select() {
nl -nln | fzf --with-nth 2.. | cut -d' ' -f1
}
# TODO: hacer que se puedan abrir con múltiples a la vez (fzf +m)
case "$mime_type" in
( text/* | application/json | application/javascript | \
application/pgp-encrypted | inode/x-empty | application/octet-stream )
app=$(menu_select <<-\EOF
$EDITOR
$EDITOR (new terminal)
nano
nano (new terminal)
EOF
)
case "$app" in
(1) "${EDITOR:-nvim}" $fx ;;
(2) dem "${TERMINAL:-alacritty}" -e "$EDITOR" $fx ;;
(3) nano $fx ;;
(4) dem "${TERMINAL:-alacritty}" -e nano $fx ;;
esac
;;
(image/svg+xml | image/png | image/jpeg | image/gif )
app=$(menu_select <<-\EOF
vimiv
gimp
mpv
krita
inkscape
EOF
)
case "$app" in
(1) dem vimiv $fx ;;
(2) dem gimp $fx ;;
(3)
case "$(tty)" in
# Demonizing on tty makes it impossible to quit
("/dev/tty"*) "${MPV:-mpv}" --keep-open=yes $fx ;;
(*) dem "${MPV:-mpv}" --keep-open=yes $fx ;;
esac
;;
(4) dem krita $fx ;;
(5) dem inkscape $fx ;;
esac
;;
(image/x-*)
app=$(menu_select <<-\EOF
gimp
vimiv
mpv
EOF
)
case "$app" in
(1) dem gimp $fx ;;
(2) dem vimiv $fx ;;
(3)
case "$(tty)" in
# Demonizing on tty makes it impossible to quit
("/dev/tty"*) "${MPV:-mpv}" --keep-open=yes $fx ;;
(*) dem "${MPV:-mpv}" --keep-open=yes $fx ;;
esac
;;
esac
;;
(audio/*)
app=$(menu_select <<-\EOF
mpv (force terminal)
mpv (background)
mpv (background, only audio)
mpv (foreground)
mpv (foreground, only audio)
mpv (force window)
EOF
)
case "$app" in
(1) dem "${TERMINAL:-alacritty}" -e "$MPV" --audio-display=no $fx ;;
(2) dem "${MPV:-mpv}" $fx ;;
(3) dem "${MPV:-mpv}" --audio-display=no $fx ;;
(4) "${MPV:-mpv}" $fx ;;
(5) echo; "${MPV:-mpv}" --audio-display=no $fx ;;
(6) dem "${MPV:-mpv}" --force-window $fx ;;
esac
;;
(video/*)
app=$(menu_select <<-\EOF
mpv
mpv (background, only audio)
mpv (foreground, only audio)
kdenlive
EOF
)
case "$app" in
(1) dem "${MPV:-mpv}" $fx ;;
(2) dem "${MPV:-mpv}" --video=no --audio-display=no $fx ;;
(3) echo; "${MPV:-mpv}" --video=no --audio-display=no $fx ;;
(4) dem "${VIDEO_EDITOR:-kdenlive}" $fx ;;
esac
esac
}}
# vim: ft=lf

202
programs/lf/previewer Executable file
View File

@@ -0,0 +1,202 @@
#!/bin/bash
# shellcheck disable=SC2222
# File preview handler for lf.
# Dependencies:
# - GNU 'file' or similar (file detection)
# - bat (text)
# - uebergzug (images, videos, pdf, fonts)
# - ffmpegthumbnailer (videos)
# - exiftool (metadata/audio, and file detection for .webm files)
# - jq (json and metadata)
# - lynx (html/web pages)
# - pdftoppm (pdf)
# - odt2txt (odt)
# - convert from imagemagick (fonts)
# - atool (archives)
# - gpg (PGP encrypted files)
# - man (troff manuals)
# - Other: stat, cut, sha256sum
# Notes:
# - If using alacritty's same process: 'alacritty msg create-window', previews only show in first window
set -C -f
IFS='
'
# Display an image with certain path, width, height, x, y
# Usage: image "$path_to_image" "$width" "$height" "$x" "$y" "$fallback_path"
image() {
# shellcheck disable=all
set +u
set +e
if [ -f "$1" ] && [ "$DISPLAY" ] && [ ! "$WAYLAND_DISPLAY" ]
then
printf '{"action": "add", "identifier": "PREVIEW", "path": "%s", "width": "%s", "height": "%s", "scaler": "contain", "x": "%s", "y": "%s"}\n' \
"$1" "$(($2-1))" "$(($3-1))" "$4" "$5" > "$FIFO_UEBERZUG"
else
exiftool -j "$6" | jq -C
fi
}
ifub() {
# shellcheck disable=all
if [ "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
command -V ueberzug >/dev/null 2>&1
fi
}
# Note that the cache file name is a function of file information, meaning if
# an image appears in multiple places across the machine, it will not have to
# be regenerated once seen.
create_cache() {
# shellcheck disable=all
CACHE="${XDG_CACHE_HOME:-"$HOME/.cache"}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' \
-- "$(readlink -f "$1" || realpath "$1" )" \
| sha256sum \
| cut -d' ' -f1)"
}
mime_preview() {
# shellcheck disable=all
# The 'ran_guard' variable is there in case I need to do recursion
# because the initial mime_type variable wasn't enough to determine
# an adequate preview
case "$mime_type","$ran_guard" in
(image/svg+xml,0 | image/svg)
create_cache "$1"
[ -f "$CACHE.png" ] \
|| rsvg-convert -o "$CACHE.png" -a -w "1000" -b '#1f2430' "$1"
image "$CACHE.png" "$2" "$3" "$4" "$5" "$1"
;;
(image/*,0)
image "$1" "$2" "$3" "$4" "$5" "$1"
;;
(text/html,0)
lynx -width="$4" -display_charset=utf-8 -dump -- "$1"
;;
(text/troff,0)
case "${1##*.}" in
([0-9] | [01]p | [23]*)
man ./ "$1" | col -b
;;
(*)
bat --terminal-width "$(($4*7/9))" -f "$1" --style=numbers
esac
;;
(text/*,0 | */xml,0 | application/javascript,0 | application/x-subrip,0 )
bat --terminal-width "$(($4*7/9))" -f "$1" --style=numbers
;;
( application/x-pie-executable,0 | application/x-executable,0 | \
application/x-sharedlib,0)
objdump -d "$1" -M intel
#readelf -WCa "$1"
#hexdump -C "$1" || xxd "$1"
;;
(application/json,0)
case "${1##*.}" in
(ipynb)
# Needs my fork of ipynb-py-convert
ipynb-py-convert --stdout "$1" \
| bat --terminal-width "$(($4*7/9))" --color=always -l python --style=numbers
;;
(*) jq -C < "$1" ;;
esac
;;
(application/zip,0 | application/x-7z-compressed,0 )
atool --list -- "$1"
;;
(audio/*,[01])
exiftool -j "$1" | jq -C
;;
(video/webm,0)
# file --mime-type doesn't distinguish well between "video/webm"
# actual webm videos or webm audios, but exiftool does, thus
# re-run this function with new mimetype
mime_type="$(exiftool -s3 -MIMEType "$1")" \
ran_guard=$((ran_guard+1))
mime_preview "$@"
;;
(video/*,[01])
create_cache "$1"
[ -f "$CACHE" ] \
|| ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
image "$CACHE" "$2" "$3" "$4" "$5" "$1"
;;
(*/pdf,0 | */postscript,0) # .pdf, .ps
create_cache "$1"
[ -f "$CACHE.jpg" ] \
|| pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1"
;;
(application/font*,0 | application/*opentype,0 | font/sfnt,0) # .ttf, .otf
create_cache "$1"
[ -f "$CACHE.png" ] \
|| convert -size "800x800" "xc:#000000" -fill "#ffffff" \
-pointsize "72" -font "$1" -gravity center -annotate +0+0 \
"ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n1234567890\n!@#$\%^&*,.;:\n_-=+'\"|\\(){}[]" \
"$CACHE.png"
image "$CACHE.png" "$2" "$3" "$4" "$5" "$1"
;;
(*opendocument*,0) # .odt, .ods
CCt=' ' \
bytes=$(du -sb "$1") bytes="${bytes%%"$CCt"*}"
if [ "$bytes" -lt 150000 ]; then
odt2txt "$1"
else
printf "file too big too preview quickly\n"
fi
;;
(*ms-excel,0) # .xls
xls2csv -- "$1" \
| bat --terminal-width "$(($4*7/9))" --color=always -l csv --style=numbers
;;
#(application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) # .xslx
# https://github.com/dilshod/xlsx2csv
#xlsx2csv -- "$1"
#;;
#(text/rtf,0 | *msword,0 ) # .doc, doesn't always work
#catdoc -- "$1"
#;;
#(*wordprocessingml.document|*/epub+zip|*/x-fictionbook+xml) # .docx
#pandoc -s -t markdown -- "$1"
#;;
#(message/rfc822)
# https://github.com/djcb/mu
#mu view -- "${FILE_PATH}" && exit 5
#;;
# TODO: add lf command to decrypt it and show the decrypted file in preview window
(application/pgp-encrypted,0)
printf "PGP armored ASCII \033[1;31mencrypted\033[m file,\ntry using gpg to decrypt it\n\n"
cat "$1"
#gpg -d -- "$1"
;;
(application/octet-stream,0)
#extension="${1##*.}" extension="${extension%"$1"}"
case "${1##*.}" in
(gpg)
printf "OpenPGP \033[1;31mencrypted\033[m file,\ntry using gpg to decrypt it\n\n"
;;
(*) exiftool -j "$1" | jq -C
esac
;;
(application/vnd.sqlite3,0)
# TODO: handle multiple tables, maybe it's better to show tables and columns in a tree format
table=$(sqlite3 "$1" '.tables')
sqlite3 "$1" ".headers on" ".mode markdown" "select * from $table"
;;
esac
return 1
}
main() {
# shellcheck disable=all
mime_type="$(file --dereference -b --mime-type -- "$1")"
"echo hiiiiiiiiiiiiiiiiii $mime_type"
ran_guard=0
mime_preview "$@" || return $?
}
main "$@" || exit $?

View File

@@ -74,6 +74,7 @@
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
rpi ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOX+6B6Axx7AqgCm1H1rrou/3yOLeOLcTd8s0In0mOIY
phone ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHxg0HKtGAkwymll8r17d9cXdt40dJgRkSAzB699pWke+edne4Ildcnbde2yle01nEL7GOg92vh5t1sh6vkCzJQ=
[tab]:8022 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDdwFZf3IRa4YZyrNseofTRIDbkmdMiIXa3Gxs7wFzZN+ICwXeipfqV1Lh9C1sI4YnRIqfZlCSU+SE2dqVoQB6Uj64cdLrdslHYvgsR9PY3vVtrYypGfE1XTkLvD516x4mFofo22A9j8fK95fcMwpWLtNnv9SVBIT3V+4fUlbRCngdJ1V2cOd41JIwBrIxmRJ6X5v/SEqajmnVneqEmsqGgGA7JBJBCMSz5wwmZzWrTpzwj4SAD5b1z/R12DZfFHmgJCZYcMbjDgUiD5khsOwCCflH8DtO41PkOZRqDlpPPT9al7qhhESwxE6w5gIvaVh6HJljSCNw9OCQWONotv3gF9tVs6sZXsWxRZ2R0oIeA3rnM+mZxEtxElc2MKLVlsQ9SM2Xcr3J4Y43cWm7m03cDOz+iZecxs2qKAgn5Au72fudapDAtiCuYjKlMGEgbWX3CmxL0n/Uo32yfTRXnEHWMzXezmdGsuHUzk/sHTL8z5RVyzIBNl2HGlhldFbATuwRxXyBW9JIuEll+rW9Jm0MvpT3KoD/Q5aXDVH+21l6SSNBcjvZu00WNiYDD+gFR4BlewobtacGNOR4ErjxVZ10d8p6S5smadmo/RmbjhrVJK8EzigJPsVxEEjtuVq+jAQCvLTZCpEyDF/cBv60vIu4CyZkoAq1UaL64m7nIhR/8Yw==
'';
home.file.".ssh/rpi/local".text = ''