]> Freerunner's - dotfiles.git/commitdiff
lf: overhaul config
authorAndre Ramnitz <tux.rising@gmail.com>
Thu, 21 Nov 2024 08:10:21 +0000 (09:10 +0100)
committerAndre Ramnitz <tux.rising@gmail.com>
Thu, 21 Nov 2024 08:22:18 +0000 (09:22 +0100)
- drop uberzug in favor of ctpv
  see also: https://github.com/NikitaIvanovV/ctpv
- overhaul keybinds, once again

dot-bashrc
dot-config/ctpv/config [new file with mode: 0644]
dot-config/fish/functions/lf.fish [deleted file]
dot-config/lf/lfrc
dot-config/lf/scripts/cleaner [deleted file]
dot-config/lf/scripts/lfub [deleted file]
dot-config/lf/scripts/preview [deleted file]
dot-config/lf/scripts/previewer_sandbox [deleted file]
dot-local/bin/lfrun

index 9edad24a10eba5471d08f7f030ce6a2de7f7a49e..c0a12cbe0a8c260811fe68e7296de5a9f463d806 100644 (file)
@@ -43,11 +43,11 @@ case $(tty) in
         ;;
     /dev/pts/[0-9]*)
         alias  l1='EZA_GRID_ROWS=26 eza -w 0 --group --group-directories-first -1'
-        alias  la='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons -l -a'
-        alias  lg='EZA_GRID_ROWS=26 eza -w 0 --group --long --grid --group-directories-first'
-        alias  ll='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons -l'
-        alias  ls='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons'
-        alias  lt='EZA_GRID_ROWS=26 eza -w 0 --group --long --grid --group-directories-first --sort=mod -t=mod --time-style=long-iso'
+        alias  la='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons -l -a --hyperlink'
+        alias  lg='EZA_GRID_ROWS=26 eza -w 0 --group --long --grid --group-directories-first --hyperlink'
+        alias  ll='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons -l --hyperlink'
+        alias  ls='EZA_GRID_ROWS=26 eza -w 55 --group --group-directories-first --icons --hyperlink'
+        alias  lt='EZA_GRID_ROWS=26 eza -w 0 --group --long --grid --group-directories-first --sort=mod -t=mod --time-style=long-iso --hyperlink'
         ;;
 esac
 
diff --git a/dot-config/ctpv/config b/dot-config/ctpv/config
new file mode 100644 (file)
index 0000000..f10f17b
--- /dev/null
@@ -0,0 +1,2 @@
+set chafasixel
+
diff --git a/dot-config/fish/functions/lf.fish b/dot-config/fish/functions/lf.fish
deleted file mode 100644 (file)
index 50e6c93..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-function lf --wraps=lfrun --description 'alias lf=lfrun'
-  lfrun $argv
-        
-end
index 709aa41fd393dedec7e7e439515dfba103ca04df..45b969be2bd302ae49830b8018a39b6157221081 100644 (file)
@@ -7,9 +7,19 @@ set ignorecase
 set icons
 set info size
 set sortby name
+set drawbox true
+set roundbox true
 
-set previewer ~/.config/lf/scripts/preview
-set cleaner ~/.config/lf/scripts/cleaner
+# previews via ueberzugpp and wrapper
+# set previewer ~/.config/lf/scripts/preview
+# set cleaner ~/.config/lf/scripts/cleaner
+
+# previews via https://github.com/NikitaIvanovV/ctpv?tab=readme-ov-file
+set sixel true
+set previewer ctpv
+set cleaner ctpvclear
+&ctpv -s $id
+&ctpvquit $id
 
 # interpreter for shell commands
 set shell sh
@@ -34,18 +44,7 @@ set ifs "\n"
 set scrolloff 3
 
 # use enter for shell commands
-# map <enter> shell
-
-# execute current file (must be executable)
-# map x $$f
-# map X !$f
-
-# dedicated keys for file opener actions
-# map o &mimeopen $f
-# map O $mimeopen --ask $f
-
-# mkdir command. See wiki if you want it to select created dir
-# map a :push %mkdir<space>
+map <enter> shell
 
 # make sure trash folder exists
 %mkdir -p ~/.trash
@@ -66,6 +65,14 @@ cmd add-file ${{
        touch $ans
 }}
 
+cmd add-file-and-edit %{{
+    IFS=" "
+    file="$*"
+    touch -- "$file"
+    file="$(printf '%s' "$file" | sed 's/\\/\\\\/g;s/"/\\"/g')"
+    lf -remote "send $id :select \"$file\"; \$\$EDITOR \"$file\""
+}}
+
 # set terminal title to current working directory
 cmd on-cd &{{
        printf "\033]0; $PWD\007" > /dev/tty
@@ -181,6 +188,14 @@ cmd on-select &{{
     lf -remote "send $id set statfmt \"$(eza -ldo --color=always --smart-group --no-permissions "$f")\""
 }}
 
+cmd goto-file &{{
+    if [ -n "$(find -mindepth 1 -maxdepth 1 -type d -print -quit)" ]; then
+        lf -remote "send $id :set dironly; bottom; set nodironly; down"
+    else
+        lf -remote "send $id top"
+    fi
+}}
+
 cmd fzf_jump ${{
     res="$(find . -maxdepth 1 | fzf --reverse --header='Jump to location')"
     if [ -n "$res" ]; then
@@ -371,13 +386,23 @@ setlocal /media sortby name
 setlocal /mnt sortby name
 
 # unmap keys
+map G
 map c
 map d
 map m
 map p
+map r
+map sa
+map sc
+map sd
+map se
+map sf
+map sn
+map ss
+map st
 map t
 map x
-map u is unselect
+map u is unselect
 
 
 # m = mark
@@ -387,6 +412,7 @@ map ml mark-load
 
 # a = add/apply
 map ad add-dir
+map ae add-file-and-edit
 map aD add-dir-and-move-selection
 map af add-file
 map aw :apply-wallpaper
@@ -404,20 +430,21 @@ map dr trash-restore
 map dZ delete #zap
 
 # g = goto
-map ga cd ~/Applications/
-map gc cd ~/.config
+map GM cd /mnt
+map Ga cd ~/Applications/
+map Gc cd ~/.config
+map Gd cd ~/dotfiles/
+map Gl cd ~/.local
+map Gm cd /media
+map Gs cd ~/Bilder/Screenshots
+map Gt cd ~/.local/share/Trash/
+map Gw cd ~/Bilder/Wallpapers
 map gd cd ~/Downloads/
-map gD cd ~/dotfiles/
-map gf :fzf_search
-map gl cd ~/.local
-map gL follow-link
-map gm cd /media
-map gM cd /mnt
 map ge bottom
-map gs cd ~/Bilder/Screenshots
+map gf :fzf_search
+map gf goto-file
+map gl follow-link
 map go :fzf_jump
-map gt cd ~/.local/share/Trash/
-map gw cd ~/Bilder/Wallpapers
 
 # o = order
 map oC : set sortby ctime; set reverse true; set info ctime
@@ -431,24 +458,43 @@ map oc : set sortby ctime; set reverse true; set info ctime
 map ot : set sortby time; set reverse true; set info time
 
 # p = paste
-map pp :paste; clear
-map pP :paste
-map pl :link; clear
-map pL :link
+map pL :link; clear
+map pP :paste; clear
+map pl :link
+map pp :paste
 
 # q = 
 map q
 map Q : quit
 
+# r = rename
+map rb bulk-rename
+map rr rename
+map rh :rename; cmd-home
+map rl :rename; cmd-end
+map rf :rename; cmd-delete-home
+map rA :rename; cmd-end; cmd-delete-home
+
 # s = select
 map sd select-dirs
 map sf select-files
+map s+ push :glob-select<space>
+map s- push :glob-unselect<space>
+map si invert
+map su unselect
 
 # x = extract/execute
 map xe extract
 map xt open-cwd-in-terminal 
 map xg push :open-with-gui<space>
-map xt push :open-with-cli<space>
+map xc push :open-with-cli<space>
+map xx &mimeopen $f
+map xo $mimeopen --ask $f
+map xs $$f
+map xa !$f
+
+# z = ???
+zp = set info perm:user:group
 
 # one-shot commands
 map R bulk-rename
@@ -462,9 +508,5 @@ map '%' : select-all
 map <esc> unselect
 map ~ toggle_preview
 map C edit-config
-map + push :glob-select<space>
-map - push :glob-unselect<space>
-# map <enter> push :open-with-gui<space>
-# map <a-enter> push :open-with-cli<space>
 map <c-f> $lf -remote "send $id select '$(fzf)'"
 
diff --git a/dot-config/lf/scripts/cleaner b/dot-config/lf/scripts/cleaner
deleted file mode 100755 (executable)
index 0159d5a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-ueberzugpp cmd -s $UB_SOCKET -a remove -i PREVIEW
diff --git a/dot-config/lf/scripts/lfub b/dot-config/lf/scripts/lfub
deleted file mode 100755 (executable)
index 45864e5..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/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
-
-UB_PID=0
-UB_SOCKET=""
-
-case "$(uname -a)" in
-    *Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;;
-    *) UEBERZUG_TMP_DIR="/tmp" ;;
-esac
-
-cleanup() {
-    exec 3>&-
-    ueberzugpp cmd -s "$UB_SOCKET" -a exit
-}
-
-if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
-    lf "$@"
-else
-    [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf"
-    UB_PID_FILE="$UEBERZUG_TMP_DIR/.$(uuidgen)"
-    ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$UB_PID_FILE"
-    UB_PID=$(cat "$UB_PID_FILE")
-    rm "$UB_PID_FILE"
-    UB_SOCKET="$UEBERZUG_TMP_DIR/ueberzugpp-${UB_PID}.socket"
-    export UB_PID UB_SOCKET
-    trap cleanup HUP INT QUIT TERM EXIT
-    lf "$@" 3>&-
-fi
diff --git a/dot-config/lf/scripts/preview b/dot-config/lf/scripts/preview
deleted file mode 100755 (executable)
index ab41c61..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-
-image() {
-    FILE_PATH="$1"
-    X=$4
-    Y=$5
-    MW=$(($2 - 1))
-    MH=$3
-    ueberzugpp cmd -s "$UB_SOCKET" -a add -i PREVIEW -x "$X" -y "$Y" --max-width "$MW" --max-height "$MH" -f "$FILE_PATH"
-    exit 1
-}
-
-batorcat() {
-    file="$1"
-    shift
-    if command -v bat >/dev/null 2>&1; then
-        bat --color=always --style=plain --pager=never "$file" "$@"
-    else
-        cat "$file"
-    fi
-}
-
-CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
-
-case "$(printf "%s\n" "$(readlink -f "$1")" | tr '[:upper:]' '[:lower:]')" in
-    *.tgz | *.tar.gz) tar tzf "$1" ;;
-    *.tar.bz2 | *.tbz2) tar tjf "$1" ;;
-    *.tar.txz | *.txz) xz --list "$1" ;;
-    *.tar) tar tf "$1" ;;
-    *.zip | *.jar | *.war | *.ear | *.oxt) unzip -l "$1" ;;
-    *.rar) unrar l "$1" ;;
-    *.7z) 7z l "$1" ;;
-    *.[1-8]) man "$1" | col -b ;;
-    *.o) nm "$1" ;;
-    *.torrent) transmission-show "$1" ;;
-    *.iso) iso-info --no-header -l "$1" ;;
-    *.odt | *.ods | *.odp | *.sxw) odt2txt "$1" ;;
-    *.doc) catdoc "$1" ;;
-    *.docx) docx2txt "$1" - ;;
-    *.xls | *.xlsx)
-        ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv
-        ;;
-    *.wav | *.mp3 | *.flac | *.m4a | *.wma | *.ape | *.ac3 | *.og[agx] | *.spx | *.opus | *.as[fx] | *.mka)
-        exiftool "$1"
-        ;;
-    *.pdf)
-        [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
-        image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
-        ;;
-    *.avi | *.mp4 | *.wmv | *.dat | *.3gp | *.ogv | *.mkv | *.mpg | *.mpeg | *.vob | *.fl[icv] | *.m2v | *.mov | *.webm | *.ts | *.mts | *.m4v | *.r[am] | *.qt | *.divx)
-        [ ! -f "${CACHE}.jpg" ] && ffmpegthumbnailer -i "$1" -o "${CACHE}.jpg" -s 0 -q 5
-        image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
-        ;;
-    *.bmp | *.jpg | *.jpeg | *.png | *.xpm | *.webp | *.gif | *.jfif)
-        image "$1" "$2" "$3" "$4" "$5"
-        ;;
-    *.svg)
-        [ ! -f "${CACHE}.jpg" ] && convert "$1" "${CACHE}.jpg"
-        image "${CACHE}.jpg" "$2" "$3" "$4" "$5"
-        ;;
-    *)
-        batorcat "$1"
-        ;;
-esac
-exit 0
diff --git a/dot-config/lf/scripts/previewer_sandbox b/dot-config/lf/scripts/previewer_sandbox
deleted file mode 100644 (file)
index f6537d9..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-!/bin/bash
-## ~/.config/lf/previewer_sandbox
-
-set -euo pipefail
-(
-    exec bwrap \
-     --ro-bind /usr/bin /usr/bin \
-     --ro-bind /usr/share/ /usr/share/ \
-     --ro-bind /usr/lib /usr/lib \
-     --ro-bind /usr/lib64 /usr/lib64 \
-     --symlink /usr/bin /bin \
-     --symlink /usr/bin /sbin \
-     --symlink /usr/lib /lib \
-     --symlink /usr/lib64 /lib64 \
-     --proc /proc \
-     --dev /dev  \
-     --ro-bind /etc /etc \
-     --ro-bind ~/.config ~/.config \
-     --ro-bind ~/.cache ~/.cache \
-     --ro-bind "$PWD" "$PWD" \
-     --unshare-all \
-     --new-session \
-     bash ~/.config/lf/preview "$@"
-)
-
index 91023150987d3614a54126531551e78f3f354635..38ce13941cde779ca33026ec48be70866e5a696e 100755 (executable)
@@ -4,38 +4,31 @@
 # ueberzug. This works in concert with the lf configuration file and the
 # lf-cleaner script.
 
-set -e
+set -euf
 
-BROWSER="$(printf "qutebrowser\n--untrusted-args\n")"
-EDITOR="$(printf "kks\nedit\n")"
-VISUAL="$(printf "kks\nedit\n")"
-# PAGER="$(printf "bat\n--style\nauto\n--pager\nalways\n")"
+if [ -n "${DISPLAY-}" ] && [ -z "${FIFO_UEBERZUG-}" ]; then
+  export FIFO_UEBERZUG="${TMPDIR:-/tmp}/lf-ueberzug-$$"
 
-
-UB_PID=0
-UB_SOCKET=""
-
-case "$(uname -a)" in
-    *Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;;
-    *) UEBERZUG_TMP_DIR="/tmp" ;;
-esac
-
-cleanup() {
+  cleanup() {
     exec 3>&-
-    ueberzugpp cmd -s "$UB_SOCKET" -a exit
-}
-
-if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
-    lf "$@"
+    rm -- "$FIFO_UEBERZUG"
+  }
+
+  mkfifo -- "$FIFO_UEBERZUG"
+  # Execute ueberzug in a loop in case it crashes. Ueberzug dies if its
+  # associated window is closed. This breaks image previews when using tmux and
+  # reattaching to an existing session.
+  while [ -p "$FIFO_UEBERZUG" ] && ! ueberzug layer -s <"$FIFO_UEBERZUG"; do :; done &
+  # Open the FIFO for writing. FIFO readers receive an EOF once all writers
+  # have closed their respective file descriptors. Holding a file descriptor
+  # will effectively keep ueberzug alive as long as lf lives.
+  exec 3>"$FIFO_UEBERZUG"
+  trap cleanup EXIT
+
+  # Start lf without passing in the file descriptor. This is done to avoid the
+  # lf server being passed the file descriptor, which would cause ueberzug to
+  # live longer than is strictly necessary.
+  lf "$@" 3>&-
 else
-    [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf"
-    UB_PID_FILE="$UEBERZUG_TMP_DIR/.$(uuidgen)"
-    ueberzugpp layer --silent --no-stdin --use-escape-codes --pid-file "$UB_PID_FILE"
-    UB_PID=$(cat "$UB_PID_FILE")
-    rm "$UB_PID_FILE"
-    UB_SOCKET="$UEBERZUG_TMP_DIR/ueberzugpp-${UB_PID}.socket"
-    export UB_PID UB_SOCKET
-    trap cleanup HUP INT QUIT TERM EXIT
-    lf "$@" 3>&-
+  exec lf "$@"
 fi
-