My build of nnn with minor changes
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

80 linhas
1.7 KiB

  1. #!/usr/bin/env sh
  2. # Description: Update nnn plugins to installed nnn version
  3. #
  4. # Shell: POSIX compliant
  5. # Authors: 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. if which nvim >/dev/null 2>&1; then
  14. nvim -d "$1" "$2"
  15. else
  16. vimdiff +0 "$1" "$2"
  17. fi
  18. }
  19. prompt () {
  20. printf "%s\n" "Plugin $1 already exists and is different."
  21. printf "Keep (k), merge (m), overwrite (o) [default: k]? "
  22. read -r operation
  23. if [ "$operation" = "m" ]; then
  24. op="merge"
  25. elif [ "$operation" = "o" ]; then
  26. op="cp -vRf"
  27. else
  28. op="true"
  29. fi
  30. }
  31. # if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
  32. # sucmd=sudo
  33. # elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
  34. # sucmd=doas
  35. # else
  36. # sucmd=: # noop
  37. # fi
  38. if which nnn >/dev/null 2>&1; then
  39. VER=$(nnn -V)
  40. else
  41. echo "nnn is not installed"
  42. exit 1
  43. fi
  44. # backup any earlier plugins
  45. if [ -d "$PLUGIN_DIR" ]; then
  46. tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
  47. fi
  48. mkdir -p "$PLUGIN_DIR"
  49. cd "$CONFIG_DIR" || exit 1
  50. curl -Ls -O https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
  51. tar -zxf nnn-v"$VER".tar.gz
  52. cd nnn-"$VER"/plugins || exit 1
  53. # shellcheck disable=SC2044
  54. # We do not use obnoxious names for plugins
  55. for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
  56. if [ -f ../../plugins/"$f" ]; then
  57. if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
  58. prompt "$f"
  59. $op "$f" ../../plugins/
  60. fi
  61. else
  62. cp -vRf "$f" ../../plugins/
  63. fi
  64. done
  65. cd ../.. || exit 1
  66. rm -rf nnn-"$VER"/ nnn-v"$VER".tar.gz