My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 line
3.1 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. 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 audio_opts
  55. #audio_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 $audio_opts "\"$1\"" $bg
  61. exit 0
  62. fi
  63. #------------------ VIDEO -------------------
  64. if [ "$2" == "video" ]; then
  65. app=mpv
  66. # To start mpv in a window enable video_opts
  67. #video_opts="--no-terminal --force-window"
  68. #bg=">/dev/null 2>&1 &"
  69. if [ -n "$bg" ]; then
  70. killall -9 $app >/dev/null 2>&1
  71. fi
  72. eval $app $video_opts "\"$1\"" $bg
  73. exit 0
  74. fi
  75. #------------------ IMAGE -------------------
  76. if [ "$2" == "image" ]; then
  77. app=viewnior
  78. #image_opts=
  79. bg=">/dev/null 2>&1 &"
  80. eval $app $image_opts "\"$1\"" $bg
  81. exit 0
  82. fi
  83. #------------------- PDF --------------------
  84. if [ "$2" == "pdf" ]; then
  85. app=zathura
  86. #pdf_opts=
  87. bg=">/dev/null 2>&1 &"
  88. eval $app $pdf_opts "\"$1\"" $bg
  89. exit 0
  90. fi
  91. #---------------- PLAINTEXT -----------------
  92. if [ "$2" == "text" ]; then
  93. app=vim
  94. #txt_opts=
  95. #bg=">/dev/null 2>&1 &"
  96. eval $app $txt_opts "\"$1\"" $bg
  97. exit 0
  98. fi