dotfiles

dotfiles
git clone git://git.wimdupont.com/dotfiles.git
Log | Files | Refs | README | LICENSE

lfrc (3398B)


      1 set shell sh
      2 set shellopts '-eu'
      3 
      4 #set drawbox
      5 set cursorpreviewfmt "\033[7m"
      6 
      7 # set internal field separator (IFS) to "\n" for shell commands
      8 # This is useful to automatically split file names in $fs and $fx properly
      9 # since default file separator used in these variables (i.e. 'filesep' option)
     10 # is newline. You need to consider the values of these options and create your
     11 # commands accordingly.
     12 set ifs "\n"
     13 
     14 # Basic Settings
     15 set ignorecase true
     16 
     17 cmd make_mod ${{
     18 	perm=$1
     19 	assu=$(test -w $f && echo 0 || echo 1)
     20 	if [ $perm != "a" ]; then
     21 		mod=$(test -$perm $f && echo "-$perm" || echo "+$perm")
     22 	else
     23 		mod="+rwx"
     24 	fi
     25 
     26 	test $assu -eq 1 && sudo chmod $mod $f || chmod $mod $f
     27 	lf -remote "send $id :reload"
     28 }}
     29 
     30 cmd mkfile ${{
     31   printf "File Name: "
     32   read ans
     33   $EDITOR $ans
     34 }}
     35 
     36 cmd setwallpaper ${{
     37     feh --bg-max "$f"
     38 }}
     39 
     40 cmd set_mime_default ${{
     41 	mime_type=$(xdg-mime query filetype $f)
     42 	colour=$(tput setaf 6)
     43 	normal=$(tput sgr0)
     44 	apps=($(ls /usr/share/applications | sed 's/.desktop//g'))
     45 
     46 	echo ""
     47 	printf "${colour}%s\t${normal}" "${apps[@]}"
     48 	printf "\nDefault application for $mime_type: "
     49 	read app
     50 
     51 	xdg-mime default $app.desktop $mime_type
     52 }}
     53 
     54 # extract the current file with the right command
     55 # (xkcd link: https://xkcd.com/1168/)
     56 cmd extract ${{
     57     set -f
     58     case $f in
     59         *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf "$f";;
     60         *.tar.gz|*.tgz) tar xzvf "$f";;
     61         *.tar.xz|*.txz) tar xJvf "$f";;
     62       	*.tar) tar -xvf "$f";;
     63         *.zip) unzip "$f";;
     64         *.rar) unrar x "$f";;
     65         *.7z) 7z x "$f";;
     66         *.gz) gzip -dk "$f";;
     67         *.gpg) gpg --decrypt-files "$f";;
     68     esac
     69 }}
     70 
     71 # compress current file or selected files with tar and gunzip
     72 cmd tar ${{
     73     tar czf $(basename $fx).tar.gz $(basename $fx)
     74 }}
     75 
     76 # define a custom 'open' command
     77 # This command is called when current file is not a directory. You may want to
     78 # use either file extensions and/or mime types here. Below uses an editor for
     79 # text files and a file opener for the rest.
     80 cmd open &{{
     81     case $(file --mime-type -Lb $f) in
     82         text/*) lf -remote "send $id \$$EDITOR \$fx";;
     83         *) lf -remote "send $id \$xdg-open \$fx";;
     84     esac
     85 }}
     86 
     87 cmd edit-config ${{
     88     $EDITOR ~/.config/lf/lfrc
     89     lf -remote "send $id source ~/.config/lf/lfrc"
     90 }}
     91 
     92 cmd move-parent &{{
     93     dironly="setlocal '$(dirname "$PWD")' dironly"
     94     lf -remote "send $id :updir; $dironly true; $1; $dironly false; open"
     95 }}
     96 
     97 cmd create_access ${{
     98     mkdir -p $HOME/access
     99     ln -s $fx $HOME/access/
    100 }}
    101 
    102 # Bindings
    103 map m
    104 
    105 map . set hidden!
    106 
    107 map J move-parent down
    108 map K move-parent up
    109 
    110 map md push %mkdir<space>
    111 map mf mkfile
    112 map mx make_mod "x"
    113 map mr make_mod "r"
    114 map mw make_mod "w"
    115 map ma make_mod "a"
    116 map mo $TYPE=$(xdg-mime query filetype $f); notify-send $(xdg-mime query default $TYPE) $TYPE
    117 map mO set_mime_default
    118 
    119 map bg setwallpaper
    120 
    121 # use enter for shell commands
    122 map <enter> shell
    123 
    124 map D delete
    125 map C edit-config
    126 
    127 # execute current file (must be executable)
    128 map x $$f
    129 map X !$f
    130 
    131 map aa create_access
    132 map ax extract
    133 map at tar
    134 map ae $encr "$(basename $f)"
    135 map ad $decr "$f"
    136 
    137 map ow $wine "$f"
    138 map os $sh "$f"
    139 map oa $mpv --no-video "$f"
    140 
    141 # dedicated keys for file opener actions
    142 map O $xdg-open "$f"
    143 map oo $xdg-open "$f"
    144 
    145 # Movement
    146 map ga cd ~/access
    147 map gc cd ~/.config
    148 map gD cd ~/desktop
    149 map gd cd ~/downloads
    150 map gp cd ~/pictures
    151 map gr cd ~/repositories
    152 map gb cd /usr/local/bin