My build of nnn with minor changes
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

120 líneas
2.8 KiB

  1. #!/bin/bash
  2. # #############################################################################
  3. # nlay: a customizable script to play files in different apps by file type
  4. #
  5. # usage: nlay file type
  6. #
  7. # MUST READ:
  8. #
  9. # 1. Feel free to change the default apps to your favourite ones.
  10. # If you change the app for a group you may also need to modify the bg
  11. # setting. If bg is set the app is detached and started in the background in
  12. # silent mode.
  13. #
  14. # The bg setting depends on personal preference and type of app, e.g.,
  15. # I would start vim (CLI) in the foreground but Sublime Text (GUI) in the
  16. # background.
  17. #
  18. # Check (and TOGGLE as you wish) the default bg settings.
  19. #
  20. # 2. Detached apps are not killed when nnn exits. Use kill(1) or killall(1) to
  21. # to stop console based background apps.
  22. #
  23. # 3. Assuming you don't to play multiple audio/video files simultaneously,
  24. # nlay kills any running instances of the audio/video player in bg mode.
  25. #
  26. # 4. Keep a personal backup (on GitHub Gist maybe?) of this file if you modify
  27. # it. nlay is OVERWRITTEN during nnn upgrade.
  28. #
  29. # Author: Arun Prakash Jana
  30. # Email: engineerarun@gmail.com
  31. # #############################################################################
  32. # Enable the lines below to handle file by extension
  33. # This is provided for using a custom player for specific files
  34. # $ext holds the extension
  35. <<ENABLE_FILE_TYPE_HANDLING
  36. fname=$(basename "$1")
  37. if [[ $fname != *"."* ]]; then
  38. exit 1
  39. fi
  40. ext="${fname##*.}"
  41. if [ -z "$ext" ]; then
  42. exit 1
  43. fi
  44. # bash 4.0 way to switch to lowercase
  45. ext="${ext,,}"
  46. # handle this extension and exit
  47. ENABLE_FILE_TYPE_HANDLING
  48. #------------------ AUDIO -------------------
  49. if [ "$2" == "audio" ]; then
  50. app=mpv
  51. # To start mpv in a window enable audio_opts
  52. #audio_opts="--no-terminal --force-window"
  53. #bg=">/dev/null 2>&1 &"
  54. if [ -n "$bg" ]; then
  55. killall -9 $app >/dev/null 2>&1
  56. fi
  57. eval $app $audio_opts "\"$1\"" $bg
  58. exit 0
  59. fi
  60. #------------------ VIDEO -------------------
  61. if [ "$2" == "video" ]; then
  62. app=mpv
  63. # To start mpv in a window enable video_opts
  64. #video_opts="--no-terminal --force-window"
  65. #bg=">/dev/null 2>&1 &"
  66. if [ -n "$bg" ]; then
  67. killall -9 $app >/dev/null 2>&1
  68. fi
  69. eval $app $video_opts "\"$1\"" $bg
  70. exit 0
  71. fi
  72. #------------------ IMAGE -------------------
  73. if [ "$2" == "image" ]; then
  74. app=viewnior
  75. #image_opts=
  76. bg=">/dev/null 2>&1 &"
  77. eval $app $image_opts "\"$1\"" $bg
  78. exit 0
  79. fi
  80. #------------------- PDF --------------------
  81. if [ "$2" == "pdf" ]; then
  82. app=zathura
  83. #pdf_opts=
  84. bg=">/dev/null 2>&1 &"
  85. eval $app $pdf_opts "\"$1\"" $bg
  86. exit 0
  87. fi
  88. #---------------- PLAINTEXT -----------------
  89. if [ "$2" == "text" ]; then
  90. app=vim
  91. #txt_opts=
  92. #bg=">/dev/null 2>&1 &"
  93. eval $app $txt_opts "\"$1\"" $bg
  94. exit 0
  95. fi