diff --git a/.config/lf/lfrc b/.config/lf/lfrc index a0a64bea..84ea88ae 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -132,27 +132,34 @@ cmd dupe &{{ # cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c +# TODO: Move this to zsh config cmd fzfsearch ${{ - file="$(find -L $PWD | fzf --header="Searching Filenames")" + file="$(find -L $PWD | fzf --header="Searching Filenames" || true)" + [ -z "$file" ] && return [ -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 --header="Searching Tags")" + file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/tags | fzf --header="Searching Tags" | sed 's/:.$//' || true)" + [ -z "$file" ] && return [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} cmd fzfmarks ${{ - r="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | fzf --header="Searching Marks")" - file="$(cat $r | sed 's/^.://')" + file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | fzf --header="Searching Marks" | cut -b 3- || true)" + [ -z "$file" ] && return [ -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 --header="Searching Shortcuts")" + [ -z "$file" ] && return [ -d $file ] && lf -remote "send $id cd $file" && return 0 [ -f $file ] && lf -remote "send $id select $file" }} +# cmd fzfworkon ${{ +# workon -n $(workon | fzf) +# }} cmd fzfgrep ${{ set +ue RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore " @@ -187,11 +194,6 @@ cmd extract ${{ done }} -# TODO: Move this to zsh config -# cmd fzfworkon ${{ -# workon -n $(workon | fzf) -# }} - cmd set_previewer %{{ if [ "${1}" = "sixel" ]; then lf -remote "send $id :set sixel; set previewer ~/.config/lf/preview/sixel" @@ -231,44 +233,85 @@ cmd new_lf_term &{{ on-cd # Bindings -map a fzfsearch -map t fzftags -map m fzfmarks -map f fzfshortcut -map g fzfgrep -map T trash -map $trash-restore $PWD -map &rm -rf -- $fx -map extract -map P link -# map S share -map lazygit -map $gdu -map pushedit -map push :&mkdir-p -map N push :&touch -map reload -map set hidden! -map x $$f -map X !$f -map o open-with -map O $less $f -map a :rename; cmd-home # rename from beginning -map r :rename; cmd-end # rename from end -map i :rename # before extension -map c push r # new rename -map B bulkrename -map b dupe -map u :clear; unselect -map n &echo $f | xclip -r -selection c +clearmaps + map quit -map g/ cd "/" -map W new_lf_term +map :toggle; down +map shell +map shell-wait +map a fzfsearch +map t fzftags +map m fzfmarks +map f fzfshortcut +map g fzfgrep +map "'" mark-load +map '"' mark-save +map "$" shell +map "!" shell-wait +map "&" shell-async +map ; find-next +map , find-prev +map / search +map a :rename; cmd-home # rename from beginning +map page-up +map b dupe +map B bulkrename +map quit +map c push r # new rename +map &rm -rf -- $fx +map scroll-down map e :set user_multiedit "true" ; open; set user_multiedit "false" map E $sudo -e $f +map f find +map F find-back +map lazygit +map $gdu +map gg top +map g/ cd "/" +# WARN: do not chain any more maps to g (check shortcutrc) +map G bottom +map h updir +map i :rename; cmd-end # rename from end +map j down +map k up +map l open +map m mark-save +map push :&mkdir-p +map n search-next +map N search-prev +map o open-with +map O $less $f +map p paste +map P link +map q quit +map reload +map r :rename # before extension map R $lf -remote "send $id :select \"$(readlink $f)\"" -# map q -# map quit +map set hidden! +map sn :set sortby natural; set info +map ss :set sortby size; set info size +map st :set sortby time; set info time +map sa :set sortby atime; set info atime +map sc :set sortby ctime; set info ctime +map se :set sortby ext; set info +map $trash-restore $PWD +map t tag-toggle +map T trash +map u :clear; unselect +map pushedit +map v invert +map W new_lf_term +map x $$f +map X !$f +map scroll-down +map y copy +map Y &echo $f | xclip -r -selection c +map zh set hidden! +map zr set reverse! +map zn set info +map zs set info size +map zt set info time +map za set info size:time # Load bookmark shortcuts source "~/.config/lf/shortcutrc" diff --git a/.config/lf/shortcutrc b/.config/lf/shortcutrc index 4e1ce669..7f75ab65 100644 --- a/.config/lf/shortcutrc +++ b/.config/lf/shortcutrc @@ -1,18 +1,18 @@ -map gh cd "/home/luca" -map gch cd "/home/luca/.cache" -map gcf cd "/home/luca/.config" -map gdt cd "/home/luca/.local/share" -map gst cd "/home/luca/.local/state" -map gsc cd "/home/luca/.local/bin" -map gse cd "/home/luca/.local/libexec" -map gmn cd "/mnt" -map gco cd "/home/luca/Documents/dev" -map gdl cd "/home/luca/Downloads" -map gdm cd "/home/luca/Documents" -map gdk cd "/home/luca/Desktop" -map gms cd "/home/luca/Music" -map gpc cd "/home/luca/Pictures" -map gvd cd "/home/luca/Videos" -map gdot cd "/home/luca/.local/share/stow/dots" -map glg cd "/home/luca/.local/log" -map gsv cd "/home/luca/.local/sv" +map gh cd "/home/luca" +map gch cd "/home/luca/.cache" +map gcf cd "/home/luca/.config" +map gdt cd "/home/luca/.local/share" +map gst cd "/home/luca/.local/state" +map gsc cd "/home/luca/.local/bin" +map gse cd "/home/luca/.local/libexec" +map gmn cd "/mnt" +map gco cd "/home/luca/Documents/dev" +map gdl cd "/home/luca/Downloads" +map gdm cd "/home/luca/Documents" +map gdk cd "/home/luca/Desktop" +map gms cd "/home/luca/Music" +map gpc cd "/home/luca/Pictures" +map gvd cd "/home/luca/Videos" +map gdot cd "/home/luca/.local/share/stow/dots" +map glg cd "/home/luca/.local/log" +map gsv cd "/home/luca/.local/sv" diff --git a/.local/bin/shortcuts b/.local/bin/shortcuts index 2ccd2c16..9d65de17 100755 --- a/.local/bin/shortcuts +++ b/.local/bin/shortcuts @@ -10,13 +10,71 @@ lf_files="$XDG_DATA_HOME/lf/shortcut-files" lf_dirs="$XDG_DATA_HOME/lf/shortcut-dirs" lf_shortcuts="$XDG_CONFIG_HOME/lf/shortcutrc" -rm -f "$lf_files" "$lf_dirs" "$lf_shortcuts" "$zsh_named_dirs" 2>/dev/null +find_marker() { + file=$1 + for marker in \ + "# @SHORTCUTS@" \ + "-- @SHORTCUTS@" \ + "// @SHORTCUTS@" \ + "/* @SHORTCUTS@ */" + do + file=$(grep -xn "$marker" "$file") + if [ -n "$file" ]; then + echo "$file" + return + fi + done +} -eval "echo \"$(cat "$bmdirs")\"" | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); - printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; - printf(\"map g%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" ; - printf(\"%s\n\",\$2) >> \"$lf_dirs\" }" +zsh() { + xargs printf "hash -d %s=%s\n" +} -eval "echo \"$(cat "$bmfiles")\"" | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); - printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; - printf(\"%s\n\",\$2) >> \"$lf_files\" }" +clean() { + rm -rf "/tmp/shortcuts" +} + +write_dirs_tmp() { + mkdir -p /tmp/shortcuts + while IFS= read -r line; do + shortcut=$(echo "$line" | cut -d' ' -f1) + path=$(echo "$line" | cut -d' ' -f2); path=$(eval "echo $path") + + printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs" + printf "map g%s cd \"%s\"\n" "$shortcut" "$path" >>"/tmp/shortcuts/lf_shortcuts" + printf "map %s" "$path" >>"/tmp/shortcuts/lf_dirs" + done +} + +write_files_tmp() { + read -r contents + mkdir -p /tmp/shortcuts + + shortcut=$(echo "$contents" | cut -d' ' -f1) + path=$(echo "$contents" | cut -d' ' -f2); + + printf "hash -d %s=%s\n" "$shortcut" "$path" >>"/tmp/shortcuts/zsh_named_dirs" + printf "map %s" "$path" >>"/tmp/shortcuts/lf_files" + +} + +apply_tmp() { + cat /tmp/shortcuts/zsh_named_dirs >"$zsh_named_dirs" + cat /tmp/shortcuts/lf_shortcuts >"$lf_shortcuts" + cat /tmp/shortcuts/lf_dirs >"$lf_dirs" + cat /tmp/shortcuts/lf_files >"$lf_files" +} + +read_file() { + in_file=$1 + sed 's/#.*//;/^$/d' "$in_file" | tr -s ' ' +} + +clean + +read_file "$bmdirs" | write_dirs_tmp +read_file "$bmfiles" | write_files_tmp + +apply_tmp + +clean