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.
 
 
 
 
 
 

74 lignes
1.4 KiB

  1. #!/usr/bin/env sh
  2. # Description: Backup of all nnn config
  3. #
  4. # Shell: POSIX compliant
  5. # Author: Léo Villeveygoux
  6. nnn_aliases="n nnn"
  7. outdir="nnn-$(whoami)@$(hostname)"
  8. outfile="${outdir}.tar.bz2"
  9. shellname="$(basename "$SHELL")"
  10. conffile="config.txt"
  11. configdir="${XDG_CONFIG_HOME:-$HOME/.config}/nnn"
  12. workdir="$PWD"
  13. tempdir="$(mktemp -d)"
  14. mkdir "$tempdir/$outdir"
  15. if [ ! -d "$tempdir" ]; then
  16. echo "Can't create work directory." >&2
  17. exit 1
  18. fi
  19. cd "$tempdir/$outdir" || exit 1
  20. # Backing up config dir content
  21. cp -r "$configdir" . || exit 1
  22. # Environment config
  23. env | sed "s/'/'\\\\''/" |\
  24. awk '/^NNN_/{print "export '\''"$0"'\''"}' > "$conffile"
  25. # Shell functions/aliases
  26. case "$shellname" in
  27. bash)
  28. for name in $nnn_aliases ; do
  29. if [ "$(bash -ic "type -t $name")" = "function" ] ; then
  30. bash -ic "type $name" | tail -n+2 >> "$conffile"
  31. elif bash -ic "alias $name" >/dev/null 2>&1 ; then
  32. bash -ic "alias $name" >> "$conffile"
  33. fi
  34. done
  35. ;;
  36. zsh)
  37. for name in $nnn_aliases ; do
  38. if zsh -ic "functions $name" ; then
  39. zsh -ic "functions $name" >> "$conffile"
  40. elif zsh -ic "alias $name" ; then
  41. echo alias "$(zsh -ic "alias $name")" >> "$conffile"
  42. fi
  43. done
  44. ;;
  45. *)
  46. echo "Unknown shell, skipping alias/function checking." >&2
  47. ;;
  48. esac
  49. cd .. || exit 1
  50. printf "Saving as '%s' ... " "$workdir/$outfile"
  51. tar caf "$workdir/$outfile" "$outdir" && echo "Done" || echo "Failed"
  52. cd "$workdir" && rm -rf "$tempdir"