.zshrc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. unsetopt HIST_SAVE_NO_DUPS #HIST DUPS SHOULD BE ALSO SAVED
  2. GREEN='\033[0;32m'
  3. RED='\033[0;31m'
  4. WHITE='\033[0;37m'
  5. RESET='\033[0m'
  6. autoload -U compinit && compinit #COMPLETION
  7. zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' #CASE-INSENSITIVE COMPLETION
  8. _comp_options+=(globdots) #HIDEN FILES
  9. setopt AUTO_PUSHD #PUSH THE CURRENT DIRECTORY TO THE VISITED STACK
  10. setopt PUSHD_IGNORE_DUPS #PUSH ONLY NEW DIRS
  11. setopt PUSHD_SILENT #DO NOT PRINT ANYTHING
  12. stty stop undef #DISABLE TERMINAL FREEZE
  13. unsetopt BEEP #DISABLE BEEP
  14. function zsh_add_file() {
  15. [ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1"
  16. }
  17. function zsh_add_plugin() {
  18. PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2)
  19. if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
  20. zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \
  21. zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh"
  22. echo "${RED}Plugged in ${GREEN}$PLUGIN_NAME${RED}!${RESET}\n"
  23. else
  24. GIT_SITE=$2
  25. [ -v $GIT_SITE ] && GIT_SITE="https://github.com/"
  26. echo "${RED}Downloading ${GREEN}$PLUGIN_NAME ${RED}plugin...${RESET}"
  27. git clone "$GIT_SITE/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" > /dev/null 2>&1 && echo "${RED}Successfully downloaded ${GREEN}$PLUGIN_NAME ${RED}plugin!${RESET}" && zsh_add_plugin $1
  28. fi
  29. }
  30. function zsh_add_theme() {
  31. THEME_NAME=$(echo $1 | cut -d "/" -f 2)
  32. if [ -d "$ZDOTDIR/themes/$THEME_NAME" ]; then
  33. zsh_add_file "themes/$THEME_NAME/$THEME_NAME.zsh-theme"
  34. echo "${RED}Themed a ${GREEN}$THEME_NAME ${RED}theme!${RESET}\n"
  35. else
  36. GIT_SITE=$2
  37. [ -v $GIT_SITE ] && GIT_SITE="https://github.com"
  38. echo "${RED}Downloading ${GREEN}$THEME_NAME ${RED}theme...${RESET}"
  39. git clone "$GIT_SITE/$1.git" "$ZDOTDIR/themes/$THEME_NAME" > /dev/null 2>&1 && echo "${RED}Successfully downloaded ${GREEN}$THEME_NAME ${RED}theme!${RESET}" && zsh_add_theme $1
  40. fi
  41. }
  42. function zsh_add_completion() {
  43. COMPLETION_NAME=$(echo $1 | cut -d "/" -f 2)
  44. if [ -d "$ZDOTDIR/completions/$COMPLETION_NAME" ]; then
  45. completion_file_path=$(ls $ZDOTDIR/completions/$COMPLETION_NAME/_*)
  46. fpath+="$(dirname "${completion_file_path}")"
  47. zsh_add_file "completions/$COMPLETION_NAME/$COMPLETION_NAME/.plugin.zsh"
  48. echo "${RED}Inserted a completion: ${GREEN}$COMPLETION_NAME${RED}!${RESET}\n"
  49. else
  50. GIT_SITE=$3
  51. [ -v $GIT_SITE ] && GIT_SITE="https://github.com"
  52. echo "${RED}Downloading ${GREEN}$COMPLETION_NAME ${RED}completion...${RESET}"
  53. git clone "$GIT_SITE/$1.git" "$ZDOTDIR/completions/$COMPLETION_NAME" > /dev/null 2>&1 && echo "${RED}Successfully downloaded ${GREEN}$COMPLETION_NAME ${RED}completion!${RESET}"
  54. fpath+=$(ls $ZDOTDIR/completions/$COMPLETION_NAME/_*)
  55. zsh_add_completion $1
  56. return
  57. fi
  58. completion_file="$(basename "${completion_file_path}")"
  59. if [ "$2" = true ] && compinit "${completion_file:1}"
  60. }
  61. function zsh-update() {
  62. return_dir=$(pwd)
  63. zsh_update_git_subfolders "plugins"
  64. zsh_update_git_subfolders "themes"
  65. zsh_update_git_subfolders "completions"
  66. cd $return_dir
  67. }
  68. function zsh_update_git_subfolders() {
  69. directory="$ZDOTDIR/$1"
  70. echo "${RED}Updating ${GREEN}$1...${RESET}\n"
  71. cd $directory
  72. for D in *; do
  73. if [ -d "${D}" ]; then
  74. cd $D
  75. echo "${RED}Updating ${GREEN}$(echo $D | cut -d "/" -f 2)${RED}..."
  76. git pull
  77. cd $directory
  78. fi
  79. done
  80. echo "${RESET}"
  81. return
  82. }
  83. zsh_add_file ".zaliases" #IMPORT ALIASES
  84. zsh_add_plugin "zsh-users/zsh-autosuggestions"
  85. zsh_add_plugin "zsh-users/zsh-syntax-highlighting"
  86. zsh_add_theme "jackharrisonsherlock/common"
  87. zsh_add_completion "esc/conda-zsh-completion" false
  88. clear
  89. autoload -U promptinit
  90. promptinit