# Basic Settings set shell zsh set shellopts '-euy' set ifs "\n" set errorfmt "\033[1;31m%s\033[0m" set promptfmt "\033[34;1m%d\033[0m\033[1m%f\033[0m" set scrolloff 5 set wrapscroll set sortby time set info size:time set reverse set incsearch set period 1 set hidden set preview set previewer lfview set ratios 2:4 set icons recol %[ $LF_LEVEL -eq 1 ] || echo "Warning: You're in a nested lf instance!" # Custom Functions cmd open ${{ case $(file --mime-type "$(readlink -f $f)" -b) in text/*|application/json) vix "$f";; image/svg+xml) display -- $f ;; image/*) setsid nsxiv-rifle $f 2>/dev/null & ;; audio/*) mpv $f ;; video/*) setsid mpv $f -quiet >/dev/null 2>&1 & ;; application/cbz|application/cbr|image/vnd.djvu|application/pdf|application/octet-stream|application/postscript|application/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;; *) xdg-open "$f" &>/dev/null &;; esac }} cmd recol &{{ w=$(tput cols) if [ $w -le 80 ]; then lf -remote "send $id set ratios 1:1" elif [ $w -le 160 ]; then lf -remote "send $id set ratios 2:2" else lf -remote "send $id set ratios 2:4" fi }} cmd bulkrename ${{ old=$(mktemp) new=$(mktemp) [ -n $fs ] && fs=$(ls) printf "$fs\n" > $old printf "$fs\n" > $new $EDITOR $new [ $(cat $new | wc -l) -ne $(cat $old | wc -l) ] && exit paste $old $new | while read names; do src=$(printf $names | cut -f1) dst=$(printf $names | cut -f2) [ $src = $dst ] && continue [ -e $dst ] && continue mv $src $dst done rm $old $new lf -remote "send $id unselect" }} # insert cmd rename-insert &{{ if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then lf -remote "send $id echo You can't change more than one file name" lf -remote "send $id unselect" else len="$(basename "$f" | wc -m)" # length of selected file/directory for i in $(seq "$len"); do pos="${pos}" # how many times do I have to press in order to get first char done lf -remote "send $id rename" lf -remote "send $id push $pos" fi }} # append before ext cmd rename-before-ext &{{ if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then lf -remote "send $id echo You can't change more than one file name" lf -remote "send $id unselect" else if [ -d "$f" ]; then lf -remote "send $id rename" else ext_len="$(echo ${f##*.} | wc -m)" # extention length for i in $(seq "$ext_len"); do pos="${pos}" done lf -remote "send $id rename" lf -remote "send $id push "$pos"" fi fi }} # change its name entirely cmd rename-new &{{ if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then lf -remote "send $id echo You can't change more than one file name" lf -remote "send $id unselect" else lf -remote "send $id rename" lf -remote "send $id push " fi }} cmd paste-rsync &{{ set -- $(cat ~/.local/share/lf/files) mode="$1" shift case "$mode" in copy) rsync -av --ignore-existing --progress -- "$@" . | stdbuf -i0 -o0 -e0 tr '\r' '\n' | while IFS= read -r line; do lf -remote "send $id echo $line" done ;; move) mv -n -- "$@" .;; esac rm ~/.local/share/lf/files lf -remote "send clear" }} cmd paste-overwrite %{{ mode=$(head -1 ~/.local/share/lf/files) list=$(sed 1d ~/.local/share/lf/files) if [ $mode = 'copy' ]; then cp -r $list . elif [ $mode = 'move' ]; then mv $list . fi lf -remote 'send clear' }} cmd fzf_jump ${{ res="$(find . -maxdepth 3 | fzf --reverse --header='Jump to location' | sed 's/\\/\\\\/g;s/"/\\"/g')" if [ -d "$res" ]; then cmd="cd" else cmd="select" fi lf -remote "send $id $cmd \"$res\"" }} cmd Link %{{ lf -remote 'load' | while read file; do if [ ! -n "${mode+1}" ]; then mode="$file" continue fi files+=("$file") done if [ "${#files[@]}" -le 1 ]; then lf -remote "send $id echo no files to link" exit 0 fi # symbolicly copy mode is indicating a soft link if [[ "$mode" == copy ]]; then ln -sr $files -t . # while a move mode is indicating a hard link elif [[ "$mode" == move ]]; then ln $files -t . fi }} cmd git_branch ${{ git branch | fzf | xargs git checkout pwd_shell=$(pwd) lf -remote "send $id updir" lf -remote "send $id cd \"$pwd_shell\"" }} # toggle single column view cmd no_preview :{{ set nopreview set ratios 2 set info size:time map ~ yes_preview }} cmd yes_preview :{{ set ratios 2:2 set preview set info map ~ no_preview }} cmd yank-dirname $dirname -- "$f" | head -c-1 | xclip -i -selection clipboard cmd yank-path $printf '%s' "$fx" | xclip -i -selection clipboard cmd yank-basename $basename -a -- $fx | head -c-1 | xclip -i -selection clipboard cmd yank-basename-without-extension ${{ echo "$fx" | xargs -r -d '\n' basename -a | awk -e '{ for (i=length($0); i > 0; i--) { if (substr($0, i, 1) == ".") { if (i == 1) print $0 else print substr($0, 0, i-1) break } } if (i == 0) print $0 }' | if [ -n "$fs" ]; then cat; else tr -d '\n'; fi | xclip -i -selection clipboard }} cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')" # Bindings # Remove some defaults map "'" map '"' map m map n map d map p map w map y map c map / map r map G cmap cmd-escape map push A # new rename map cut map copy map reload map push $touch map push :mkdir map delete map paste map open map delete map . set hidden! map ~ no_preview map | top map ¿ bottom map x clear map dd cut map yy copy map yn yank-dirname map yp yank-path map yn yank-basename map yw yank-basename-without-extension map pp paste map po paste-overwrite map pr paste-rsync map o &mimeopen $f map O $mimeopen --ask $f map cx $chmod +x "$f" map bg $setbg $f map du %du -sh $f map Y %cp -ri $fs . map D %mv -i $fs . map zf $file-roller "$f" map zc $zip -9 -r "$f".cbz $f map zx $zx "$f" map I push A # at the very beginning map A rename # at the very end map i push A # at the very beginning map a push A # after extention map B bulkrename map L :Link map f fzf_jump map / $lf -remote "send $id select \"$(FZF_DEFAULT_COMMAND='fd --max-depth=1 --strip-cwd-prefix' fzf)\"" map F $find | lf -remote "send $id select $(fzf --reverse --border --margin 2% --inline-info --color border:#005688,bg+:#16252E,fg+:#26c6da,hl+:#ffffff,hl:#26c6da)" map Gb :git_branch map Gp ${{clear; git pull --rebase || true; echo "press ENTER"; read ENTER}} map Gs ${{clear; git status; echo "press ENTER"; read ENTER}} map Gl ${{clear; git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit}} map da $git add $fx # Movement map gR cd / map gE cd /etc map gU cd /usr map gM cd /media map gl cd ~/.local/share map gg cd ~/.local/share/go map gb cd ~/.local/bin map g. cd ~/.config map gn cd ~/.config/nvim map gz cd ~/.config/zsh map gd cd ~/doc map gm cd ~/mus map ga cd ~/prg map gp cd ~/doc/paginas map gv cd ~/vid map ge cd ~/etc map gi cd ~/img map gc cd /mnt/cell map gx cd /mnt/vb/graveyard