zsh-navigation-tools.plugin.zsh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env zsh
  2. 0="${(%):-%N}" # this gives immunity to functionargzero being unset
  3. export ZNT_REPO_DIR="${0%/*}"
  4. export ZNT_CONFIG_DIR="$HOME/.config/znt"
  5. #
  6. # Copy configs
  7. #
  8. if [[ ! -d "$HOME/.config" ]]; then
  9. command mkdir "$HOME/.config"
  10. fi
  11. if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
  12. command mkdir "$ZNT_CONFIG_DIR"
  13. fi
  14. # 9 files
  15. unset __ZNT_CONFIG_FILES
  16. typeset -ga __ZNT_CONFIG_FILES
  17. set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
  18. # Check for random 2 files if they exist
  19. # This will shift 0 - 7 elements
  20. shift $(( RANDOM % 8 )) __ZNT_CONFIG_FILES
  21. if [[ ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[1]}" || ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[2]}" ]]; then
  22. # Something changed - examine every file
  23. set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
  24. unset __ZNT_CONFIG_FILE
  25. typeset -g __ZNT_CONFIG_FILE
  26. for __ZNT_CONFIG_FILE in "${__ZNT_CONFIG_FILES[@]}"; do
  27. if [[ ! -f "$ZNT_CONFIG_DIR/$__ZNT_CONFIG_FILE" ]]; then
  28. command cp "$ZNT_REPO_DIR/.config/znt/$__ZNT_CONFIG_FILE" "$ZNT_CONFIG_DIR"
  29. fi
  30. done
  31. unset __ZNT_CONFIG_FILE
  32. fi
  33. unset __ZNT_CONFIG_FILES
  34. #
  35. # Load functions
  36. #
  37. autoload n-aliases n-cd n-env n-functions n-history n-kill n-list n-list-draw n-list-input n-options n-panelize n-help
  38. autoload znt-usetty-wrapper znt-history-widget znt-cd-widget znt-kill-widget
  39. alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
  40. alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
  41. zle -N znt-history-widget
  42. bindkey '^R' znt-history-widget
  43. setopt AUTO_PUSHD HIST_IGNORE_DUPS PUSHD_IGNORE_DUPS
  44. zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'