lfrc (6770B)
1 # Luke's lf settings 2 3 4 # Note on Image Previews 5 # For those wanting image previews, like this system, there are four steps to 6 # set it up. These are done automatically for LARBS users, but I will state 7 # them here for others doing it manually. 8 # 9 # 1. ueberzug must be installed. 10 # 2. The scope file (~/.config/lf/scope for me), must have a command similar to 11 # mine to generate ueberzug images. 12 # 3. A `set cleaner` line as below is a cleaner script. 13 # 4. lf should be started through a wrapper script (~/.local/bin/lfub for me) 14 # that creates the environment for ueberzug. This command can be be aliased 15 # in your shellrc (`alias lf="lfub") or if set to a binding, should be 16 # called directly instead of normal lf. 17 18 # Basic vars 19 set shellopts '-eu' 20 set ifs "\n" 21 set scrolloff 10 22 set icons 23 set period 1 24 set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml" 25 set cleaner '~/.config/lf/cleaner' 26 set previewer '~/.config/lf/scope' 27 set autoquit true 28 29 # cmds/functions 30 cmd open ${{ 31 case $(file --mime-type "$(readlink -f $f)" -b) in 32 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;; 33 image/vnd.djvu|application/pdf|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;; 34 text/*|application/json|inode/x-empty|application/x-subrip) $EDITOR $fx;; 35 image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;; 36 image/svg+xml) display -- $f ;; 37 image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|avif\|tif\|ico\)\(_large\)*$" | 38 setsid -f nsxiv -aio 2>/dev/null | while read -r file; do 39 [ -z "$file" ] && continue 40 lf -remote "send select \"$file\"" 41 lf -remote "send toggle" 42 done & 43 ;; 44 audio/*|video/x-ms-asf) mpv --audio-display=no $f ;; 45 video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;; 46 application/pdf|application/vnd.djvu|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;; 47 application/pgp-encrypted) $EDITOR $fx ;; 48 application/vnd.openxmlformats-officedocument.wordprocessingml.document|application/vnd.oasis.opendocument.text|application/vnd.openxmlformats-officedocument.spreadsheetml.sheet|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.openxmlformats-officedocument.presentationml.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.presentation|application/vnd.ms-powerpoint|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.formula|application/vnd.oasis.opendocument.database) setsid -f libreoffice $fx >/dev/null 2>&1 ;; 49 application/octet-stream) case ${f##*.} in 50 doc|docx|xls|xlsx|odt|ppt|pptx) setsid -f libreoffice $fx >/dev/null 2>&1 ;; 51 ghw) setsid -f gtkwave $f >/dev/null 2>&1 ;; 52 ts) setsid -f mpv $f -quiet >/dev/null 2>&1 ;; 53 *) setsid -f zathura $fx >/dev/null 2>&1 ;; 54 esac ;; 55 *) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;; 56 esac 57 }} 58 59 cmd mkdir $mkdir -p "$@" 60 61 cmd extract ${{ 62 clear; tput cup $(($(tput lines)/3)); tput bold 63 set -f 64 printf "%s\n\t" "$fx" 65 printf "extract?[y/N]" 66 read ans 67 [ $ans = "y" ] && { 68 case $fx in 69 *.tar.bz2) tar xjf $fx ;; 70 *.tar.gz) tar xzf $fx ;; 71 *.bz2) bunzip2 $fx ;; 72 *.rar) unrar e $fx ;; 73 *.gz) gunzip $fx ;; 74 *.tar) tar xf $fx ;; 75 *.tbz2) tar xjf $fx ;; 76 *.tgz) tar xzf $fx ;; 77 *.zip) unzip $fx ;; 78 *.Z) uncompress $fx ;; 79 *.7z) 7z x $fx ;; 80 *.tar.xz) tar xf $fx ;; 81 esac 82 } 83 }} 84 85 cmd delete ${{ 86 clear; tput cup $(($(tput lines)/3)); tput bold 87 set -f 88 printf "%s\n\t" "$fx" 89 printf "delete?[y/N]" 90 read ans 91 [ $ans = "y" ] && rm -rf -- $fx 92 }} 93 94 cmd moveto ${{ 95 set -f 96 dest=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" | fzf --prompt 'Move to where? ' | sed 's|~|$HOME|') 97 [ -z "$dest" ] && exit 98 destpath=$(eval printf '%s' \"$dest\") 99 clear; tput cup $(($(tput lines)/3)); tput bold 100 echo "From:" 101 echo "$fx" | sed 's/^/ /' 102 printf "To:\n %s\n\n\tmove?[y/N]" "$destpath" 103 read -r ans 104 [ "$ans" != "y" ] && exit 105 for x in $fx; do 106 mv -iv "$x" "$destpath" 107 done && 108 notify-send "🚚 File(s) moved." "File(s) moved to $destpath." 109 }} 110 111 cmd copyto ${{ 112 set -f 113 dest=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" | fzf --prompt 'Copy to where? ' | sed 's|~|$HOME|') 114 [ -z "$dest" ] && exit 115 destpath=$(eval printf '%s' \"$dest\") 116 clear; tput cup $(($(tput lines)/3)); tput bold 117 echo "From:" 118 echo "$fx" | sed 's/^/ /' 119 printf "To:\n %s\n\n\tcopy?[y/N]" "$destpath" 120 read -r ans 121 [ "$ans" != "y" ] && exit 122 for x in $fx; do 123 cp -ivr "$x" "$destpath" 124 done && 125 notify-send "📋 File(s) copied." "File(s) copied to $destpath." 126 }} 127 128 cmd setbg "$1" 129 130 cmd bulkrename ${{ 131 tmpfile_old="$(mktemp)" 132 tmpfile_new="$(mktemp)" 133 134 [ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls) 135 136 echo "$fs" > "$tmpfile_old" 137 echo "$fs" > "$tmpfile_new" 138 $EDITOR "$tmpfile_new" 139 140 [ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new"; exit 1; } 141 142 paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst 143 do 144 [ "$src" = "$dst" ] || [ -e "$dst" ] || mv -- "$src" "$dst" 145 done 146 147 rm -f "$tmpfile_old" "$tmpfile_new" 148 lf -remote "send $id unselect" 149 }} 150 151 # Bindings 152 map <c-f> $lf -remote "send $id select \"$(fzf)\"" 153 map J $lf -remote "send $id cd $(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf)" 154 map H cd ~ 155 map g top 156 map D delete 157 map E extract 158 map C copyto 159 map M moveto 160 map <c-n> push :mkdir<space>""<left> 161 map <c-r> reload 162 map <c-s> set hidden! 163 map <enter> shell 164 map x $$f 165 map X !$f 166 map o &mimeopen "$f" 167 map O $mimeopen --ask "$f" 168 169 map A :rename; cmd-end # at the very end 170 map c push A<c-u> # new rename 171 map I :rename; cmd-home # at the very beginning 172 map i :rename # before extension 173 map a :rename; cmd-right # after extension 174 map B bulkrename 175 map b $setbg $f 176 177 map <c-e> down 178 map <c-y> up 179 map V push :!nvim<space> 180 181 map W $setsid -f $TERMINAL >/dev/null 2>&1 182 183 map U $printf "%s" "$fx" | xclip -selection clipboard 184 map u $printf "%s" "$fx" | sed 's/.*\///' | xclip -selection clipboard 185 map . $printf "%s" "$fx" | sed -E 's/^.+\[/https:\/\/www.youtube.com\/watch?v=/' | sed -E 's/\]\..+//' | xclip -selection clipboard 186 map <gt> $printf "%s" "$fx" | sed -E 's/^.+\[/https:\/\/piped.video\/watch?v=/' | sed -E 's/\]\..+//' | xclip -selection clipboard 187 map T $nsxiv -t "$(pwd)" # opens thumbnail mode 188 map <c-l> unselect 189 190 191 192 # Source Bookmarks 193 source "~/.config/lf/shortcutrc"