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.
 
 
 
 
 
 

106 lignes
2.7 KiB

  1. #!/usr/bin/env bash
  2. # #############################################################################
  3. # nlay: a customizable script to play files in different apps by file type
  4. #
  5. # usage: nlay file/path type/action
  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 preferences and type of utility, e.g., I
  15. # would start vi (CLI) in the foreground but Sublime Text (GUI) in background.
  16. #
  17. # Check (and TOGGLE as you wish) the default bg settings.
  18. #
  19. # 2. Detached apps are not killed when nnn exits. Use kill(1) or killall(1) to
  20. # stop console based background apps.
  21. #
  22. # 3. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
  23. # location other than the default and have an alias with nnn option '-p' to
  24. # invoke it. Remember it might break or lack new capabilities added to nlay
  25. # in future releases. Check the file diff once in a while.
  26. #
  27. # Author: Arun Prakash Jana
  28. # Email: engineerarun@gmail.com
  29. # Homepage: https://github.com/jarun/nnn
  30. # Copyright © 2016-2018 Arun Prakash Jana
  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 (UNUSED) ------------
  49. if [ "$2" == "text" ]; then
  50. app=("vi")
  51. opts=("")
  52. bg=("")
  53. #----------------- SEARCH -------------------
  54. elif [ "$2" == "search" ]; then
  55. app=("gnome-search-tool"
  56. "catfish")
  57. opts=("--path"
  58. "--path")
  59. bg=(">/dev/null 2>&1 &"
  60. ">/dev/null 2>&1 &")
  61. #--------------- SCREENSAVER ----------------
  62. elif [ "$2" == "screensaver" ]; then
  63. app=("vlock"
  64. "bashlock"
  65. "lock")
  66. for index in ${!app[@]}
  67. do
  68. type -P ${app[$index]} &>/dev/null &&
  69. eval ${app[$index]} &&
  70. exit 0
  71. done
  72. #------------------ SCRIPT ------------------
  73. elif [ "$2" == "script" ]; then
  74. # add commands or a custom script below
  75. # echo "my commands or custom script"
  76. # sh "path_to_script.sh"
  77. $SHELL "$1"
  78. exit 0
  79. fi
  80. #----------------- RUN APP ------------------
  81. for index in ${!app[@]}
  82. do
  83. type -P ${app[$index]} &>/dev/null &&
  84. eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]} &&
  85. break
  86. done