From 80bbb3d24b1b93c4d45d454edc53081a5c01e5e2 Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Tue, 15 Mar 2022 08:21:12 +0100 Subject: [PATCH] feat: more lf updates --- home/lf/default.nix | 13 +++++++++++++ home/lf/pv.nix | 2 +- home/zsh/common.nix | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/home/lf/default.nix b/home/lf/default.nix index bc392a2..b3751cc 100644 --- a/home/lf/default.nix +++ b/home/lf/default.nix @@ -11,6 +11,19 @@ in { enable = true; previewer.source = pv; settings.icons = true; + commands = { + get-mime-type = ''%xdg-mime query filetype "$f"''; + open = '' + ''${{ + test -L $f && f=$(readlink -f $f) + case $(file --mime-type $f -b) in + text/*) vi $fx;; + application/json) vi $fx;; + *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;; + esac + }} + ''; + }; extraConfig = '' set cleaner ${cleaner} ''; diff --git a/home/lf/pv.nix b/home/lf/pv.nix index e521272..fd49f87 100644 --- a/home/lf/pv.nix +++ b/home/lf/pv.nix @@ -52,7 +52,7 @@ in pkgs.writeShellScript "pv.sh" '' */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" ;; + text/* | */xml | application/json) ${bat} --terminal-width "$4" -f "$1" ;; application/zip) ${atool} --list -- "$1" ;; *opendocument*) ${odt2txt} "$1" ;; audio/* | application/octet-stream) ${mediainfo} "$1" || exit 1 ;; diff --git a/home/zsh/common.nix b/home/zsh/common.nix index 368ecc4..e079d15 100644 --- a/home/zsh/common.nix +++ b/home/zsh/common.nix @@ -94,6 +94,16 @@ source "''${VENV_DIR}/''${selected_env}/bin/activate" } + lf () { + tmp=$(mktemp) + lf-wrapper -last-dir-path="$tmp" "$@" + if [ -f "$tmp" ]; then + dir=$(cat "$tmp") + rm -f "$tmp" + [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" + fi + } + export LANG=en_US.utf8 export LC_ALL=en_US.UTF-8 '';