lfrc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # interpreter for shell commands
  2. set shell sh
  3. # set '-eu' options for shell commands
  4. # These options are used to have safer shell commands. Option '-e' is used to
  5. # exit on error and option '-u' is used to give error for unset variables.
  6. # Option '-f' disables pathname expansion which can be useful when $f, $fs, and
  7. # $fx variables contain names with '*' or '?' characters. However, this option
  8. # is used selectively within individual commands as it can be limiting at
  9. # times.
  10. set shellopts '-eu'
  11. # set internal field separator (IFS) to "\n" for shell commands
  12. # This is useful to automatically split file names in $fs and $fx properly
  13. # since default file separator used in these variables (i.e. 'filesep' option)
  14. # is newline. You need to consider the values of these options and create your
  15. # commands accordingly.
  16. set ifs "\n"
  17. # leave some space at the top and the bottom of the screen
  18. set scrolloff 10
  19. # Use the `dim` attribute instead of underline for the cursor in the preview pane
  20. set cursorpreviewfmt "\033[7;2m"
  21. # use enter for shell commands
  22. map <enter> shell
  23. # show the result of execution of previous commands
  24. map ` !true
  25. # execute current file (must be executable)
  26. map x $$f
  27. map X !$f
  28. # dedicated keys for file opener actions
  29. map o &mimeopen $f
  30. map O $mimeopen --ask $f
  31. # define a custom 'open' command
  32. # This command is called when current file is not a directory. You may want to
  33. # use either file extensions and/or mime types here. Below uses an editor for
  34. # text files and a file opener for the rest.
  35. cmd open &{{
  36. case $(file --mime-type -Lb $f) in
  37. text/*) lf -remote "send $id \$$EDITOR \$fx";;
  38. *) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
  39. esac
  40. }}
  41. # mkdir command. See wiki if you want it to select created dir
  42. map a :push %mkdir<space>
  43. # define a custom 'rename' command without prompt for overwrite
  44. # cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
  45. # map r push :rename<space>
  46. # make sure trash folder exists
  47. # %mkdir -p ~/.trash
  48. # move current file or selected files to trash folder
  49. # (also see 'man mv' for backup/overwrite options)
  50. cmd trash %set -f; mv $fx ~/.trash
  51. # define a custom 'delete' command
  52. # cmd delete ${{
  53. # set -f
  54. # printf "$fx\n"
  55. # printf "delete?[y/n]"
  56. # read ans
  57. # [ "$ans" = "y" ] && rm -rf $fx
  58. # }}
  59. # use '<delete>' key for either 'trash' or 'delete' command
  60. # map <delete> trash
  61. # map <delete> delete
  62. # extract the current file with the right command
  63. # (xkcd link: https://xkcd.com/1168/)
  64. cmd extract ${{
  65. set -f
  66. case $f in
  67. *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
  68. *.tar.gz|*.tgz) tar xzvf $f;;
  69. *.tar.xz|*.txz) tar xJvf $f;;
  70. *.zip) unzip $f;;
  71. *.rar) unrar x $f;;
  72. *.7z) 7z x $f;;
  73. esac
  74. }}
  75. # compress current file or selected files with tar and gunzip
  76. cmd tar ${{
  77. set -f
  78. mkdir $1
  79. cp -r $fx $1
  80. tar czf $1.tar.gz $1
  81. rm -rf $1
  82. }}
  83. # compress current file or selected files with zip
  84. cmd zip ${{
  85. set -f
  86. mkdir $1
  87. cp -r $fx $1
  88. zip -r $1.zip $1
  89. rm -rf $1
  90. }}
  91. set previewer ~/etc/lf/previewer
  92. set cleaner ~/etc/lf/cleaner