From 1752251157bb80fbb55d811b032c6459fd06c819 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 18:47:57 +0100 Subject: [PATCH] streamlining lf things, new functionality --- .config/lf/colors | 2 +- .config/lf/lfrc | 53 +++----- .config/lf/rifle.conf | 224 ++++++++++---------------------- .config/zsh/configs/widgets | 9 +- .local/bin/lf-sixel | 11 -- .local/bin/{lf-ueberzug => lfX} | 9 +- .local/bin/opener | 13 +- 7 files changed, 98 insertions(+), 223 deletions(-) delete mode 100755 .local/bin/lf-sixel rename .local/bin/{lf-ueberzug => lfX} (62%) diff --git a/.config/lf/colors b/.config/lf/colors index 17e8c99ee..eb37bfcb5 100644 --- a/.config/lf/colors +++ b/.config/lf/colors @@ -1,4 +1,4 @@ -# vim:ft=dircolors + # (This is not a dircolors file but it helps to highlight colors and comments) # default values from dircolors diff --git a/.config/lf/lfrc b/.config/lf/lfrc index e6c2f702e..defe814ad 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -11,23 +11,19 @@ set previewer "~/.config/lf/preview/chafa" set cursorpreviewfmt "\033[7;90m" set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033[32m ยป \033[33m%f\033[0m" -cmd pushedit %{{ - echo "Open: " && read files - if sh -c '[ -n "$VIM" ]'; then - lf -remote "send $id vimopen $files" - else - lf -remote "send $id \$echo $files | xargs -or nvim +wa" - fi - lf -remote "send $id reload" +# This might seem awkward, but it it needed to trigger the open for the taolf nvim plugin +cmd open ${{ + set +u + [ "$lf_user_multiopen" = "true" ] && { $OPENER $fx; return; } + $OPENER "$f" }} -cmd edit ${{ - if sh -c "[ -n \"\$VIM\" ]"; then - lf -remote "send $id vimopen $fx" - else - lf -remote "send $id \$echo \$fx | xargs -or nvim +wa" - fi - lf -remote "send $id unselect" +cmd pushedit %{{ + echo "Open: " && read files + echo + echo $files | xargs touch + lf -remote "send $id \$$OPENER $files + send $id unselect" }} cmd open-with ${{ @@ -35,16 +31,6 @@ cmd open-with ${{ rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p $method $fx }} -cmd vimopen &{{ - touch "$@" - lf -remote "$( - for f in "$@"; do printf "%b" "send $id toggle $f\n"; done - printf "%b" "send $id select $f\n" - printf "%b" "send $id open\n" - printf "%b" "send $id unselect\n" - )" -}} - cmd mkdir &mkdir -p "$(echo $* | tr ' ' '\ ')" cmd trash &{{ @@ -54,7 +40,7 @@ cmd trash &{{ lf -remote "send load" }} -cmd lazygit %{{ +cmd lazygit ${{ dir=$(dirname "$(realpath "${f:-_}")"}) if ! git --noglob-pathspecs -C $dir status >/dev/null 2>&1; then echo "Initialize git repo in '${dir}' [Y/n]:" && read yn && @@ -186,18 +172,13 @@ cmd extract ${{ cmd set_previewer %{{ if [ "${1}" = "sixel" ]; then - lf -remote "send $id set sixel" - lf -remote "send $id set previewer ~/.config/lf/preview/sixel" - lf -remote "send $id reload" + lf -remote "send $id :set sixel; set previewer ~/.config/lf/preview/sixel; reload" echo 'Previewer set to sixel' elif [ "${1}" = "ueberzug" ]; then - lf -remote "send $id set cleaner ~/.config/lf/preview/clean" - lf -remote "send $id set previewer ~/.config/lf/preview/ueberzug" - lf -remote "send $id reload" + lf -remote "send $id :set cleaner ~/.config/lf/preview/clean; set previewer ~/.config/lf/preview/ueberzug; reload" echo 'Previewer set to ueberzug' else - lf -remote "send $id set previewer ~/.config/lf/preview/chafa" - lf -remote "send $id reload" + lf -remote "send $id :set previewer ~/.config/lf/preview/chafa; reload" echo 'Previewer set to chafa' fi }} @@ -222,6 +203,7 @@ map extract map P link # map S share map lazygit +map $gdu map pushedit map push :mkdir map N push :&touch @@ -242,8 +224,9 @@ map n &echo $f | xclip -r -selection c map quit map g/ cd "/" map W new_lf_term -map e edit +map e :set user_multiopen "true" ; open; set user_multiopen "false" map E $sudo -e $f +map R $lf -remote "send $id :select \"$(readlink $f)\"" # Load bookmark shortcuts source "~/.config/lf/shortcutrc" diff --git a/.config/lf/rifle.conf b/.config/lf/rifle.conf index 0427d498d..1f1dec421 100644 --- a/.config/lf/rifle.conf +++ b/.config/lf/rifle.conf @@ -1,202 +1,114 @@ # vim: ft=cfg -# -# This is the configuration file of "rifle", ranger's file executor/opener. -# Each line consists of conditions and a command. For each line the conditions -# are checked and if they are met, the respective command is run. -# -# Syntax: -# , , ... = command -# -# The command can contain these environment variables: -# $1-$9 | The n-th selected file -# $@ | All selected files -# -# If you use the special command "ask", rifle will ask you what program to run. -# -# Prefixing a condition with "!" will negate its result. -# These conditions are currently supported: -# match | The regexp matches $1 -# ext | The regexp matches the extension of $1 -# mime | The regexp matches the mime type of $1 -# name | The regexp matches the basename of $1 -# path | The regexp matches the absolute path of $1 -# has | The program is installed (i.e. located in $PATH) -# env | The environment variable "variable" is non-empty -# file | $1 is a file -# directory | $1 is a directory -# number | change the number of this command to n -# terminal | stdin, stderr and stdout are connected to a terminal -# X | $DISPLAY is not empty (i.e. Xorg runs) -# -# There are also pseudo-conditions which have a "side effect": -# flag | Change how the program is run. See below. -# label