Переход на менеджер https://github.com/jandamm/zgenom

This commit is contained in:
Andrei Astafev 2021-11-06 19:50:38 +03:00
parent e9b976f5f2
commit 00bd63ccc6
14 changed files with 230 additions and 169 deletions

42
.zshrc
View File

@ -1,32 +1,18 @@
zmodload zsh/zprof
for S in \
"$ZDOTDIR/env.start.zsh" \
"$ZDOTDIR/env.zsh" \
"$ZDOTDIR/env.user.zsh" \
\
"$ZDOTDIR/history.zsh" \
"$ZDOTDIR/history.user.zsh" \
\
"$ZDOTDIR/options.zsh" \
"$ZDOTDIR/options.user.zsh" \
\
"$ZDOTDIR/plugins.zsh" \
"$ZDOTDIR/plugins.user.zsh" \
\
"$ZDOTDIR/agents.zsh" \
"$ZDOTDIR/agents.user.zsh" \
\
"$ZDOTDIR/prompt.zsh" \
"$ZDOTDIR/prompt.user.zsh" \
\
"$ZDOTDIR/aliases.zsh" \
"$ZDOTDIR/aliases.user.zsh" \
\
"$ZDOTDIR/compinit.zsh" \
"$ZDOTDIR/compinit.user.zsh" \
;
do [ -e "$S" ] && source "$S"
05-start \
15-env \
25-history \
35-options \
45-plugins \
55-agents \
65-prompt \
75-aliases \
78-scripts \
85-compinit \
95-finish
do
[ -e "$ZDOTDIR/$S.zsh" ] && source "$ZDOTDIR/$S.zsh"
[ -e "$ZDOTDIR/$S.user.zsh" ] && source "$ZDOTDIR/$S.user.zsh"
done
true

View File

@ -1,21 +1,32 @@
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CACHE_HOME=$HOME/.cache
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
declare -A ZINIT
ZINIT[HOME_DIR]=$XDG_CACHE_HOME/zsh/zinit
ZINIT[PLUGINS_DIR]=$XDG_CACHE_HOME/zsh/plugins
ZINIT[SNIPPETS_DIR]=$XDG_CACHE_HOME/zsh/snippets
ZINIT[ZCOMPDUMP_PATH]=$XDG_CACHE_HOME/zsh/zcompdump
export ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
export ZSH_COMPDUMP="$ZSH_CACHE_DIR/completions/dump"
export ZGEN_SOURCE="$ZSH_CACHE_DIR"
export ZGEN_SOURCE_BIN="$ZSH_CACHE_DIR/plugins"
export ZGEN_DIR="$ZSH_CACHE_DIR/zgenom"
ZPFX=$ZGEN_DIR/polaris
ZPFX=$XDG_CACHE_HOME/zsh/polaris
DISABLE_AUTO_UPDATE=true
# PATH
for P in \
"$HOME/.vim/plugged/vim-superman/bin" \
"$HOME/bin" \
"$HOME/.local/bin"
do
if [[ -d "${P}" ]]; then
export PATH="${P}:${PATH}"
fi
done
export PATH=$HOME/bin:$HOME/.local/bin:$PATH
# Удалить дубликаты в PATH
typeset -U PATH
export GNUPGHOME=$HOME/.config/gnupg
export SVDIR=$HOME/sv
export GNUPGHOME="$XDG_CONFIG_HOME/gnupg"
export SVDIR="$HOME/sv"
# Настройка uncrustify
UNCRUSTIFY_CONFIG="${XDG_CONFIG_HOME}/uncrustify/default.cfg"

View File

@ -1,9 +1,9 @@
HISTFILE="$HOME/.cache/zsh/history"
HISTFILE="$ZSH_CACHE_DIR/history"
HISTSIZE=10000000
SAVEHIST=10000000
HISTDUP=erase
[ ! -d "$HOME/.cache/zsh" ] && mkdir -p "$HOME/.cache/zsh"
[ ! -d "$ZSH_CACHE_DIR" ] && mkdir -p "$ZSH_CACHE_DIR"
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
@ -19,4 +19,3 @@ setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording en
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.

View File

@ -2,15 +2,22 @@
# apt-get install autojump
[[ -s /usr/share/autojump/autojump.sh ]] && source /usr/share/autojump/autojump.sh
setopt AUTO_PUSHD # Push the current directory visited on the stack.
setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack.
setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd.
autoload -Uz allopt zed zmv zcalc colors
colors
zmodload zsh/terminfo
autoload -Uz edit-command-line
zle -N edit-command-line
#bindkey -M vicmd v edit-command-line
bindkey -M vicmd v edit-command-line
autoload -Uz select-word-style
select-word-style shell
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic

66
45-plugins.zsh Normal file
View File

@ -0,0 +1,66 @@
# Менеджер плагинов zgenom
if [ ! -e "$ZGEN_DIR/zgenom.zsh" ]; then
git clone https://github.com/jandamm/zgenom "$ZGEN_DIR"
fi
source "$ZGEN_DIR/zgenom.zsh"
#
# Ohmyzsh
#
zgenom ohmyzsh
# Плагины
zgenom load willghatch/zsh-saneopt
zgenom load mafredri/zsh-async
zgenom load djui/alias-tips
zgenom load rupa/z
if [[ "$DISPLAY" != '' ]] && command -v xdotool > /dev/null 2>&1 && command -v wmctrl > /dev/null 2>&1; then
zgenom load marzocchi/zsh-notify
zstyle ':notify:*' expire-time 5000
zstyle ':notify:*' command-complete-timeout 20
zstyle ':notify:*' enable-on-ssh yes
fi
if command -v peco > /dev/null 2>&1; then
zgenom load jimeh/zsh-peco-history
fi
zgenom ohmyzsh plugins/command-not-found
zgenom ohmyzsh plugins/systemadmin
zgenom ohmyzsh plugins/common-aliases
zgenom ohmyzsh plugins/debian
if command -v fzf > /dev/null 2>&1; then
export DISABLE_FZF_KEY_BINDINGS=true
zgenom ohmyzsh plugins/fzf
# fzf
[ -e /usr/share/doc/fzf/examples/key-bindings.zsh ] && source /usr/share/doc/fzf/examples/key-bindings.zsh
[ -e /usr/share/doc/fzf/examples/completion.zsh ] && source /usr/share/doc/fzf/examples/completion.zsh
fi
if command -v git > /dev/null 2>&1; then
zgenom ohmyzsh plugins/git
zgenom ohmyzsh plugins/git-auto-fetch
zgenom ohmyzsh plugins/git-extras
zgenom ohmyzsh plugins/github
zgenom load paulirish/git-open
fi
if command -v psql > /dev/null 2>&1; then
zgenom ohmyzsh plugins/postgres
fi
if command -v sudo > /dev/null 2>&1; then
zgenom ohmyzsh plugins/sudo
fi
if command -v systemctl > /dev/null 2>&1; then
zgenom ohmyzsh plugins/systemd
fi
if command -v vim > /dev/null 2>&1; then
zgenom ohmyzsh plugins/vim-interaction
fi
zgenom ohmyzsh plugins/web-search
zgenom ohmyzsh plugins/tmux
zstyle ':prezto:module:tmux:auto-start' local 'no'
zstyle ':prezto:module:tmux:auto-start' remote 'yes'
zstyle ':prezto:module:tmux:session' name "$(hostname)"
zgenom load laggardkernel/zsh-tmux

View File

@ -6,13 +6,12 @@
# zstyle :omz:plugins:ssh-agent agent-forwarding on
# zstyle :omz:plugins:ssh-agent identities id_rsa
# zstyle :omz:plugins:ssh-agent lifetime 10h
# zinit snippet OMZP::ssh-agent
# zgenom ohmyzsh plugins/ssh-agent
##
# GPG agent
##
# zinit ice wait'1' lucid
# zinit light laggardkernel/zsh-gpg-agent
# zgenom ohmyzsh plugins/gpg-agent
##
# Keychain
@ -20,5 +19,5 @@
# zstyle :omz:plugins:keychain identities id_rsa 01234567
# zstyle :omz:plugins:keychain options --quiet --inherit local-once --noask --nocolor --quick
# zstyle :omz:plugins:keychain agents gpg,ssh
# zinit snippet OMZP::keychain
# zgenom ohmyzsh plugins/keychain

View File

@ -29,7 +29,7 @@ fi
autoload is-at-least
if is-at-least "5.2" "$ZSH_VERSION"; then
zinit load "denysdovhan/spaceship-prompt"
zgenom load "denysdovhan/spaceship-prompt"
else
zinit load "nojhan/liquidprompt"
zgenom load "nojhan/liquidprompt"
fi

View File

@ -22,14 +22,6 @@ aptf() {
apt-cache search $1 | grep $2
fi
}
aptl() {
[ -z $1 ] && return 1
sudo apt-get purge linux-modules-extra-"$1".* linux-modules-"$1".* linux-tools-"$1".* \
linux-image-"$1".* linux-image-unsigned-"$1".* linux-headers-"$1".*
}
# VIM
alias gvim='gvim --remote-silent'
# Youtube
YDL="$HOME/bin/youtube-dl"
@ -49,8 +41,6 @@ alias gur="git pull --recurse-submodules"
alias gsui="git submodule update --recursive --init"
alias gsur="git submodule update --recursive --init --remote"
# Фильтры
alias -g G="| grep"
alias -g L="| less"
# Фильтры (H,T,G,L определены в common-aliases)
alias -g NN='&>/dev/null'

57
78-scripts.zsh Normal file
View File

@ -0,0 +1,57 @@
ch() {
curl -s "https://cheat.sh/$1" | less
}
exf() {
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.tar.xz) tar xJf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.tar) tar xf "$1" ;;
*.zip) unzip "$1" ;;
*.7z) 7z x "$1" ;;
*.iso) 7z x "$1" ;;
*.rar) unrar x "$1" ;;
*) echo "'$1' cannot be extracted" ;;
esac
}
exfl() {
for F in "$@"
do
if [ -f "$F" ]; then
exf "$F"
else
echo "'$F' is not a valid file"
fi
done
}
exd() {
case "$1" in
*.tar.bz2) b=${1%.tar.bz2}; mkdir -p "$b">/dev/null; tar xjf "$1" -C "$b" ;;
*.tar.gz) b=${1%.tar.gz}; mkdir -p "$b">/dev/null; tar xzf "$1" -C "$b" ;;
*.tar.xz) b=${1%.tar.xz}; mkdir -p "$b">/dev/null; tar xJf "$1" -C "$b" ;;
*.tbz2) b=${1%.tbz2}; mkdir -p "$b">/dev/null; tar xjf "$1" -C "$b" ;;
*.tgz) b=${1%.tgz}; mkdir -p "$b">/dev/null; tar xzf "$1" -C "$b" ;;
*.tar) b=${1%.tar}; mkdir -p "$b">/dev/null; tar xf "$1" -C "$b" ;;
*.zip) b=${1%.zip}; unzip "$1" -d "$b" ;;
*.7z) b=${1%.7z}; 7z x -o"$b" "$1" ;;
*.iso) b=${1%.iso}; 7z x -o"$b" "$1" ;;
*.rar) b=${1%.rar}; rar x "$1" "$b" ;;
*) echo "'$1' cannot be extracted" ;;
esac
}
exdl() {
for F in "$@"
do
if [ -f "$F" ]; then
exd "$F"
else
echo "'$F' is not a valid file"
fi
done
}

42
85-compinit.zsh Normal file
View File

@ -0,0 +1,42 @@
typeset -i _compinit_updated_at=$(date +'%j' -r $ZSH_COMPDUMP 2>/dev/null || stat -f '%Sm' -t '%j' $ZSH_COMPDUMP 2>/dev/null)
ZGEN_COMPINIT_FLAGS="-i"
if [ $(date +'%j') = $_compinit_updated_at ]; then
ZGEN_COMPINIT_FLAGS+=" -C"
fi
unset _compinit_updated_at
zmodload -i zsh/complist
autoload -Uz compinit && eval "compinit $ZGEN_COMPINIT_FLAGS -d $ZSH_COMPDUMP"
#zgenom load marlonrichert/zsh-autocomplete
zgenom load zsh-users/zsh-autosuggestions
# Speed up autocomplete, force prefix mapping
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path $ZSH_CACHE_DIR/completion
zstyle ':completion:*:processes' command 'ps -ax'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*' force-list always
zstyle ':completion:*:*:kill:*' insert-ids single
zstyle ':completion:*:processes-names' command 'ps -e -o comm='
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
# SSH/SCP/RSYNC
zstyle ':completion:*:(ssh|scp|rsync):*' hosts off
zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*.*' loopback localhost
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^*.*' '*@*'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^<->.<->.<->.<->' '127.0.0.<->'
# Вызов в этом месте и в таком порядке
zgenom load zsh-users/zsh-syntax-highlighting
zgenom load zsh-users/zsh-history-substring-search

3
95-finish.zsh Normal file
View File

@ -0,0 +1,3 @@
#zgenom save 2>/dev/null
#zgenom compile $ZDOTDIR

View File

@ -9,7 +9,7 @@ sudo apt-get install zsh
Установка желательных пакетов:
```sh
sudo apt-get install keychain peco fzf wmctrl xdotool autojump git ssh-askpass
sudo apt-get install keychain peco fzf wmctrl xdotool autojump
```
Клонирование репозитория в каталог `~/.config/zsh`:
@ -30,7 +30,7 @@ sudo ${EDITOR:-mcedit} /etc/zsh/zshenv
и добавить строку
```sh
export ZDOTDIR=$HOME/.config/zsh
[[ -z "$ZDOTDIR" ]] && export ZDOTDIR=$HOME/.config/zsh
```
Установить интерпретатор Zsh по умолчанию для пользователя `username`.
@ -45,7 +45,7 @@ sudo usermod -s /usr/bin/zsh username
Для любого из вариантов следует скопировать шаблонный файл для настроек:
```sh
cp ~/.config/zsh/agents.zsh ~/.config/zsh/agents.user.zsh
cp ~/.config/zsh/55-agents.zsh ~/.config/zsh/55-agents.user.zsh
```
## Настройка GPG агента
@ -53,8 +53,7 @@ cp ~/.config/zsh/agents.zsh ~/.config/zsh/agents.user.zsh
Раскомментировать в файле ` ~/.config/zsh/agents.user.zsh` строки:
```text
# zinit ice wait'1' lucid
# zinit light laggardkernel/zsh-gpg-agent
# zgenom ohmyzsh plugins/gpg-agent
```
Пример файла настройки GPG агента `~/.config/gnupg/gpg-agent.conf`:
@ -81,7 +80,7 @@ pinentry-program /usr/bin/pinentry-qt
# zstyle :omz:plugins:ssh-agent agent-forwarding on
# zstyle :omz:plugins:ssh-agent identities id_rsa
# zstyle :omz:plugins:ssh-agent lifetime 10h
# zinit snippet OMZP::ssh-agent
# zgenom ohmyzsh plugins/ssh-agent
```
Добавить в конец файла `~/.ssh/config` правило для разрешения агенту сохранять ключи:
@ -105,7 +104,7 @@ Host *
# zstyle :omz:plugins:keychain identities id_rsa 01234567
# zstyle :omz:plugins:keychain options --quiet --inherit local-once --noask --nocolor --quick
# zstyle :omz:plugins:keychain agents gpg,ssh
# zinit snippet OMZP::keychain
# zgenom ohmyzsh plugins/keychain
```
Отредактировать файлы настроек для агента GPG и SSH, как это описано в разделах выше.
@ -114,7 +113,7 @@ Host *
## Инициализация
После редактирования файлов настройки запустить `zsh`, в результате чего будет
загружен менеджер пакетов `zinit` и необходимые плагины.
загружен менеджер пакетов `zgenom` и необходимые плагины.
## Обновление
@ -122,11 +121,11 @@ Host *
Обновление менеджера пакетов:
```sh
zinit self-update
zgenom selfupdate
````
Обновление плагинов:
```sh
zinit update --parallel
zgenom update
```

View File

@ -1,27 +0,0 @@
typeset -i _compinit_updated_at=$(date +'%j' -r $ZINIT[ZCOMPDUMP_PATH] 2>/dev/null || stat -f '%Sm' -t '%j' $ZINIT[ZCOMPDUMP_PATH] 2>/dev/null)
if [ $(date +'%j') != $_compinit_updated_at ]; then
ZINIT[COMPINIT_OPTS]="-i"
else
ZINIT[COMPINIT_OPTS]="-C -i"
fi
unset _compinit_updated_at
zinit wait lucid for \
atinit"zpcompinit; zpcdreplay" \
zdharma/fast-syntax-highlighting \
atload"!_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions \
blockf \
zsh-users/zsh-completions
zmodload -i zsh/complist
zstyle ':completion:*:processes' command 'ps -ax'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:processes-names' command 'ps -e -o comm='
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always

View File

@ -1,71 +0,0 @@
# Менеджер плагинов zinit
if [ ! -d $ZINIT[HOME_DIR] ]; then
git clone https://github.com/zdharma/zinit $ZINIT[HOME_DIR]
zcompile $ZINIT[HOME_DIR]/zinit.zsh
fi
source $ZINIT[HOME_DIR]/zinit.zsh
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Плагины
zinit load willghatch/zsh-saneopt
zinit load mafredri/zsh-async
zinit load zsh-users/zsh-history-substring-search
zinit load rupa/z
if [[ "$DISPLAY" != '' ]] && command -v xdotool > /dev/null 2>&1 && command -v wmctrl > /dev/null 2>&1; then
zinit load marzocchi/zsh-notify
zstyle ':notify:*' expire-time 5000
zstyle ':notify:*' command-complete-timeout 20
zstyle ':notify:*' enable-on-ssh yes
zstyle ':notify:*' always-check-active-window yes
fi
if command -v peco > /dev/null 2>&1; then
zinit load jimeh/zsh-peco-history
fi
zinit snippet OMZP::command-not-found
zinit snippet OMZP::common-aliases
zinit snippet OMZP::debian
if command -v fzf > /dev/null 2>&1; then
export DISABLE_FZF_KEY_BINDINGS=true
zinit snippet OMZP::fzf
# fzf
if [ -e /usr/share/doc/fzf/examples/key-bindings.zsh ]; then
. /usr/share/doc/fzf/examples/key-bindings.zsh
fi
if [ -e /usr/share/doc/fzf/examples/completion.zsh ]; then
. /usr/share/doc/fzf/examples/completion.zsh
fi
fi
if command -v git > /dev/null 2>&1; then
zinit snippet OMZP::git
zinit load paulirish/git-open
zinit lucid wait'2' for \
as"program" pick"$ZPFX/bin/git-*" \
src"etc/git-extras-completion.zsh" make"PREFIX=$ZPFX" tj/git-extras \
as"program" make"PREFIX=$ZPFX install" Fakerr/git-recall \
as"program" load davidosomething/git-my
fi
if command -v psql > /dev/null 2>&1; then
zinit snippet OMZP::postgres
fi
if command -v sudo > /dev/null 2>&1; then
zinit snippet OMZP::sudo
fi
if command -v systemctl > /dev/null 2>&1; then
zinit snippet OMZP::systemd
fi
if command -v vim > /dev/null 2>&1; then
zinit snippet OMZP::vim-interaction
fi
zinit snippet OMZP::web-search
zinit load djui/alias-tips
zstyle ':prezto:module:tmux:auto-start' local 'no'
zstyle ':prezto:module:tmux:auto-start' remote 'no'
zstyle ':prezto:module:tmux:session' name "$(hostname)"
zinit snippet PZTM::tmux