lfrc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # interpreter for shell commands (needs to be POSIX compatible)
  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 enter for shell commands
  20. map <enter> shell
  21. # execute current file (must be executable)
  22. map x $$f
  23. map X !$f
  24. # dedicated keys for file opener actions
  25. map o &mimeopen $f
  26. map O $mimeopen --ask $f
  27. # custom fnc binding
  28. map b $~/.scripts/fnc $f
  29. # define a custom 'open' command
  30. # This command is called when current file is not a directory. You may want to
  31. # use either file extensions and/or mime types here. Below uses an editor for
  32. # text files and a file opener for the rest.
  33. cmd open ${{
  34. case "${f##*.}" in
  35. xopp) devour xournalpp $f;;
  36. mp3) mpv $f;;
  37. pdf) devour llpp $f > /dev/null 2> /dev/null &disown;;
  38. epub) llpp $f > /dev/null 2> /dev/null &disown;;
  39. sc) sc-im $f;;
  40. *)
  41. case $(file --mime-type $f -b) in
  42. text/*) $EDITOR $fx;;
  43. image/*) sxiv $f &;;
  44. *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
  45. esac;;
  46. esac
  47. }}
  48. # define a custom 'rename' command without prompt for overwrite
  49. # cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
  50. # map r push :rename<space>
  51. # make sure trash folder exists
  52. # %mkdir -p ~/.trash
  53. # move current file or selected files to trash folder
  54. # (also see 'man mv' for backup/overwrite options)
  55. cmd trash %set -f; mv $fx ~/.trash
  56. # define a custom 'delete' command
  57. # cmd delete ${{
  58. # set -f
  59. # printf "$fx\n"
  60. # printf "delete?[y/n]"
  61. # read ans
  62. # [ $ans = "y" ] && rm -rf $fx
  63. # }}
  64. # use '<delete>' key for either 'trash' or 'delete' command
  65. # map <delete> trash
  66. # map <delete> delete
  67. # extract the current file with the right command
  68. # (xkcd link: https://xkcd.com/1168/)
  69. cmd extract ${{
  70. set -f
  71. case $f in
  72. *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
  73. *.tar.gz|*.tgz) tar xzvf $f;;
  74. *.tar.xz|*.txz) tar xJvf $f;;
  75. *.zip) unzip $f;;
  76. *.rar) unrar x $f;;
  77. *.7z) 7z x $f;;
  78. esac
  79. }}
  80. # compress current file or selected files with tar and gunzip
  81. cmd tar ${{
  82. set -f
  83. mkdir $1
  84. cp -r $fx $1
  85. tar czf $1.tar.gz $1
  86. rm -rf $1
  87. }}
  88. # compress current file or selected files with zip
  89. cmd zip ${{
  90. set -f
  91. mkdir $1
  92. cp -r $fx $1
  93. zip -r $1.zip $1
  94. rm -rf $1
  95. }}