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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #opts=
  65. #bg=">/dev/null 2>&1 &"
  66. type -P $app &>/dev/null &&
  67. eval $app $opts $bg
  68. exit 0
  69. fi
  70. #----------------- RUN APP ------------------
  71. for index in ${!app[@]}
  72. do
  73. type -P ${app[$index]} &>/dev/null &&
  74. eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]} &&
  75. break
  76. done