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.
 
 
 
 
 
 

94 line
2.4 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 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. # #############################################################################
  31. # Enable the lines below to handle file by extension
  32. # This is provided for using a custom player for specific files
  33. # $ext holds the extension
  34. <<ENABLE_FILE_TYPE_HANDLING
  35. fname=$(basename "$1")
  36. if [[ $fname != *"."* ]]; then
  37. exit 1
  38. fi
  39. ext="${fname##*.}"
  40. if [ -z "$ext" ]; then
  41. exit 1
  42. fi
  43. # bash 4.0 way to switch to lowercase
  44. ext="${ext,,}"
  45. # handle this extension and exit
  46. ENABLE_FILE_TYPE_HANDLING
  47. #------------ PLAINTEXT (UNUSED) ------------
  48. if [ "$2" == "text" ]; then
  49. app=("vim")
  50. opts=("")
  51. bg=("")
  52. #----------------- SEARCH -------------------
  53. elif [ "$2" == "search" ]; then
  54. app=("gnome-search-tool"
  55. "catfish")
  56. opts=(""
  57. "--path")
  58. bg=(">/dev/null 2>&1 &"
  59. ">/dev/null 2>&1 &")
  60. #--------------- SCREENSAVER ----------------
  61. elif [ "$2" == "screensaver" ]; then
  62. app=vlock
  63. #opts=
  64. #bg=">/dev/null 2>&1 &"
  65. type -P $app &>/dev/null &&
  66. eval $app $opts $bg
  67. exit 0
  68. fi
  69. #------------------- PLAY -------------------
  70. for index in ${!app[@]}
  71. do
  72. type -P ${app[$index]} &>/dev/null &&
  73. eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]} &&
  74. break
  75. done