# interpreter for shell commands set shell sh # set '-eu' options for shell commands # These options are used to have safer shell commands. Option '-e' is used to # exit on error and option '-u' is used to give error for unset variables. # Option '-f' disables pathname expansion which can be useful when $f, $fs, and # $fx variables contain names with '*' or '?' characters. However, this option # is used selectively within individual commands as it can be limiting at # times. set shellopts '-eu' # set internal field separator (IFS) to "\n" for shell commands # This is useful to automatically split file names in $fs and $fx properly # since default file separator used in these variables (i.e. 'filesep' option) # is newline. You need to consider the values of these options and create your # commands accordingly. set ifs "\n" # leave some space at the top and the bottom of the screen set scrolloff 5 # Basic Settings set hidden true #set drawbox true set icons true set ignorecase true set smartcase true set mouse set previewer preview set preview cmd open $$OPENER $f cmd on-cd &{{ [ -z "$CD_HISTFILE" ] && export CD_HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/cd_history" sed -i "\|^$PWD$|d" "$CD_HISTFILE" echo "$PWD" >> "$CD_HISTFILE" }} cmd delete ${{ clear; tput cup $(($(tput lines)/3)); tput bold set -f printf "%s\n\t" "$fx" printf "delete?[y/N] " read ans [ $ans = "y" ] && rm -rf -- $fx }} cmd extract ${{ # extract the current file with the right command # (xkcd link: https://xkcd.com/1168/) set -f for f in $fx; do case "$f" in *.tar) tar xvf "$f" ;; *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf "$f" ;; *.tar.gz|*.tgz) tar xzvf "$f" ;; *.tar.xz|*.txz) tar xJvf "$f" ;; *.gz) gunzip "$f" ;; *.zip|*.epub) unzip "$f" ;; *.rar) unrar x "$f" ;; *.7z) 7z x "$f" ;; *.zst) unzstd "$f" ;; *) echo "Unsupported format" >&2; exit 1 ;; esac done }} cmd link_index %{{ case "$f" in *.html) index="index.html" ;; *) echo "Unsupported file"; exit 1 ;; esac [ -e "$index" ] && [ ! -L "$index" ] && { echo "Failed: $index already exists and is not a symbolic link" exit } ln -sf "$f" "$index" }} cmd select_eval ${{ res="$(eval "$@")" [ -d "$res" ] && lf -remote "send $id cd \"$res\"" || lf -remote "send $id select \"$res\"" }} cmd link %{{ set -- $(cat ~/.local/share/lf/files) mode="$1" shift [ "$#" -lt 1 ] && { lf -remote "send $id echo no files to link"; exit 0; } case "$mode" in copy) ln -sr -t . -- "$@";; move) ln -t . -- "$@";; esac rm ~/.local/share/lf/files lf -remote "send clear" }} # Basic Functions cmap cmd-menu-complete cmap cmd-menu-complete-back map shell map trash map set preview! map push $mkdir"" map :source ~/.config/lf/lfrc map :toggle; down map :toggle; up map Z :toggle; up map select_eval "fzf --reverse --query '!/$ ' --header-first --header='Jump to location'" map ${{ lf -remote "send $id select \"$(cat \"${OPEN_HISTFILE:-${XDG_STATE_HOME:-$HOME/.local/state}/open_history}\" | fzf --tac --reverse --header-first --header='File History')\"" }} map ${{ lf -remote "send $id cd \"$(cat ${CD_HISTFILE:-${XDG_STATE_HOME:-$HOME/.local/state}/cd_history} | fzf --tac --reverse --header-first --header='Path History')\"" }} map select_eval "fzf --reverse --query '/$ ' --header-first --header='Jump to directory'" map c map d map I :rename; cmd-home map i :rename; cmd-word-back; cmd-left map a :rename; cmd-right map A :rename; cmd-end map S push A map o $LESSOPEN="|preview %s" less -r $f map O $mimeopen --ask $f map . set hidden! map x cut map M $lf -remote "send $id select \"$(fmd)\"" map D delete map W $setsid -f $TERMINAL >/dev/null 2>&1 map X !$f map T !dev test $f map b $vidir map V push :!nvim"" map P :link map ge extract map gl clear map gx ${{ chmod +x $fx; lf -remote "send $id reload"; }} map gX ${{ chmod -x $fx; lf -remote "send $id reload"; }} map gm push $chmod--$fx map gL %lf -remote "send ${id} select '$(readlink $f)'" map gd !du -hd1 map gf !{{ file "$f" && file --brief --mime-type "$f" }} map gy %{{ printf "%s" "$fx" | xsel -b }} map gi link_index map gsb $setbg $f map zpp set previewer preview map zpt set previewer text-preview # Trash Mappings map dd ${{ echo "$fx" | xargs -I{} trash-put "{}" }} map dtc $trash-empty map dtr $trash-restore # Dragon Mapping map dr %dragon-drop -a -x $fx map ds %dragon-drop -a $fx map di %dragon-drop $fx map dm %cpdragon map dc %mvdragon map dl %dlfile source ~/.config/lf/shortcutrc