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.
 
 
 
 
 
 

84 lignes
1.8 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 [ "$1" = "master" ] ; then
  39. VER="master"
  40. ARCHIVE_URL=https://github.com/jarun/nnn/archive/master.tar.gz
  41. elif which nnn >/dev/null 2>&1; then
  42. VER=$(nnn -V)
  43. ARCHIVE_URL=https://github.com/jarun/nnn/releases/download/v"$VER"/nnn-v"$VER".tar.gz
  44. else
  45. echo "nnn is not installed"
  46. exit 1
  47. fi
  48. # backup any earlier plugins
  49. if [ -d "$PLUGIN_DIR" ]; then
  50. tar -C "$CONFIG_DIR" -czf "$CONFIG_DIR""plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
  51. fi
  52. mkdir -p "$PLUGIN_DIR"
  53. cd "$CONFIG_DIR" || exit 1
  54. curl -Ls "$ARCHIVE_URL" -o nnn-"$VER".tar.gz
  55. tar -zxf nnn-"$VER".tar.gz
  56. cd nnn-"$VER"/plugins || exit 1
  57. # shellcheck disable=SC2044
  58. # We do not use obnoxious names for plugins
  59. for f in $(find . -maxdepth 1 \( ! -iname "." ! -iname "*.md" \)); do
  60. if [ -f ../../plugins/"$f" ]; then
  61. if [ "$(diff --brief "$f" ../../plugins/"$f")" ]; then
  62. prompt "$f"
  63. $op "$f" ../../plugins/
  64. fi
  65. else
  66. cp -vRf "$f" ../../plugins/
  67. fi
  68. done
  69. cd ../.. || exit 1
  70. rm -rf nnn-"$VER"/ nnn-"$VER".tar.gz