My build of nnn with minor changes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

121 lignes
2.9 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. Keep a personal backup (on GitHub Gist maybe?) of this file if you modify
  28. # it. nlay is OVERWRITTEN during nnn upgrade.
  29. #
  30. # Author: Arun Prakash Jana
  31. # Email: engineerarun@gmail.com
  32. # #############################################################################
  33. # Enable the lines below to handle file by extension
  34. # This is provided for using a custom player for specific files
  35. # $ext holds the extension
  36. <<ENABLE_FILE_TYPE_HANDLING
  37. fname=$(basename "$1")
  38. if [[ $fname != *"."* ]]; then
  39. exit 1
  40. fi
  41. ext="${fname##*.}"
  42. if [ -z "$ext" ]; then
  43. exit 1
  44. fi
  45. # bash 4.0 way to switch to lowercase
  46. ext="${ext,,}"
  47. # handle this extension and exit
  48. ENABLE_FILE_TYPE_HANDLING
  49. #------------------ AUDIO -------------------
  50. if [ "$2" == "audio" ]; then
  51. app=mpv
  52. # To start mpv in a window enable audio_opts
  53. #audio_opts="--no-terminal --force-window"
  54. #bg=">/dev/null 2>&1 &"
  55. if [ -n "$bg" ]; then
  56. killall -9 $app >/dev/null 2>&1
  57. fi
  58. eval $app $audio_opts "\"$1\"" $bg
  59. exit 0
  60. fi
  61. #------------------ VIDEO -------------------
  62. if [ "$2" == "video" ]; then
  63. app=mpv
  64. # To start mpv in a window enable video_opts
  65. #video_opts="--no-terminal --force-window"
  66. #bg=">/dev/null 2>&1 &"
  67. if [ -n "$bg" ]; then
  68. killall -9 $app >/dev/null 2>&1
  69. fi
  70. eval $app $video_opts "\"$1\"" $bg
  71. exit 0
  72. fi
  73. #------------------ IMAGE -------------------
  74. if [ "$2" == "image" ]; then
  75. app=viewnior
  76. #image_opts=
  77. bg=">/dev/null 2>&1 &"
  78. eval $app $image_opts "\"$1\"" $bg
  79. exit 0
  80. fi
  81. #------------------- PDF --------------------
  82. if [ "$2" == "pdf" ]; then
  83. app=zathura
  84. #pdf_opts=
  85. bg=">/dev/null 2>&1 &"
  86. eval $app $pdf_opts "\"$1\"" $bg
  87. exit 0
  88. fi
  89. #---------------- PLAINTEXT -----------------
  90. if [ "$2" == "text" ]; then
  91. app=vim
  92. #txt_opts=
  93. #bg=">/dev/null 2>&1 &"
  94. eval $app $txt_opts "\"$1\"" $bg
  95. exit 0
  96. fi