From f70d5dc9b1f546bcfae67f067fe2e3b67f94ca45 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 3 Nov 2021 19:59:44 +0100 Subject: improving dotfiles --- zsh/dot-zimrc | 43 +++++++++++ zsh/dot-zshrc | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ zsh/zimrc | 43 ----------- zsh/zshrc | 222 --------------------------------------------------------- 4 files changed, 268 insertions(+), 265 deletions(-) create mode 100644 zsh/dot-zimrc create mode 100644 zsh/dot-zshrc delete mode 100644 zsh/zimrc delete mode 100644 zsh/zshrc (limited to 'zsh') diff --git a/zsh/dot-zimrc b/zsh/dot-zimrc new file mode 100644 index 0000000..2a2bb68 --- /dev/null +++ b/zsh/dot-zimrc @@ -0,0 +1,43 @@ +# Start configuration added by Zim install {{{ +# ------- +# Modules +# ------- + +# Sets sane Zsh built-in environment options. +zmodule environment +# Provides handy git aliases and functions. +zmodule git +# Applies correct bindkeys for input events. +zmodule input +# Sets a custom terminal title. +zmodule termtitle +# Utility aliases and functions. Adds colour to ls, grep and less. +zmodule utility + +# +# Prompt +# +# Exposes to prompts how long the last command took to execute, used by asciiship. +zmodule duration-info +# Exposes git repository status information to prompts, used by asciiship. +zmodule git-info +# A heavily reduced, ASCII-only version of the Spaceship and Starship prompts. +# zmodule asciiship + +# Additional completion definitions for Zsh. +zmodule zsh-users/zsh-completions +# Enables and configures smart and extensive tab completion. +# completion must be sourced after zsh-users/zsh-completions +zmodule completion +# Fish-like autosuggestions for Zsh. +zmodule zsh-users/zsh-autosuggestions +# Fish-like syntax highlighting for Zsh. +# zsh-users/zsh-syntax-highlighting must be sourced after completion +zmodule zsh-users/zsh-syntax-highlighting +# Fish-like history search (up arrow) for Zsh. +# zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting +zmodule zsh-users/zsh-history-substring-search +# }}} End configuration added by Zim install + +zmodule exa +zmodule fzf diff --git a/zsh/dot-zshrc b/zsh/dot-zshrc new file mode 100644 index 0000000..d116b4a --- /dev/null +++ b/zsh/dot-zshrc @@ -0,0 +1,225 @@ +if [ -z "$TMUX" ] +then + tmux -2 attach -t TMUX || tmux -2 new -s TMUX +fi + +# Start configuration added by Zim install {{{ +# +# User configuration sourced by interactive shells +# + +# ----------------- +# Zsh configuration +# ----------------- + +# +# History +# + +# Remove older command from the history if a duplicate is to be added. +setopt HIST_IGNORE_ALL_DUPS + +# +# Input/output +# + +# Set editor default keymap to emacs (`-e`) or vi (`-v`) +bindkey -v + +# Prompt for spelling correction of commands. +#setopt CORRECT + +# Customize spelling correction prompt. +#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' + +# Remove path separator from WORDCHARS. +WORDCHARS=${WORDCHARS//[\/]} + + +# -------------------- +# Module configuration +# -------------------- + +# +# completion +# + +# Set a custom path for the completion dump file. +# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used. +#zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}" + +# +# git +# + +# Set a custom prefix for the generated aliases. The default prefix is 'G'. +#zstyle ':zim:git' aliases-prefix 'g' + +# +# input +# + +# Append `../` to your input for each `.` you type after an initial `..` +#zstyle ':zim:input' double-dot-expand yes + +# +# termtitle +# + +# Set a custom terminal title format using prompt expansion escape sequences. +# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes +# If none is provided, the default '%n@%m: %~' is used. +#zstyle ':zim:termtitle' format '%1~' + +# +# zsh-autosuggestions +# + +# Customize the style that the suggestions are shown with. +# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style +#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242' + +# +# zsh-syntax-highlighting +# + +# Set what highlighters will be used. +# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) + +# Customize the main highlighter styles. +# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it +#typeset -A ZSH_HIGHLIGHT_STYLES +#ZSH_HIGHLIGHT_STYLES[comment]='fg=242' + +# ------------------ +# Initialize modules +# ------------------ + +if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then + # Update static initialization script if it does not exist or it's outdated, before sourcing it + source ${ZIM_HOME}/zimfw.zsh init -q +fi +source ${ZIM_HOME}/init.zsh + +# ------------------------------ +# Post-init module configuration +# ------------------------------ + +# +# zsh-history-substring-search +# + +# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init +bindkey '^[[A' history-substring-search-up +bindkey '^[[B' history-substring-search-down + +# Bind up and down keys +zmodload -F zsh/terminfo +p:terminfo +if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then + bindkey ${terminfo[kcuu1]} history-substring-search-up + bindkey ${terminfo[kcud1]} history-substring-search-down +fi + +bindkey '^P' history-substring-search-up +bindkey '^N' history-substring-search-down +bindkey -M vicmd 'k' history-substring-search-up +bindkey -M vicmd 'j' history-substring-search-down +# }}} End configuration added by Zim install + +ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#aaaaff,underline" +alias bell='echo "\a"' + +export EDITOR=nvim +[ -f "$HOME/nvim.appimage" ] && export EDITOR=$HOME/nvim.appimage +alias vi=$EDITOR + +bindkey -M viins 'jk' vi-cmd-mode + +autoload -U colors +colors + +setopt nopromptbang prompt{cr,percent,sp,subst} + +zstyle ':zim:duration-info' threshold 0.1 +zstyle ':zim:duration-info' format '%d' + +autoload -Uz add-zsh-hook +add-zsh-hook preexec duration-info-preexec +add-zsh-hook precmd duration-info-precmd + +PRMPT_COL=#556677 + +_prompt_miguel_vimode() { + case ${KEYMAP} in + vicmd) print -n "%F{red}%h%f%K{$PRMPT_COL}%F{black}%f%K{$PRMPT_COL}" ;; + *) print -n "%F{$PRMPT_COL}%h%f%K{$PRMPT_COL}%F{black}%f%K{$PRMPT_COL}" ;; + esac +} +_prompt_miguel_keymap_select() { + zle reset-prompt + zle -R +} + +autoload -Uz add-zle-hook-widget +add-zle-hook-widget -Uz keymap-select _prompt_miguel_keymap_select + +typeset -gA git_info +if (( ${+functions[git-info]} )); then + zstyle ':zim:git-info:branch' format '%F{blue}%b%f' + zstyle ':zim:git-info:commit' format 'HEAD %F{green}(%c)' + zstyle ':zim:git-info:action' format ' %F{yellow}(${(U):-%s})' + zstyle ':zim:git-info:stashed' format '\\\$' + zstyle ':zim:git-info:unindexed' format '!' + zstyle ':zim:git-info:indexed' format '+' + zstyle ':zim:git-info:untracked' format '?' + zstyle ':zim:git-info:ahead' format '%A>' + zstyle ':zim:git-info:behind' format '%B<' +# zstyle ':zim:git-info' ignore-submodules 'none' + zstyle ':zim:git-info' verbose yes + zstyle ':zim:git-info:keys' format \ + 'status' '%u%S%I%i%A%B' \ + 'prompt' '%F{white}%b%c%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f +' + add-zsh-hook precmd git-info +fi + +function _miguel_check_last_exit_code() { + local LAST_EXIT_CODE=$? + if [[ $LAST_EXIT_CODE -ne 0 ]]; then + echo "%F{red}- $LAST_EXIT_CODE -%f" + else + echo "%F{$PRMPT_COL}%n@%m%f" + fi +} + +function _miguel_shllvl() { + local LVL='' + if [[ $SHLVL -gt 2 ]]; then + for i in {3..$SHLVL} + do + if [ $(( $i % 2 )) -eq $(($SHLVL % 2)) ]; then + LVL+="%F{$PRMPT_COL}%K{black}%k%f" + else + LVL+="%F{black}%K{$PRMPT_COL}%k%f" + fi + done + echo $LVL + fi +} + +add-zsh-hook precmd git-info + +PS1='${(e)git_info[prompt]}$(_miguel_shllvl)$(_prompt_miguel_vimode) %~%f%k%F{$PRMPT_COL}%f ' +RPS1='%(1j.%K{$PRMPT_COL}%B %j %b%k.) $duration_info $(_miguel_check_last_exit_code)' + +export PATH=$HOME/.local/bin:$PATH + +[ -f "$HOME/.zshrc.local" ] && source "$HOME/.zshrc.local" +[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env" +[ -f "$HOME/.ghcup/env" ] && source "$HOME/.ghcup/env" +[ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ] && source "$HOME/.nix-profile/etc/profile.d/nix.sh" + +eval "$(direnv hook zsh)" + +cd $HOME diff --git a/zsh/zimrc b/zsh/zimrc deleted file mode 100644 index 2a2bb68..0000000 --- a/zsh/zimrc +++ /dev/null @@ -1,43 +0,0 @@ -# Start configuration added by Zim install {{{ -# ------- -# Modules -# ------- - -# Sets sane Zsh built-in environment options. -zmodule environment -# Provides handy git aliases and functions. -zmodule git -# Applies correct bindkeys for input events. -zmodule input -# Sets a custom terminal title. -zmodule termtitle -# Utility aliases and functions. Adds colour to ls, grep and less. -zmodule utility - -# -# Prompt -# -# Exposes to prompts how long the last command took to execute, used by asciiship. -zmodule duration-info -# Exposes git repository status information to prompts, used by asciiship. -zmodule git-info -# A heavily reduced, ASCII-only version of the Spaceship and Starship prompts. -# zmodule asciiship - -# Additional completion definitions for Zsh. -zmodule zsh-users/zsh-completions -# Enables and configures smart and extensive tab completion. -# completion must be sourced after zsh-users/zsh-completions -zmodule completion -# Fish-like autosuggestions for Zsh. -zmodule zsh-users/zsh-autosuggestions -# Fish-like syntax highlighting for Zsh. -# zsh-users/zsh-syntax-highlighting must be sourced after completion -zmodule zsh-users/zsh-syntax-highlighting -# Fish-like history search (up arrow) for Zsh. -# zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting -zmodule zsh-users/zsh-history-substring-search -# }}} End configuration added by Zim install - -zmodule exa -zmodule fzf diff --git a/zsh/zshrc b/zsh/zshrc deleted file mode 100644 index a28e0e6..0000000 --- a/zsh/zshrc +++ /dev/null @@ -1,222 +0,0 @@ -if [ -z "$TMUX" ] -then - tmux -2 attach -t TMUX || tmux -2 new -s TMUX -fi - -# Start configuration added by Zim install {{{ -# -# User configuration sourced by interactive shells -# - -# ----------------- -# Zsh configuration -# ----------------- - -# -# History -# - -# Remove older command from the history if a duplicate is to be added. -setopt HIST_IGNORE_ALL_DUPS - -# -# Input/output -# - -# Set editor default keymap to emacs (`-e`) or vi (`-v`) -bindkey -v - -# Prompt for spelling correction of commands. -#setopt CORRECT - -# Customize spelling correction prompt. -#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' - -# Remove path separator from WORDCHARS. -WORDCHARS=${WORDCHARS//[\/]} - - -# -------------------- -# Module configuration -# -------------------- - -# -# completion -# - -# Set a custom path for the completion dump file. -# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used. -#zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}" - -# -# git -# - -# Set a custom prefix for the generated aliases. The default prefix is 'G'. -#zstyle ':zim:git' aliases-prefix 'g' - -# -# input -# - -# Append `../` to your input for each `.` you type after an initial `..` -#zstyle ':zim:input' double-dot-expand yes - -# -# termtitle -# - -# Set a custom terminal title format using prompt expansion escape sequences. -# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes -# If none is provided, the default '%n@%m: %~' is used. -#zstyle ':zim:termtitle' format '%1~' - -# -# zsh-autosuggestions -# - -# Customize the style that the suggestions are shown with. -# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style -#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242' - -# -# zsh-syntax-highlighting -# - -# Set what highlighters will be used. -# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md -ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) - -# Customize the main highlighter styles. -# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it -#typeset -A ZSH_HIGHLIGHT_STYLES -#ZSH_HIGHLIGHT_STYLES[comment]='fg=242' - -# ------------------ -# Initialize modules -# ------------------ - -if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then - # Update static initialization script if it does not exist or it's outdated, before sourcing it - source ${ZIM_HOME}/zimfw.zsh init -q -fi -source ${ZIM_HOME}/init.zsh - -# ------------------------------ -# Post-init module configuration -# ------------------------------ - -# -# zsh-history-substring-search -# - -# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init -bindkey '^[[A' history-substring-search-up -bindkey '^[[B' history-substring-search-down - -# Bind up and down keys -zmodload -F zsh/terminfo +p:terminfo -if [[ -n ${terminfo[kcuu1]} && -n ${terminfo[kcud1]} ]]; then - bindkey ${terminfo[kcuu1]} history-substring-search-up - bindkey ${terminfo[kcud1]} history-substring-search-down -fi - -bindkey '^P' history-substring-search-up -bindkey '^N' history-substring-search-down -bindkey -M vicmd 'k' history-substring-search-up -bindkey -M vicmd 'j' history-substring-search-down -# }}} End configuration added by Zim install - -ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#aaaaff,underline" -alias bell='echo "\a"' - -export EDITOR=nvim -[ -f "$HOME/nvim.appimage" ] && export EDITOR=$HOME/nvim.appimage -alias vi=$EDITOR - -bindkey -M viins 'jk' vi-cmd-mode - -autoload -U colors -colors - -setopt nopromptbang prompt{cr,percent,sp,subst} - -zstyle ':zim:duration-info' threshold 0.1 -zstyle ':zim:duration-info' format '%d' - -autoload -Uz add-zsh-hook -add-zsh-hook preexec duration-info-preexec -add-zsh-hook precmd duration-info-precmd - -PRMPT_COL=#556677 - -_prompt_miguel_vimode() { - case ${KEYMAP} in - vicmd) print -n "%F{red}%h%f%K{$PRMPT_COL}%F{black}%f%K{$PRMPT_COL}" ;; - *) print -n "%F{$PRMPT_COL}%h%f%K{$PRMPT_COL}%F{black}%f%K{$PRMPT_COL}" ;; - esac -} -_prompt_miguel_keymap_select() { - zle reset-prompt - zle -R -} - -autoload -Uz add-zle-hook-widget -add-zle-hook-widget -Uz keymap-select _prompt_miguel_keymap_select - -typeset -gA git_info -if (( ${+functions[git-info]} )); then - zstyle ':zim:git-info:branch' format '%F{blue}%b%f' - zstyle ':zim:git-info:commit' format 'HEAD %F{green}(%c)' - zstyle ':zim:git-info:action' format ' %F{yellow}(${(U):-%s})' - zstyle ':zim:git-info:stashed' format '\\\$' - zstyle ':zim:git-info:unindexed' format '!' - zstyle ':zim:git-info:indexed' format '+' - zstyle ':zim:git-info:untracked' format '?' - zstyle ':zim:git-info:ahead' format '%A>' - zstyle ':zim:git-info:behind' format '%B<' -# zstyle ':zim:git-info' ignore-submodules 'none' - zstyle ':zim:git-info' verbose yes - zstyle ':zim:git-info:keys' format \ - 'status' '%u%S%I%i%A%B' \ - 'prompt' '%F{white}%b%c%s${(e)git_info[status]:+" %F{red}[${(e)git_info[status]}]"}%f -' - add-zsh-hook precmd git-info -fi - -function _miguel_check_last_exit_code() { - local LAST_EXIT_CODE=$? - if [[ $LAST_EXIT_CODE -ne 0 ]]; then - echo "%F{red}- $LAST_EXIT_CODE -%f" - else - echo "%F{$PRMPT_COL}%n@%m%f" - fi -} - -function _miguel_shllvl() { - local LVL='' - if [[ $SHLVL -gt 2 ]]; then - for i in {3..$SHLVL} - do - if [ $(( $i % 2 )) -eq $(($SHLVL % 2)) ]; then - LVL+="%F{$PRMPT_COL}%K{black}%k%f" - else - LVL+="%F{black}%K{$PRMPT_COL}%k%f" - fi - done - echo $LVL - fi -} - -add-zsh-hook precmd git-info - -PS1='${(e)git_info[prompt]}$(_miguel_shllvl)$(_prompt_miguel_vimode) %~%f%k%F{$PRMPT_COL}%f ' -RPS1='%(1j.%K{$PRMPT_COL}%B %j %b%k.) $duration_info $(_miguel_check_last_exit_code)' - -export PATH=$HOME/.local/bin:$PATH - -[ -f "$HOME/.zshrc.local" ] && source "$HOME/.zshrc.local" -[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env" -[ -f "$HOME/.ghcup/env" ] && source "$HOME/.ghcup/env" - -cd $HOME -- cgit v1.2.3