From 1d04de74017013cf94479d1f8177d16327569431 Mon Sep 17 00:00:00 2001 From: Tri Vo Khac Date: Mon, 5 Jun 2023 13:08:15 +0700 Subject: [PATCH] refactor: - use `zap-zsh` instead of manual plugin manager - rename local plugins to meet naming conventions --- zsh/.config/zsh/.gitignore | 1 - zsh/.config/zsh/.zshrc | 77 ++++---------------- zsh/.config/zsh/{zsh-aliases => aliases.zsh} | 2 +- zsh/.config/zsh/{zsh-eval => eval.zsh} | 3 +- zsh/.config/zsh/{zsh-exports => exports.zsh} | 3 +- zsh/.config/zsh/zsh-functions | 68 ----------------- 6 files changed, 17 insertions(+), 137 deletions(-) rename zsh/.config/zsh/{zsh-aliases => aliases.zsh} (87%) rename zsh/.config/zsh/{zsh-eval => eval.zsh} (66%) rename zsh/.config/zsh/{zsh-exports => exports.zsh} (82%) delete mode 100644 zsh/.config/zsh/zsh-functions diff --git a/zsh/.config/zsh/.gitignore b/zsh/.config/zsh/.gitignore index c0df0c3..dffc945 100644 --- a/zsh/.config/zsh/.gitignore +++ b/zsh/.config/zsh/.gitignore @@ -1,5 +1,4 @@ .zcompdump .zsh_history -plugins/ .zcompcache/ .zsh_sessions/ diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc index 948d90d..35f748f 100644 --- a/zsh/.config/zsh/.zshrc +++ b/zsh/.config/zsh/.zshrc @@ -1,77 +1,28 @@ -#!/usr/bin/env zsh +# Created by Zap installer +[ -f "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" ] && source "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" -# some useful options (man zshoptions) -setopt AUTO_CD EXTENDED_GLOB NOMATCH MENU_COMPLETE -setopt INTERACTIVE_COMMENTS -stty stop undef # Disable ctrl-s to freeze terminal. -zle_highlight=('paste:none') - -# history -setopt APPEND_HISTORY -setopt INC_APPEND_HISTORY -setopt HIST_EXPIRE_DUPS_FIRST -setopt HIST_IGNORE_DUPS -setopt HIST_IGNORE_ALL_DUPS -setopt HIST_IGNORE_SPACE -setopt HIST_FIND_NO_DUPS -setopt HIST_SAVE_NO_DUPS - -unsetopt EXTENDED_HISTORY - -# beeping is annoying -unsetopt BEEP - -# remove % symbol on prompt -unsetopt PROMPT_SP - -# completions - -# for brew -if type brew &>/dev/null -then - FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}" -fi - -autoload -Uz compinit -zstyle ':completion:*' menu select -# zstyle ':completion::complete:lsof:*' menu yes select -zmodload zsh/complist -# compinit -_comp_options+=(globdots) # Include hidden files. - -autoload -U up-line-or-beginning-search -autoload -U down-line-or-beginning-search -zle -N up-line-or-beginning-search -zle -N down-line-or-beginning-search - -# Colors -autoload -Uz colors && colors - -# Useful Functions -source "$ZDOTDIR/zsh-functions" - -# Normal files to source -zsh_add_file "zsh-exports" -zsh_add_file "zsh-aliases" -zsh_add_file "zsh-eval" - -# Plugins repos=( + # remote plugins zsh-users/zsh-autosuggestions zsh-users/zsh-completions + wintermi/zsh-brew + wintermi/zsh-lsd + zap-zsh/supercharge zap-zsh/fzf zap-zsh/fnm zdharma-continuum/fast-syntax-highlighting hlissner/zsh-autopair - wintermi/zsh-lsd + # local plugins + "$ZDOTDIR/aliases.zsh" + "$ZDOTDIR/exports.zsh" + "$ZDOTDIR/eval.zsh" ) -plugin-load $repos + +for repo in $repos; do plug $repo; done # Clean startup prompt ! [ -f ~/.hushlogin ] && touch ~/.hushlogin +# Load and initialise completion system +autoload -Uz compinit compinit - -# Edit line in vim with ctrl-e: -autoload edit-command-line; zle -N edit-command-line -# bindkey '^e' edit-command-line diff --git a/zsh/.config/zsh/zsh-aliases b/zsh/.config/zsh/aliases.zsh similarity index 87% rename from zsh/.config/zsh/zsh-aliases rename to zsh/.config/zsh/aliases.zsh index b9e8313..f438a9c 100644 --- a/zsh/.config/zsh/zsh-aliases +++ b/zsh/.config/zsh/aliases.zsh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh [ -x "$(command -v bat)" ] && alias cat="bat" [ -x "$(command -v codium)" ] && alias code="codium" diff --git a/zsh/.config/zsh/zsh-eval b/zsh/.config/zsh/eval.zsh similarity index 66% rename from zsh/.config/zsh/zsh-eval rename to zsh/.config/zsh/eval.zsh index 983a709..a94565f 100644 --- a/zsh/.config/zsh/zsh-eval +++ b/zsh/.config/zsh/eval.zsh @@ -1,6 +1,5 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh -[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)" command -v zoxide > /dev/null 2>&1 && eval "$(zoxide init zsh)" command -v starship > /dev/null 2>&1 && eval "$(starship init zsh)" command -v opam > /dev/null 2>&1 && eval $(opam env) diff --git a/zsh/.config/zsh/zsh-exports b/zsh/.config/zsh/exports.zsh similarity index 82% rename from zsh/.config/zsh/zsh-exports rename to zsh/.config/zsh/exports.zsh index 9c4c9c3..15d72eb 100644 --- a/zsh/.config/zsh/zsh-exports +++ b/zsh/.config/zsh/exports.zsh @@ -1,11 +1,10 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh HISTFILE="$ZDOTDIR"/.zsh_history HISTSIZE=1000000 SAVEHIST=1000000 export MANWIDTH=999 -export PATH="$HOME/.local/bin":$PATH export EDITOR="micro" export PAGE="bat" diff --git a/zsh/.config/zsh/zsh-functions b/zsh/.config/zsh/zsh-functions deleted file mode 100644 index 59c43f7..0000000 --- a/zsh/.config/zsh/zsh-functions +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env zsh - -# Function to source files if they exist -function zsh_add_file() { - [ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1" -} - -function zsh_add_plugin() { - PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) - if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then - # For plugins - zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \ - zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh" - else - git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" - fi -} - -function zsh_add_completion() { - PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) - if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then - # For completions - completion_file_path=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) - fpath+="$(dirname "${completion_file_path}")" - zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" - else - git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" - fpath+=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) - [ -f $ZDOTDIR/.zccompdump ] && $ZDOTDIR/.zccompdump - fi - completion_file="$(basename "${completion_file_path}")" - [ "$2" = true ] && compinit "${completion_file:1}" -} - -# https://github.com/mattmc3/zsh_unplugged -function plugin-load { - local repo plugdir initfile - ZPLUGINDIR=${ZPLUGINDIR:-${ZDOTDIR:-$HOME/.config/zsh}/plugins} - for repo in $@; do - plugdir=$ZPLUGINDIR/${repo:t} - initfile=$plugdir/${repo:t}.plugin.zsh - if [[ ! -d $plugdir ]]; then - echo "Cloning $repo..." - git clone -q --depth 1 --recursive --shallow-submodules https://github.com/$repo $plugdir - fi - if [[ ! -e $initfile ]]; then - local -a initfiles=($plugdir/*.plugin.{z,}sh(N) $plugdir/*.{z,}sh{-theme,}(N)) - (( $#initfiles )) || { echo >&2 "No init file found '$repo'." && continue; } - ln -sf "${initfiles[1]}" "$initfile" - fi - fpath+=$plugdir - (( $+functions[zsh-defer] )) && zsh-defer . $initfile || . $initfile - done -} - -function plugin-update { - ZPLUGINDIR=${ZPLUGINDIR:-$HOME/.config/zsh/plugins} - for d in $ZPLUGINDIR/*/.git(/); do - echo "Updating ${d:h:t}..." - command git -C "${d:h}" pull --ff --recurse-submodules --depth 1 --rebase --autostash - done -} - -function plugin-list { - for d in $ZPLUGINDIR/*/.git; do - git -C "${d:h}" remote get-url origin - done -}