From: ma Date: Mon, 29 Mar 2021 16:52:34 +0000 (+0200) Subject: Add zsh config X-Git-Url: https://git.beaudet.xyz/?a=commitdiff_plain;h=58348e8bea7f1c0598a74d253e17bb2f6cd46897;p=dot.git Add zsh config --- diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile new file mode 100644 index 0000000..989d2e9 --- /dev/null +++ b/.config/zsh/.zprofile @@ -0,0 +1,19 @@ +#!/bin/zsh + +export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) +gpgconf --launch gpg-agent + +[ ! -f ${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc ] && shortcuts >/dev/null 2>&1 & + +if pacman -Qs libxft-bgra >/dev/null 2>&1; then + # Start graphical server on user's current tty if not already running. + [ "$(tty)" = "/dev/tty1" ] && ! pidof -s Xorg >/dev/null 2>&1 && exec startx +else + echo "\033[31mIMPORTANT\033[0m: Note that \033[32m\`libxft-bgra\`\033[0m must be installed for this build of dwm. +Please run: + \033[32myay -S libxft-bgra-git\033[0m +and replace \`libxft\`. Afterwards, you may start the graphical server by running \`startx\`." +fi + +# Switch escape and caps if tty and no passwd required: +# sudo -n loadkeys ${XDG_DATA_HOME:-$HOME/.local/share}/larbs/ttymaps.kmap 2>/dev/null diff --git a/.config/zsh/.zshenv b/.config/zsh/.zshenv new file mode 100644 index 0000000..7d46e44 --- /dev/null +++ b/.config/zsh/.zshenv @@ -0,0 +1,67 @@ +#!/bin/zsh + +# Here we set env variables +export XDG_CONFIG_HOME="$HOME"/.config +export XDG_DATA_HOME="$HOME"/.local/share +export XDG_CACHE_HOME="$HOME"/.cache + +# Default programs +export EDITOR="vim" +export VISUAL="vim" +export TERMINAL="st" +export BROWSER="qutebrowser" +export READER="zathura" + +# Zsh related +ZDOTDIR="$XDG_CONFIG_HOME"/zsh +HISTFILE="$XDG_CACHE_HOME"/zshhistory +HISTSIZE=10000 +SAVEHIST=10000 + +# Go related +export GOPATH="$XDG_DATA_HOME"/go + +# NPM +export NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/npm/npmrc" + +# Node related +export NODE_REPL_HISTORY="XDG_DATA_HOME"/node_repl_history + +# Rust related +export CARGO_HOME="$XDG_DATA_HOME"/cargo +export RUSTUP_HOME="$XDG_DATA_HOME"/rustup + +# PostgreSQL +export PSQLRC="$XDG_CONFIG_HOME"/pg/psqlrc +export PSQL_HISTORY="$XDG_CACHE_HOME"/pg/psql_history +export PGPASSFILE="$XDG_CONFIG_HOME"/pg/pgpass +export PGSERVICEFILE="XDG_CONFIG_HOME"/pg/pg_service.conf + +# Other programs +export DOCKER_CONFIG="$XDG_CONFIG_HOME"/docker +export LESSHISTFILE=- +export WGETRC="$XDG_CONFIG_HOME"/wgetrc +export MBSYNCRC="${XDG_CONFIG_HOME:-$HOME/.config}/mbsync/config" +export PASSWORD_STORE_DIR="$XDG_DATA_HOME"/pass +export ELECTRUMDIR="${XDG_DATA_HOME:-$HOME/.local/share}/electrum" +export SUDO_ASKPASS="$HOME/.local/bin/dmenupass" +export GTK2_RC_FILES="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-2.0/gtkrc-2.0" +export ANDROID_SDK_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/android" +export WINEPREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/wineprefixes/default" +export KODI_DATA="${XDG_DATA_HOME:-$HOME/.local/share}/kodi" +export NUGET_PACKAGES="${XDG_CACHE_HOME:-$HOME/.cache}/NuGetPackages" +export NOTMUCH_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/notmuch/notmuchrc" +export NMBGIT="${XDG_DATA_HOME:-$HOME/.local/share}/notmuch/nmbug" +export PYLINTHOME="${XDG_CACHE_HOME:-$HOME/.cache}/pylint" +export XAUTHORITY="${XDG_RUNTIME_DIR:-/run/user/$USER}/Xauthority" + +# export GNUPGHOME="${XDG_DATA_HOME:-$HOME/.local/share}/gnupg" + +# # PATH +typeset -U PATH path +PATH="$PATH:$HOME/.local/bin" +PATH="$PATH:$CARGO_HOME/bin" +PATH="$PATH:$XDG_DATA_HOME/npm/bin" +PATH="$PATH:$(du "$HOME/.local/bin" | cut -f2 | paste -sd ':' -)" + +export PATH diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc new file mode 100644 index 0000000..20d164e --- /dev/null +++ b/.config/zsh/.zshrc @@ -0,0 +1,104 @@ +# Source alias +. $XDG_CONFIG_HOME/shell/aliasrc + +# Enable colors and change prompt: +autoload -U colors && colors # Load colors +PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b " + +stty stop undef # Disable ctrl-s to freeze terminal. + +# On demand rehash +# https://wiki.archlinux.org/index.php/zsh#On-demand_rehash +zshcache_time="$(date +%s%N)" +autoload -Uz add-zsh-hook + +rehash_precmd() { + if [[ -a /var/cache/zsh/pacman ]]; then + local paccache_time="$(date -r /var/cache/zsh/pacman +%s%N)" + if (( zshcache_time < paccache_time )); then + rehash + zshcache_time="$paccache_time" + fi + fi +} + +add-zsh-hook -Uz precmd rehash_precmd + +# https://wiki.archlinux.org/index.php/zsh#Shortcut_to_exit_shell_on_partial_command_line +exit_zsh() { exit } +zle -N exit_zsh +bindkey '^D' exit_zsh + + +# Basic auto/tab complete: +autoload -U compinit +zstyle ':completion:*' menu select +zmodload zsh/complist +compinit +_comp_options+=(globdots) # Include hidden files. + +# vi mode +bindkey -v +export KEYTIMEOUT=1 + +# Use vim keys in tab complete menu: +bindkey -M menuselect 'h' vi-backward-char +bindkey -M menuselect 'k' vi-up-line-or-history +bindkey -M menuselect 'l' vi-forward-char +bindkey -M menuselect 'j' vi-down-line-or-history +bindkey -v '^?' backward-delete-char + +# Change cursor shape for different vi modes. +function zle-keymap-select { + if [[ ${KEYMAP} == vicmd ]] || + [[ $1 = 'block' ]]; then + echo -ne '\e[1 q' + elif [[ ${KEYMAP} == main ]] || + [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || + [[ $1 = 'beam' ]]; then + echo -ne '\e[5 q' + fi +} +zle -N zle-keymap-select +zle-line-init() { + zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) + echo -ne "\e[5 q" +} +zle -N zle-line-init +echo -ne '\e[5 q' # Use beam shape cursor on startup. +preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt. + + +# Git prompt +autoload -Uz vcs_info +precmd_vcs_info() { vcs_info } +precmd_functions+=( precmd_vcs_info ) +setopt prompt_subst +RPROMPT=\$vcs_info_msg_0_ +zstyle ':vcs_info:git:*' formats '%F{240}(%b)%r%f' +zstyle ':vcs_info:*' enable git + +# # Start of lines added by zsh init +# zstyle :compinstall filename '/home/ma/.config/zsh/.zshrc' +# +# autoload -Uz compinit +# compinit +# # End of lines added by compinstall + + +# https://github.com/softmoth/zsh-vim-mode +# . $ZDOTDIR/plugins/zsh-vim-mode.plugin.zsh + + +# GnuPG related +GPG_TTY=$(tty) +export GPG_TTY +gpg-connect-agent updatestartuptty /bye >/dev/null +export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) +gpgconf --launch gpg-agent + +# Should be last +. /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh + +# eval "$(starship init zsh)"