diff --git a/.config/bash/.bashrc b/.config/bash/.bashrc index 7a2705f..34d2601 100644 --- a/.config/bash/.bashrc +++ b/.config/bash/.bashrc @@ -40,7 +40,7 @@ bind '"\C-f":"cd $(dirname "$(fzf)")\n"' function lfcd() { tmp="$(mktemp -uq)" trap 'rm -f $tmp >/dev/null 2>&1' HUP INT QUIT TERM PWR EXIT - lf -last-dir-path="$tmp" "$@" + lfub -last-dir-path="$tmp" "$@" if [ -f "$tmp" ]; then dir="$(cat "$tmp")" [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" || return diff --git a/.config/lf/cleaner b/.config/lf/cleaner new file mode 100755 index 0000000..a184d84 --- /dev/null +++ b/.config/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/.config/lf/lfrc b/.config/lf/lfrc index 6d5cafb..c060d42 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -2,6 +2,20 @@ # Luke's lf settings +# Note on Image Previews +# For those wanting image previews, like this system, there are four steps to +# set it up. These are done automatically for LARBS users, but I will state +# them here for others doing it manually. +# +# 1. ueberzug must be installed. +# 2. The scope file (~/.config/lf/scope for me), must have a command similar to +# mine to generate ueberzug images. +# 3. A `set cleaner` line as below is a cleaner script. +# 4. lf should be started through a wrapper script (~/.local/bin/lfub for me) +# that creates the environment for ueberzug. This command can be be aliased +# in your shellrc (`alias lf="lfub") or if set to a binding, should be +# called directly instead of normal lf. + # Basic vars set shellopts '-eu' set ifs "\n" @@ -10,11 +24,15 @@ set icons set ignorecase set period 1 set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml" -set previewer ctpv -set cleaner ctpvclear -&ctpv -s $id -&ctpvquit $id -cmd on-quit $ctpv -e $id +set cleaner '~/.config/lf/cleaner' +set previewer '~/.config/lf/scope' + +# CTPV is an option for previewer, it's very nice, but doesn't handle image previews +# set previewer ctpv +# set cleaner ctpvclear +# &ctpv -s $id +# &ctpvquit $id +# cmd on-quit $ctpv -e $id # cmds/functions cmd open ${{ diff --git a/.config/lf/scope b/.config/lf/scope new file mode 100755 index 0000000..b55962f --- /dev/null +++ b/.config/lf/scope @@ -0,0 +1,57 @@ +#!/bin/sh + +# File preview handler for lf. + +set -C -f +IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" + +image() { + if [ -f "$1" ] && [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1; 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 "$6" + 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. + +case "$(file --dereference --brief --mime-type -- "$1")" in + image/avif) CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && magick "$1" "$CACHE.jpg" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + image/vnd.djvu) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && djvused "$1" -e 'select 1; save-page-with /dev/stdout' | magick -density 200 - "$CACHE.jpg" > /dev/null 2>&1 + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + image/svg+xml) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.png" ] && inkscape --convert-dpi-method=none -o "$CACHE.png" --export-overwrite -D --export-png-color-mode=RGBA_16 "$1" + image "$CACHE.png" "$2" "$3" "$4" "$5" "$1" ;; + image/x-xcf) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && magick "$1[0]" "$CACHE.jpg" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + image/*) image "$1" "$2" "$3" "$4" "$5" "$1" ;; + text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;; + text/troff) man ./ "$1" | col -b ;; + text/* | */xml | application/json | application/x-ndjson) bat -p --theme ansi --terminal-width "$(($4-2))" -f "$1" ;; + audio/* | application/octet-stream) mediainfo "$1" || exit 1 ;; + video/* ) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0 + image "$CACHE" "$2" "$3" "$4" "$5" "$1" ;; + */pdf) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + */epub+zip|*/mobi*) + CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum)" CACHE="${CACHE%% *}" + [ ! -f "$CACHE.jpg" ] && gnome-epub-thumbnailer "$1" "$CACHE.jpg" + image "$CACHE.jpg" "$2" "$3" "$4" "$5" "$1" ;; + application/*zip) atool --list -- "$1" ;; + *opendocument*) odt2txt "$1" ;; + application/pgp-encrypted) gpg -d -- "$1" ;; +esac +exit 1 diff --git a/.config/nvim/lua/lazyvim/config/keymaps.lua b/.config/nvim/lua/lazyvim/config/keymaps.lua index aebfa7e..9226086 100644 --- a/.config/nvim/lua/lazyvim/config/keymaps.lua +++ b/.config/nvim/lua/lazyvim/config/keymaps.lua @@ -60,20 +60,22 @@ vim.keymap.set("t", "", "") vim.keymap.set("n", "xt", "PlenaryBustedFile %") -- angular related -vim.keymap.set("n", "gs", function() require("lazyvim.utils.angular").toggle_between_spec_and_file() end) +vim.keymap.set("n", "gs", function() + require("lazyvim.utils.angular").toggle_between_spec_and_file() +end) local job_id = 0 vim.keymap.set("n", "Ts", function() - vim.cmd.vnew() - vim.cmd.term() - vim.cmd.wincmd("J") - vim.api.nvim_win_set_width(0, 5) + vim.cmd.vnew() + vim.cmd.term() + vim.cmd.wincmd("J") + vim.api.nvim_win_set_width(0, 5) - job_id = vim.bo.channel + job_id = vim.bo.channel end, { desc = "Small Terminal" }) vim.keymap.set("n", "gotest", function() - vim.fn.chansend(job_id, { "go test\r\n" }) + vim.fn.chansend(job_id, { "go test\r\n" }) end) vim.keymap.set("n", "Tf", "FloatTerminal") @@ -85,7 +87,12 @@ vim.keymap.set("n", "Y", [["+Y]]) vim.keymap.set({ "n", "v" }, "d", [["_d]]) vim.keymap.set("n", "Q", "") vim.keymap.set("n", "Tt", "silent !tmux neww tmux-sessionizer") -vim.keymap.set("n", "S", [[:%s/\<\>//gI]], { desc = "search and replace" }) +vim.keymap.set( + "n", + "S", + [[:%s/\<\>//gI]], + { desc = "search and replace" } +) vim.keymap.set("n", "X", "!chmod +x %", { silent = true, desc = "make me executable" }) -- spell check, etc diff --git a/.local/bin/compiler b/.local/bin/compiler index d4a3790..fefa85a 100755 --- a/.local/bin/compiler +++ b/.local/bin/compiler @@ -11,7 +11,7 @@ ext="${file##*.}" dir=${file%/*} base="${file%.*}" -cd "${dir}" || exit "1" +# cd "${dir}" || exit "1" case "${ext}" in [0-9]) preconv "${file}" | refer -PS -e | groff -mandoc -T pdf > "${base}.pdf" ;; diff --git a/.local/bin/lfub b/.local/bin/lfub new file mode 100755 index 0000000..f9bb2df --- /dev/null +++ b/.local/bin/lfub @@ -0,0 +1,24 @@ +#!/bin/sh + +# This is a wrapper script for lf that allows it to create image previews with +# ueberzug. This works in concert with the lf configuration file and the +# lf-cleaner script. + +set -e + +cleanup() { + exec 3>&- + rm "$FIFO_UEBERZUG" +} + +if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + lf "$@" +else + [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf" + export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$" + mkfifo "$FIFO_UEBERZUG" + ueberzug layer -s <"$FIFO_UEBERZUG" -p json & + exec 3>"$FIFO_UEBERZUG" + trap cleanup HUP INT QUIT TERM PWR EXIT + lf "$@" 3>&- +fi