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.
 
 
 
 
 
 

67 lignes
1.4 KiB

  1. #!/usr/bin/env sh
  2. # Description: Update nnn plugins
  3. #
  4. # Shell: POSIX compliant
  5. # Author: Arun Prakash Jana, KlzXS
  6. CONFIG_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/
  7. PLUGIN_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
  8. is_cmd_exists () {
  9. which "$1" > /dev/null 2>&1
  10. echo $?
  11. }
  12. merge () {
  13. vimdiff +0 "$1" "$2"
  14. }
  15. prompt () {
  16. printf "%s" "Plugin $1 already exists and is different.\n"
  17. printf "Keep (k), merge (m), overwrite (o) [default: k]? "
  18. read -r operation
  19. if [ "$operation" = "m" ]; then
  20. op="merge"
  21. elif [ "$operation" = "o" ]; then
  22. op="cp -vRf"
  23. else
  24. op="true"
  25. fi
  26. }
  27. if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
  28. sucmd=sudo
  29. elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
  30. sucmd=doas
  31. else
  32. sucmd=: # noop
  33. fi
  34. # backup any earlier plugins
  35. if [ -d "$PLUGIN_DIR" ]; then
  36. tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
  37. fi
  38. mkdir -p "$PLUGIN_DIR"
  39. cd "$CONFIG_DIR" || exit 1
  40. curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
  41. tar -zxf master.tar.gz
  42. cd nnn-master/plugins || exit 1
  43. for f in *; do
  44. if [ -f ../../plugins/"$f" ]; then
  45. if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
  46. prompt "$f"
  47. $op "$f" ../../plugins/
  48. fi
  49. else
  50. cp -vRf "$f" ../../plugins/
  51. fi
  52. done
  53. cd ../.. || exit 1
  54. $sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
  55. rm -rf nnn-master/ master.tar.gz "$PLUGIN_DIR"/README.md