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.4 KiB

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