My build of nnn with minor changes
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

148 рядки
3.6 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 opts and
  11. # bg settings. If bg is set the app is detached and started in the background
  12. # in 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. I also prefer mpv running in the background without disturbing
  17. # my ongoing activity in nnn by blocking navigation.
  18. #
  19. # Check (and TOGGLE as you wish) the default bg settings.
  20. #
  21. # 2. Detached apps are not killed when nnn exits. Use kill(1) or killall(1) to
  22. # to stop console based background apps.
  23. #
  24. # 3. Assuming you don't to play multiple audio/video files simultaneously,
  25. # nlay kills any running instances of the audio/video player in bg mode.
  26. #
  27. # 4. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
  28. # location other than the default and have an alias with nnn option '-p' to
  29. # invoke it. Remember it might break or lack new capabilities added to nlay
  30. # in future releases. Check the file diff once in a while.
  31. #
  32. # Author: Arun Prakash Jana
  33. # Email: engineerarun@gmail.com
  34. # #############################################################################
  35. # Enable the lines below to handle file by extension
  36. # This is provided for using a custom player for specific files
  37. # $ext holds the extension
  38. <<ENABLE_FILE_TYPE_HANDLING
  39. fname=$(basename "$1")
  40. if [[ $fname != *"."* ]]; then
  41. exit 1
  42. fi
  43. ext="${fname##*.}"
  44. if [ -z "$ext" ]; then
  45. exit 1
  46. fi
  47. # bash 4.0 way to switch to lowercase
  48. ext="${ext,,}"
  49. # handle this extension and exit
  50. ENABLE_FILE_TYPE_HANDLING
  51. #------------------ AUDIO -------------------
  52. if [ "$2" == "audio" ]; then
  53. app=mpv
  54. # To start mpv in a window enable opts
  55. #opts="--no-terminal --force-window"
  56. #bg=">/dev/null 2>&1 &"
  57. if [ -n "$bg" ]; then
  58. killall -9 $app >/dev/null 2>&1
  59. fi
  60. eval $app $opts "\"$1\"" $bg
  61. exit 0
  62. #------------------ VIDEO -------------------
  63. elif [ "$2" == "video" ]; then
  64. app=mpv
  65. # To start mpv in a window enable opts
  66. #opts="--no-terminal --force-window"
  67. #bg=">/dev/null 2>&1 &"
  68. if [ -n "$bg" ]; then
  69. killall -9 $app >/dev/null 2>&1
  70. fi
  71. eval $app $opts "\"$1\"" $bg
  72. exit 0
  73. #------------------ IMAGE -------------------
  74. elif [ "$2" == "image" ]; then
  75. app=("viewnior"
  76. "fim")
  77. opts=(""
  78. "-a --cd-and-readdir")
  79. bg=(">/dev/null 2>&1 &"
  80. ">/dev/null 2>&1 &")
  81. #------------------- PDF --------------------
  82. elif [ "$2" == "pdf" ]; then
  83. app=("zathura")
  84. opts=("")
  85. bg=(">/dev/null 2>&1 &")
  86. #---------------- PLAINTEXT -----------------
  87. elif [ "$2" == "text" ]; then
  88. app=("vim")
  89. opts=("")
  90. bg=("")
  91. #----------------- SEARCH -------------------
  92. elif [ "$2" == "search" ]; then
  93. app=("gnome-search-tool"
  94. "catfish")
  95. opts=(""
  96. "--path")
  97. bg=(">/dev/null 2>&1 &"
  98. ">/dev/null 2>&1 &")
  99. #--------------- SCREENSAVER ----------------
  100. elif [ "$2" == "screensaver" ]; then
  101. app=vlock
  102. #opts=
  103. #bg=">/dev/null 2>&1 &"
  104. type -P $app &>/dev/null &&
  105. eval $app $opts $bg
  106. exit 0
  107. fi
  108. #------------------- PLAY -------------------
  109. for index in ${!app[@]}
  110. do
  111. type -P ${app[$index]} &>/dev/null &&
  112. eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]}
  113. done