From 625d81d7655716b9aaafd1f2f0c24e59d08630a3 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 00:33:30 +0100 Subject: [PATCH 1/9] Work on new opening system --- .config/lf/lfrc | 55 ++++++++++++++++++++++++++++++++++++----------- .config/lf/opener | 11 ++++++++++ .config/lf/todo | 5 +++++ 3 files changed, 59 insertions(+), 12 deletions(-) create mode 100755 .config/lf/opener diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 5ae344a8..cb17effe 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -10,21 +10,50 @@ set period 1 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" +set opener=opener -cmd open $set -f; rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p 0 $fx; clear +cmd pushedit %{{ + echo "Open: " + files=$(read x; echo $x) + 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" +}} + +cmd edit ${{ + rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 $fx + # if sh -c "[ -n '\$VIM' ]"; then + # lf -remote "send $id vimopen $fx" + # else + # lf -remote "send $id '\$echo $fx | xargs -or nvim +wa'" + # fi +}} cmd open-with ${{ - method=$(rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -l $fx | fzf | cut -d':' -f1) + method=$(rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -l $fx | fzf --header="Choose an application:" | cut -d':' -f1) 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 &{{ for f in $fx; do trash-put $f & done - lf -remote "send $id load" + lf -remote "send load" }} cmd lazygit ${{ @@ -96,22 +125,22 @@ cmd dupe &{{ # cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c cmd fzfsearch ${{ - file="$(find $PWD | fzf)" + file="$(find -L $PWD | fzf --header="Searching Filenames")" [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} cmd fzftags ${{ - file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/tags | sed 's/:\*$//' | fzf)" + file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/tags | sed 's/:\*$//' | fzf --header="Searching Tags")" [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} cmd fzfmarks ${{ - file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | sed 's/^.://' | fzf)" + file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | sed 's/^.://' | fzf --header="Searching Marks")" [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} cmd fzfshortcut ${{ - file="$(cat ${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc | cut -d '"' -f2 | fzf)" + file="$(cat ${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc | cut -d '"' -f2 | fzf --header="Searching Shortcuts")" [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} @@ -120,15 +149,17 @@ cmd fzfgrep ${{ res="$( FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \ fzf --bind "change:reload:$RG_PREFIX {q} || true" \ - --ansi --layout=reverse --header 'Search in files' |\ + --ansi --layout=reverse --header 'Searching file contents' |\ grep -iv -e 'Trash/files' -e 'Trash/info' )" file="$(echo $res | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" row="$(echo $res | cut -d':' -f2)" column="$(echo $res | cut -d':' -f3)" if [ -n "$res" ]; then - lf -remote "send ${id} select '$file'" - if [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then + lf -remote "send $id select '$file'" + if [ -n "$VIM" ]; then + lf -remote "send $id open '$file'" + elsif [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then lf -remote "send $id \$$EDITOR '$file' +'call cursor($row, $column)'" else lf -remote "send $id \$$EDITOR '$file'" @@ -185,7 +216,7 @@ map extract map P link # map S share map lazygit -map push :!$EDITOR +map pushedit map push :mkdir map N push :&touch map reload @@ -205,7 +236,7 @@ map n &echo $f | xclip -r -selection c map quit map g/ cd "/" map W new_lf_term -map e $$EDITOR $f +map e edit map E $sudo -e $f # Load bookmark shortcuts diff --git a/.config/lf/opener b/.config/lf/opener new file mode 100755 index 00000000..2f1e723a --- /dev/null +++ b/.config/lf/opener @@ -0,0 +1,11 @@ +#!/bin/sh +set -f + +if [ "$2" ]; then + for f in "$@"; do + # shellcheck disable=2086 + rifle -p0 $f + done +else + rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 "$1" +fi diff --git a/.config/lf/todo b/.config/lf/todo index 19fb367a..de835e27 100644 --- a/.config/lf/todo +++ b/.config/lf/todo @@ -1 +1,6 @@ gpg asks for unlock when viewing gpg keys +rework rifle.conf +look into perl-File-MimeInfo +look into mimeo +Get the swallow patch up and running asap! +inode/directory handler for forking/terminal From ed6954e23918667eaba80b381196b89690336ba6 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 08:24:30 +0100 Subject: [PATCH 2/9] minor script changes --- .local/bin/escapefilter | 10 ++++++++++ .local/bin/lf-sixel | 7 ++++--- .local/bin/trash-restore | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100755 .local/bin/escapefilter diff --git a/.local/bin/escapefilter b/.local/bin/escapefilter new file mode 100755 index 00000000..df8c3cef --- /dev/null +++ b/.local/bin/escapefilter @@ -0,0 +1,10 @@ +#!/usr/bin/env perl +# this script should filter out any terminal escapes in a text stream +while (<>) { + s/ \e[ #%()*+\-.\/]. | + \e\[ [ -?]* [@-~] | # CSI ... Cmd + \e\] .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL) + \e[P^_] .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST + \e. //xg; + print; +} diff --git a/.local/bin/lf-sixel b/.local/bin/lf-sixel index 140c8971..346a6aff 100755 --- a/.local/bin/lf-sixel +++ b/.local/bin/lf-sixel @@ -2,9 +2,10 @@ set -e if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then - command lf "$@" + # shellcheck disable=2068 + command lf $@ else [ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf" - # shellcheck disable=2016 - command lf -command 'set_previewer sixel' "$@" 3>&- + # shellcheck disable=2016,2068 + command lf -command 'set_previewer sixel' $@ 3>&- fi diff --git a/.local/bin/trash-restore b/.local/bin/trash-restore index 659a4649..1eb6dfcd 100755 --- a/.local/bin/trash-restore +++ b/.local/bin/trash-restore @@ -37,10 +37,9 @@ sub trashed_files ( $search_path, $trash_path ) { sub fzf_files (@files) { my $n = 0; - my $str; + my $str = ""; for my $e (@files) { - $str .= "\n" if $n > 0; - $str .= "$n | $$e[2] | $$e[1]"; + $str = "$n | $$e[2] | $$e[1]\n" . $str; $n++; } chomp($str); From 0e223879c7267252d40664937609b1becebcbb12 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 08:33:21 +0100 Subject: [PATCH 3/9] async lazygit starting --- .config/lf/lfrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index cb17effe..6cb8f60c 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -56,8 +56,8 @@ cmd trash &{{ lf -remote "send load" }} -cmd lazygit ${{ - cd "$(dirname "$(realpath "$f")")" && lazygit +cmd lazygit &{{ + lf -remote "send $id \$cd "$(dirname "$(realpath "$f")")" && lazygit" }} # y (select for copy) and P to paste soft-link From e639accfdcf7182a232a3cdf4f2c7a442cb2e733 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 09:33:43 +0100 Subject: [PATCH 4/9] update lazygit function for lf --- .config/lf/lfrc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 6cb8f60c..c3ea070d 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -13,8 +13,7 @@ set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033 set opener=opener cmd pushedit %{{ - echo "Open: " - files=$(read x; echo $x) + echo "Open: " && read files if sh -c '[ -n "$VIM" ]'; then lf -remote "send $id vimopen $files" else @@ -56,8 +55,16 @@ cmd trash &{{ lf -remote "send load" }} -cmd lazygit &{{ - lf -remote "send $id \$cd "$(dirname "$(realpath "$f")")" && 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 && + case $yn in + "" | [Yy]*) git -C ${dir} init >/dev/null 2>&1; break ;; + [Nn]*) ;; + esac + fi + lf -remote "send $id \$cd '$dir' && lazygit" }} # y (select for copy) and P to paste soft-link From a676a1dd5e29ff001214a25703db364c61831484 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 09:48:41 +0100 Subject: [PATCH 5/9] change CurSearch highlight vim https://github.com/neovim/neovim/issues/23590 --- .config/nvim/lua/plugins/misc/tokyonight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/nvim/lua/plugins/misc/tokyonight.lua b/.config/nvim/lua/plugins/misc/tokyonight.lua index 89f758ad..1beef464 100644 --- a/.config/nvim/lua/plugins/misc/tokyonight.lua +++ b/.config/nvim/lua/plugins/misc/tokyonight.lua @@ -6,7 +6,7 @@ local opts = { style = "night", transparent = true, on_highlights = function(hl, _) - hl.CurSearch = nil + hl.CurSearch = { link = "Search" } end, } From a42b402162e78df1b43c18b9e57c849407b71fe1 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 10:03:07 +0100 Subject: [PATCH 6/9] change glow style and zk preview --- .config/glow/style.json | 9 +++++++-- .config/zk/config.toml | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.config/glow/style.json b/.config/glow/style.json index 8e8b5d6d..894373ec 100644 --- a/.config/glow/style.json +++ b/.config/glow/style.json @@ -21,35 +21,40 @@ }, "h1": { "prefix": "▋ ", + "block_suffix": "\n", "color": "#89ddff", - "bold": true, - "block_suffix": "\n" + "bold": true }, "h2": { "prefix": "▌ ", + "block_suffix": "\n", "color": "#61bdf2", "bold": true }, "h3": { "prefix": "┃ ", + "block_suffix": "\n", "color": "#82aaff", "bold": true }, "h4": { "prefix": "│ ", + "block_suffix": "\n", "color": "#6d91de", "bold": true }, "h5": { "prefix": "┆ ", + "block_suffix": "\n", "color": "#9aa5ce", "bold": true }, "h6": { "prefix": "┊ ", + "block_suffix": "\n", "color": "#61bdf2" }, "text": { diff --git a/.config/zk/config.toml b/.config/zk/config.toml index f70f0f00..43b10164 100644 --- a/.config/zk/config.toml +++ b/.config/zk/config.toml @@ -5,3 +5,6 @@ dir = "~/Documents/wiki" language = "en" filename = "{{slug title}}-{{id}}" extension = "md" + +[tool] +fzf-preview = "glow -s '$XDG_CONFIG_HOME/glow/style.json' {-1}" From 05715e781ed0caa8c77b79b83d7c71bd990b22ca Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 10:08:40 +0100 Subject: [PATCH 7/9] lf edit command fix --- .config/lf/lfrc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index c3ea070d..e680d94b 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -23,12 +23,11 @@ cmd pushedit %{{ }} cmd edit ${{ - rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 $fx - # if sh -c "[ -n '\$VIM' ]"; then - # lf -remote "send $id vimopen $fx" - # else - # lf -remote "send $id '\$echo $fx | xargs -or nvim +wa'" - # fi + if sh -c "[ -n \"\$VIM\" ]"; then + lf -remote "send $id vimopen $fx" + else + lf -remote "send $id \$echo \$fx | xargs -or nvim +wa" + fi }} cmd open-with ${{ From 823141fdb16cf7b61e458b4d093ba1a05f29d0aa Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 10:25:26 +0100 Subject: [PATCH 8/9] fix lf new terminal function --- .config/lf/lfrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index e680d94b..760facca 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -204,7 +204,7 @@ cmd set_previewer %{{ # HACK: This is a dirty hack to have an lf terminal that I can "exit" out of into a shell cmd new_lf_term &{{ - mapcmd='map q $tmux' + mapcmd='map q $sh -c "tmux; kill $id"' previewercmd="set_previewer $(basename "$lf_previewer")" $TERMINAL -e lf -command "${previewercmd}; ${mapcmd}" }} From ee3da54e767529cbca7aac0db90a9650e12d57b9 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 1 Feb 2024 10:50:28 +0100 Subject: [PATCH 9/9] setup opener for lf --- .config/lf/lfrc | 1 - .config/zsh/.zprofile | 2 ++ {.config/lf => .local/bin}/opener | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename {.config/lf => .local/bin}/opener (73%) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 760facca..b2b3eb20 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -10,7 +10,6 @@ set period 1 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" -set opener=opener cmd pushedit %{{ echo "Open: " && read files diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index 8fdfdef9..30e90b65 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -6,6 +6,8 @@ export EDITOR="nvim" export TERMINAL="st" +export TERMCMD=$TERMINAL +export OPENER=opener export BROWSER="brave-browser" # Locale diff --git a/.config/lf/opener b/.local/bin/opener similarity index 73% rename from .config/lf/opener rename to .local/bin/opener index 2f1e723a..f026df66 100755 --- a/.config/lf/opener +++ b/.local/bin/opener @@ -4,7 +4,7 @@ set -f if [ "$2" ]; then for f in "$@"; do # shellcheck disable=2086 - rifle -p0 $f + rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 $f done else rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 "$1"