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.
 
 
 
 
 
 

67 lines
1.3 KiB

  1. #!/usr/bin/env sh
  2. # Description: Update nnn plugins
  3. #
  4. # Shell: POSIX compliant
  5. # Author: Arun Prakash Jana
  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 $1 $2
  14. cp -vRf $1 $2
  15. }
  16. prompt () {
  17. echo "Plugin $1 already exists and is different."
  18. echo -n "Keep (k), merge (m), overwrite (o) [default: k]? "
  19. read operation
  20. if [ "$operation" = "m" ]; then
  21. op="merge"
  22. elif [ "$operation" = "o" ]; then
  23. op="cp -vRf"
  24. else
  25. op="true"
  26. fi
  27. }
  28. if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
  29. sucmd=sudo
  30. elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
  31. sucmd=doas
  32. else
  33. sucmd=: # noop
  34. fi
  35. # backup any earlier plugins
  36. if [ -d $PLUGIN_DIR ]; then
  37. tar -C $CONFIG_DIR -czf $CONFIG_DIR"plugins-$(date '+%Y%m%d%H%M').tar.gz" plugins/
  38. fi
  39. cd $CONFIG_DIR
  40. curl -Ls -O https://github.com/jarun/nnn/archive/master.tar.gz
  41. tar -zxf master.tar.gz
  42. cd nnn-master/plugins
  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 ../..
  54. $sucmd mv -vf nnn-master/misc/nlaunch/nlaunch /usr/local/bin/
  55. rm -rf nnn-master/ master.tar.gz README.md