diff --git a/flake.nix b/flake.nix index 33c5ab4..0999496 100644 --- a/flake.nix +++ b/flake.nix @@ -175,9 +175,6 @@ } ]; }; - }; - - nixOnDroidConfigurations = rec { "tab" = inputs.nix-on-droid.lib.nixOnDroidConfiguration { modules = [ ./hosts/tab/nix-on-droid.nix @@ -189,29 +186,30 @@ } ]; }; + + test = inputs.nix-on-droid.lib.nixOnDroidConfiguration { + modules = [ ./hosts/nix-on-phone.nix ]; + + # list of extra special args for Nix-on-Droid modules + extraSpecialArgs = { + # rootPath = ./.; + }; + + # set nixpkgs instance, it is recommended to apply `nix-on-droid.overlays.default` + pkgs = import nixpkgs { + system = "aarch64-linux"; + + overlays = [ + inputs.nix-on-droid.overlays.default + # add other overlays + ]; + }; + + # set path to home-manager flake + home-manager-path = inputs.home-manager.outPath; + }; }; - nixOnDroidConfigurations.default = inputs.nix-on-droid.lib.nixOnDroidConfiguration { - modules = [ ./hosts/nix-on-phone.nix ]; - - # list of extra special args for Nix-on-Droid modules - extraSpecialArgs = { - # rootPath = ./.; - }; - - # set nixpkgs instance, it is recommended to apply `nix-on-droid.overlays.default` - pkgs = import nixpkgs { - system = "aarch64-linux"; - - overlays = [ - inputs.nix-on-droid.overlays.default - # add other overlays - ]; - }; - - # set path to home-manager flake - home-manager-path = inputs.home-manager.outPath; - }; packages.x86_64-linux = { cbm = nixpkgs.legacyPackages.x86_64-linux.callPackage ./mods/cbm.nix { }; diff --git a/hosts/main.nix b/hosts/main.nix index e5886e8..91321ae 100644 --- a/hosts/main.nix +++ b/hosts/main.nix @@ -59,6 +59,13 @@ }; ################################ my youtube blocking service ############################# + environment.etc."host.conf" = { + # needed so that firefox does not ignore the hosts file + text = '' + multi off + order hosts,bind,nis + ''; + }; systemd.services.stark = let stark = pkgs.writeShellApplication { @@ -67,20 +74,18 @@ runtimeInputs = with pkgs; [ curl w3m ]; text = '' - if [ -f "/etc/host-youtube-block" ]; + if [ -f "/etc/hosts-youtube-block" ]; then - timeout=$(cat /etc/host-youtube-block) - if [[ "$timeout" == "1" ]] + timeout=$(cat /etc/hosts-youtube-block) + if [[ "$timeout" == "1" ]] || [[ "$timeout" == "1\n" ]] then rm /etc/host-youtube-block else - echo old: "$timeout" timeout=$((timeout - 1)) - echo new: "$timeout" - echo -en $timeout > /etc/host-youtube-block + echo -en $timeout > /etc/hosts-youtube-block fi else - rm /etc/hosts + rm -rf /etc/hosts cat ${self}/misc/my-hosts > /etc/hosts cat ${self}/misc/my-hosts-"$(cat /etc/current_hosts)" >> /etc/hosts fi @@ -252,7 +257,7 @@ }; ipv4 = { - address1 = "192.168.20.11/24"; + #address1 = "192.168.20.11/24"; method = "auto"; }; }; diff --git a/misc/my-hosts b/misc/my-hosts index 39d9423..a67c46a 100644 --- a/misc/my-hosts +++ b/misc/my-hosts @@ -1 +1,4 @@ 127.0.0.1 youtube.com +127.0.0.1 www.youtube.com +::1 www.youtube.com +::1 youtube.com diff --git a/programs/alacritty.nix b/programs/alacritty.nix index b601e16..c588e6a 100644 --- a/programs/alacritty.nix +++ b/programs/alacritty.nix @@ -46,7 +46,7 @@ style = "Bold Italic"; }; - size = 9; + size = 8; }; # Dracula theme for alacritty diff --git a/programs/bash.nix b/programs/bash.nix index 524a67b..6eda924 100644 --- a/programs/bash.nix +++ b/programs/bash.nix @@ -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 diff --git a/programs/lf/cleaner b/programs/lf/cleaner new file mode 100755 index 0000000..a184d84 --- /dev/null +++ b/programs/lf/cleaner @@ -0,0 +1,4 @@ +#!/bin/sh +if [ -n "$FIFO_UEBERZUG" ]; then + printf '{"action": "remove", "identifier": "PREVIEW"}\n' > "$FIFO_UEBERZUG" +fi diff --git a/programs/lf/colors b/programs/lf/colors new file mode 100644 index 0000000..0cc093a --- /dev/null +++ b/programs/lf/colors @@ -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 diff --git a/programs/lf/default.nix b/programs/lf/default.nix index 0962990..e2f890a 100644 --- a/programs/lf/default.nix +++ b/programs/lf/default.nix @@ -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!"; "" = "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" + ''; }; } diff --git a/programs/lf/icons b/programs/lf/icons new file mode 100644 index 0000000..204314b --- /dev/null +++ b/programs/lf/icons @@ -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 diff --git a/programs/lf/lf-config b/programs/lf/lf-config new file mode 160000 index 0000000..1c295ce --- /dev/null +++ b/programs/lf/lf-config @@ -0,0 +1 @@ +Subproject commit 1c295ce7bc09c418dc9e101a0add033d74ce48b7 diff --git a/programs/lf/opener b/programs/lf/opener new file mode 100644 index 0000000..31f4107 --- /dev/null +++ b/programs/lf/opener @@ -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 diff --git a/programs/lf/previewer b/programs/lf/previewer new file mode 100755 index 0000000..e95ef0f --- /dev/null +++ b/programs/lf/previewer @@ -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 $? diff --git a/programs/ssh.nix b/programs/ssh.nix index f88b4ff..8f461fc 100644 --- a/programs/ssh.nix +++ b/programs/ssh.nix @@ -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 = '' diff --git a/scripts/nav/.nav_db b/scripts/nav/.nav_db new file mode 100644 index 0000000..982cfc1 --- /dev/null +++ b/scripts/nav/.nav_db @@ -0,0 +1 @@ +. m main.py diff --git a/scripts/nav/db b/scripts/nav/db index 543287c..f98162f 100644 --- a/scripts/nav/db +++ b/scripts/nav/db @@ -1,5 +1,8 @@ * H ~ +* O .. +* W ~/work * / / ~ w ~/work ~/work c config +~/work d downloads diff --git a/scripts/nav/lf-raw-mode-shell-pipe/main.py b/scripts/nav/lf-raw-mode-shell-pipe/main.py new file mode 100644 index 0000000..b5680e7 --- /dev/null +++ b/scripts/nav/lf-raw-mode-shell-pipe/main.py @@ -0,0 +1,195 @@ + +import shlex +from pathlib import Path +from os import path +import os +import argparse +import sys, tty, termios +import subprocess +import signal + +DB_FILE = "/home/me/work/config/scripts/nav/db" + + +def main(): + pwd = Path(os.getcwd()) + db_matches = get_db_matches(pwd, DB_FILE) + folder_db_matches = get_folder_db_matches(pwd) + folder_matches = get_folder_matches(pwd) + + parser = argparse.ArgumentParser() + parser.add_argument('-m', '--mode', help='mode of the program', type=str) + args = parser.parse_args() + + if args.mode == "lf": + + cmd = "ps" # | grep lf | awk '{print $1}'" + cmd2 = "ps | grep lf | awk '{print $1}'" + #p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + + #result = subprocess.run(cmd2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + #pid = result.stdout.decode('utf-8').strip() + + #print("hiiiiiiiiii:", b) + #a = p.stdout.readlines() + #a = subprocess.check_output(["ps"]).decode("utf-8") + + #a = input("hello --" + f"/proc/{pid}/fd/0" + "--") + + #signal.signal(signal) + + out = open("/home/me/p1", "w") + sys.stdout = out + sys.stderr = out + + + path = "/proc/2778149/fd/0" + + print("my stdin:", os.readlink('/proc/self/fd/0')) + print("lf stdin:", os.readlink(path)) + print("pid:", os.getpid()) + input() + print("after first input") + + file = open("/dev/pts/16", "r") + os.setpgid(os.getpid(), 2778149) + + subprocess.run(["ps", "-j"], stdout=out, stderr=out) + + exec("file.read(1)") + #file.read(1) + + a = input() + print("input was:", a) + + out.close() + file.close() + + exit() + + #out.write("test" + pid + "\n") + out.flush() + + #path = f"/proc/{pid}/fd/0" + + + out.write(f"before path: {path}\n") + out.flush() + + os.system("echo from echo $SHELL > /home/me/p2") + #os.system("/bin/bash /home/me/work/config/scripts/nav/run.sh 2>/home/me/p2 1>/home/me/p2") + os.system(f"python /home/me/work/config/scripts/nav/test.py /home/me/p2 1>/home/me/p2") + + #os.system(f"cat {path}") + #old_settings = termios.tcgetattr(fd) + + try: + + file = open(path, "r") + tty.setraw(file.fileno()) + + out.write(f"before path: {file}\n") + out.flush() + + b = file.read(1) + + out.write("got: " + b + "\n") + out.flush() + + file.close() + except e: + out.write("ERROR: " + str(e) + "\n") + + #while True: + #b = file.read(1) + #out.write("got: " + b + "\n") + + out.close() + + + """ + while True: + fd = sys.stdin.fileno() + print("fd", fd) + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + if ch == "q": + break + print("hello: ", ch) + """ + + #os.system("echo hello-world") + #while True: + #print("test", a) + #input() + #input("end: ") + + + else: + print("test", my_resolve("~")) + print("db:", db_matches) + print("folder db:", folder_db_matches) + print("folder:", folder_matches) + + +def get_db_matches(directory, db_file): + matches = [] + with open(db_file, "r") as file: + for line in file.readlines(): + line = line.strip() + if line == "": + continue + tmp = shlex.split(line) + try: + dir_in = tmp[0] + shortcut = tmp[1] + dest = tmp[2] + except: + eprint("db parse error on:", line) + continue + + if dir_in == "*": + matches.append((shortcut, dest)) + + elif my_resolve(directory) == my_resolve(dir_in): + matches.append((shortcut, dest)) + + return matches + +def get_folder_matches(directory): + matches = [] + ls = os.listdir(directory) + + for path in ls: + if path[0] == ".": + path_as_list = list(str(path)) + path_as_list.pop(0) + path = "".join(path_as_list) + + + return matches + +def get_folder_db_matches(directory): + if os.path.exists(directory / ".nav_db"): + return get_db_matches(directory, directory / ".nav_db") + else: + return [] + +def my_resolve(path): + if path == ".": + return Path(os.getcwd()) + if str(path)[0] == "~": + path_as_list = list(str(path)) + path_as_list.pop(0) + return Path(str(Path.home()) + "".join(path_as_list)) + + return path.resolve() + + +if __name__ == "__main__": + main() + diff --git a/scripts/nav/lf-raw-mode-shell-pipe/run.sh b/scripts/nav/lf-raw-mode-shell-pipe/run.sh new file mode 100755 index 0000000..1897526 --- /dev/null +++ b/scripts/nav/lf-raw-mode-shell-pipe/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +echo from script +#script=$(cat ./test.py) +#python -c "$script" + +python /home/me/work/config/scripts/nav/test.py #2>/home/me/p2 1>/home/me/p2 diff --git a/scripts/nav/lf-raw-mode-shell-pipe/test.py b/scripts/nav/lf-raw-mode-shell-pipe/test.py new file mode 100644 index 0000000..531c65e --- /dev/null +++ b/scripts/nav/lf-raw-mode-shell-pipe/test.py @@ -0,0 +1,33 @@ + +print("hiiiiiiiiiiiiiiiiiiiii:") + +#import sys +import os + + +#path = input("path: ") +path = "/proc/2767310/fd/0" +print("path:", path) + +#os.system(f"cat {path}") +#print("hi:", os.path.abspath(sys.stdin.name)) +print("my stdin:", os.readlink('/proc/self/fd/0')) +print("lf stdin:", os.readlink(path)) + +#os.system(f"cat /dev/pts/16") +#os.system("stty -F /proc/2763309/fd/0 -raw -icanon -echo; cat /proc/2763309/fd/0 > /home/me/p2") +exit() + +try: + file = open(path, "r") + + print(f"before path: {path}\n") + print(f"before path: {file}\n") + + b = file.read(1) + + print("got: " + b + "\n") + + file.close() +except Exception as e: + print("ERROR: " + str(e) + "\n") diff --git a/scripts/nav/main.py b/scripts/nav/main.py index 920841b..6f39c7c 100644 --- a/scripts/nav/main.py +++ b/scripts/nav/main.py @@ -3,54 +3,251 @@ import shlex from pathlib import Path from os import path import os +import argparse +import sys, tty, termios +import subprocess +from subprocess import Popen +import signal -DB_FILE = "/home/me/work/config/nav/db" +DB_FILE = "/home/me/work/config/scripts/nav/db" +def debug(*args, **kargs): + global out + print(*args, **kargs, file=out) + out.flush() def main(): - pwd = Path(os.getcwd()) - db_matches = get_db_matches(pwd) - folder_matches = get_folder_matches(pwd) - print(my_resolve("~/work/config")) - print("db:", db_matches) - print("folder:", folder_matches) + parser = argparse.ArgumentParser() + parser.add_argument('-m', '--mode', help='mode of the program', type=str) + parser.add_argument('-c', '--char', help='mode of the program', type=str) + args = parser.parse_args() + + if args.mode == "lf": + pre_cd = None + lf_id = os.environ["id"] + pwd = Path(os.getcwd()) + if args.char is not None: + dests = do_nav(args.char, pwd) + if len(dests) == 1: + pre_cd = my_resolve(dests[0], pwd=pwd) + pwd = pre_cd + + Popen(["lf", "-remote", f"send {lf_id} echo -- NAV --"]) + + # for debug + global out + #out = open("/home/me/p1", "w") + #sys.stderr = out + #sys.stdout = out + #debug() + + pid_lf = int(os.environ["lf_user_pid"]) + pgid = int(os.environ["lf_user_pgid"]) + + #for debug + #print("pid_lf", pid_lf) + #print("pgid", pgid) + + path = f"/proc/{pid_lf}/fd/0" + + os.setpgid(os.getpid(), pgid) + + file = open(path, "r") + + #clear filter + #os.system(f'lf -remote "send $id setfilter"') + #os.system('lf -remote "send $id echo -- NAV --"') + + chars = [] + while True: + print("-- HIIIIIIIIIII --") + #Popen(["lf", "-remote", f"send {lf_id} echo -- NAV iiiiiiiiiiiiiiii --"]) + + c = file.read(1) + #debug("-- HIIIIIIIIIII after --") + + if pre_cd is not None: + Popen(["lf", "-remote", f"send {lf_id} cd {pre_cd}"]) + pre_cd = None + + if c == "\x20" or c == "\x1b": # exit nav mode, when space or ESC is pressed + if len(chars) == 0: + pass + Popen(["lf", "-remote", f"send {lf_id} setfilter"]) + Popen(["lf", "-remote", f"send {lf_id} echo NAV Done"]) + print("NAV Done") + break + + if c == "\x03": + chars = chars[0:len(chars)-1] + + chars.append(c) + + dests = do_nav(chars, pwd) + + #for debug + #debug("dests:", dests) + + if len(dests) == 1: + path_to_go = my_resolve(dests[0], pwd=pwd) + Popen(["lf", "-remote", f"send {lf_id} setfilter"]) + + if os.path.isdir(path_to_go): + #for debug + #print("cding to:", path_to_go) + + Popen(["lf", "-remote", f"send {lf_id} cd {path_to_go}"]) + print("-- NAV --") + #Popen(["lf", "-remote", f"send {lf_id} echo -- NAV --"]) + else: + Popen(["lf", "-remote", f"send {lf_id} select {path_to_go}"]) + Popen(["lf", "-remote", f"send {lf_id} echo NAV Done"]) + break -def get_db_matches(directory): + chars = [] + pwd = path_to_go + + elif len(dests) == 0: + chars = [] + + else: + chars_as_string = "".join(chars) + Popen(["lf", "-remote", f"send {lf_id} setfilter {chars_as_string}"]) + print("-- NAV --") + #Popen(["lf", "-remote", f"send {lf_id} echo -- NAV --"]) + + #debug("got:", c, "chars:", chars) + + file.close() + + # for debug + out.close() + + + else: + chars = [] + while True: + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + c = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + + if c == "\x20" or c == "\x1b": # exit nav mode, when space or ESC is pressed + break + + if c == "\x03": + chars = chars[0:len(chars)-1] + + dests = do_nav(chars, pwd) + + if len(dests) == 1: + path_to_go = my_resolve(dests[0], pwd=pwd) + os.system("export") + + elif len(dests) == 0: + pass + + else: + pass + +def do_nav(chars, pwd): + db_matches = get_db_matches(pwd, DB_FILE) + folder_db_matches = get_folder_db_matches(pwd) + folder_items = list_folder(pwd) + + # for debug + #print("pwd:", pwd) + #print("chars:", chars) + + # first check if the char matches in what is in the main db + # immediatly cd (return list with one el) if found + for (match, dest) in db_matches: + if match == chars[0]: + return [dest] + + # next check local db + # but also immediatly cd when found + for (match, dest) in folder_db_matches: + if match == chars[0]: + return [dest] + + # then check folder contents + # and return all that start with that char + dests = [] + for item in folder_items: + item_chars = item[0:len(chars)] + search_chars = "".join(chars[0:len(chars)]) + if item_chars == search_chars: + dests.append(item) + return dests + + +def get_db_matches(directory, db_file): matches = [] - with open(DB_FILE, "r") as file: + with open(db_file, "r") as file: for line in file.readlines(): + line = line.strip() + if line == "": + continue tmp = shlex.split(line) try: dir_in = tmp[0] shortcut = tmp[1] dest = tmp[2] except: + eprint("db parse error on:", line) continue if dir_in == "*": matches.append((shortcut, dest)) - if dir_in == "~": - #if directory == Path.home(): + + elif my_resolve(directory) == my_resolve(dir_in): matches.append((shortcut, dest)) return matches -def get_folder_matches(directory): +def list_folder(directory): matches = [] ls = os.listdir(directory) - return matches + """ + for path in ls: + if path[0] == ".": + path_as_list = list(str(path)) + path_as_list.pop(0) + path = "".join(path_as_list) -def my_resolve(path): - if str(path)[0] == "~": + matches.append(path) + """ + + return ls + +def get_folder_db_matches(directory): + if os.path.exists(directory / ".nav_db"): + return get_db_matches(directory, directory / ".nav_db") + else: + return [] + +def my_resolve(path, pwd=os.getcwd()): + if path == ".": + return Path(pwd) + + elif str(path)[0] == "~": path_as_list = list(str(path)) path_as_list.pop(0) - print("path_as_list:", path_as_list) return Path(str(Path.home()) + "".join(path_as_list)) - return path.resolve() + elif str(path)[0] == "/": + return Path(path) + + else: + return Path(pwd) / Path(path) + if __name__ == "__main__": diff --git a/users/common/home.nix b/users/common/home.nix index ea80534..6678ccf 100644 --- a/users/common/home.nix +++ b/users/common/home.nix @@ -32,6 +32,7 @@ }; home.packages = with pkgs; [ + hostname vim tree htop @@ -57,7 +58,7 @@ click click-aliases ])) - /* + #/* (busybox.overrideAttrs (final: prev: { # get only nslookup from busybox # because the less would overwrite the actuall less and the busybox does not have -r @@ -73,9 +74,9 @@ mv $out/busybox $out/bin/busybox ''; })) - */ + # */ ]; - #*/ + # */ } diff --git a/users/me/home.nix b/users/me/home.nix index b88a671..57230b6 100644 --- a/users/me/home.nix +++ b/users/me/home.nix @@ -99,6 +99,64 @@ libvirt virt-manager freerdp + (pkgs.writeShellApplication { + name = "rpi"; + text = let + myPythonRpi = pkgs.writers.writePython3Bin "myPythonRpi" {} '' + # flake8: noqa + import os + import sys + import subprocess + + mac_map = { + "tab": ""; + "phone": "86:9d:6a:bc:ca:1b" + } + + + if len(sys.argv) == 1: + print("one arg needed") + exit() + net = sys.argv[1] + + if net == "pw": + ips = subprocess.run(["${pkgs.arp-scan}/bin/arp-scan", "-l", "-x", "-I", "wlp2s0"]) + for line in ips.split("\n"): + split = line.split(" ") + ip = split[0] + mac = split[1] + + old = {} + with open(f"/etc/hosts", "r") as file: + for line in file.readlines(): + if line == "\n": + continue + split = line.split(" ") + try: + old[split[1].strip()] = split[0].strip() + except: + print("error with: ", split) + + #to_update = {} + with open(f"${self}/misc/my-hosts-{net}", "r") as file: + for line in file.readlines(): + split = line.split(" ") + try: + old[split[1].strip()] = split[0].strip() + except: + print("error with: ", split) + + with open("/etc/hosts", "w") as file: + lines = [] + for key, val in old.items(): + lines.append(val + " " + key) + file.write("\n".join(lines) + "\n") + + with open("/etc/current_hosts", "w") as file: + file.write(net) + ''; + in ''sudo ${myPythonRpi}/bin/myPythonRpi "$@"''; + }) ]; }