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.

nlay 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
  25. # location other than the default and have an alias with nnn option '-p' to
  26. # invoke it. Remember it might break or lack new capabilities added to nlay
  27. # in future releases. Check the file diff once in a while.
  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. #---------------- PLAINTEXT -----------------
  49. if [ "$2" == "text" ]; then
  50. app=("vim")
  51. opts=("")
  52. bg=("")
  53. #----------------- SEARCH -------------------
  54. elif [ "$2" == "search" ]; then
  55. app=("gnome-search-tool"
  56. "catfish")
  57. opts=(""
  58. "--path")
  59. bg=(">/dev/null 2>&1 &"
  60. ">/dev/null 2>&1 &")
  61. #--------------- SCREENSAVER ----------------
  62. elif [ "$2" == "screensaver" ]; then
  63. app=vlock
  64. #opts=
  65. #bg=">/dev/null 2>&1 &"
  66. type -P $app &>/dev/null &&
  67. eval $app $opts $bg
  68. exit 0
  69. fi
  70. #------------------- PLAY -------------------
  71. for index in ${!app[@]}
  72. do
  73. type -P ${app[$index]} &>/dev/null &&
  74. eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]}
  75. done