From 1e0befb3abce3ddb8980da05cfb211a954f63c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20B=C3=BCscher?= Date: Wed, 4 Dec 2024 12:47:25 +0100 Subject: [PATCH] refactor shell config for sharing common things like aliases between bash and zsh shells --- .../{zsh/aliases.zsh => shell/aliases.sh} | 28 ++++---- home/dot_config/zsh/dot_inputrc | 3 - home/dot_config/zsh/keybindings.zsh | 31 -------- home/dot_zshenv | 3 - home/{dot_config/zsh => }/dot_zshrc | 70 +++++++++++++------ 5 files changed, 65 insertions(+), 70 deletions(-) rename home/dot_config/{zsh/aliases.zsh => shell/aliases.sh} (78%) delete mode 100644 home/dot_config/zsh/dot_inputrc delete mode 100644 home/dot_config/zsh/keybindings.zsh rename home/{dot_config/zsh => }/dot_zshrc (61%) diff --git a/home/dot_config/zsh/aliases.zsh b/home/dot_config/shell/aliases.sh similarity index 78% rename from home/dot_config/zsh/aliases.zsh rename to home/dot_config/shell/aliases.sh index cf01c9e..a5c9b48 100644 --- a/home/dot_config/zsh/aliases.zsh +++ b/home/dot_config/shell/aliases.sh @@ -10,21 +10,23 @@ alias rm="rm -iv" alias mkdir="mkdir -pv" alias bc="bc -ql" -# if command -v eza >/dev/null; then -# alias l="eza --icons" -# alias ls="eza --git --icons" -# alias la="eza --git -a --icons" -# alias ll="eza -lab --git --icons" -# alias tree="eza --tree --icons" -# else -# alias l="ls --color=auto" -# alias ls="ls --color=auto" -# alias la="ls -la" -# alias ll="ls -al" -# fi -# +if command -v eza >/dev/null; then + alias l="eza --icons" + alias ls="eza --git --icons" + alias la="eza --git -a --icons" + alias ll="eza -lab --git --icons" + alias tree="eza --tree --icons" +else + alias l="ls --color=auto" + alias ls="ls --color=auto" + alias la="ls -la" + alias ll="ls -al" +fi + # chezmoi alias d="chezmoi cd" +alias ca="chezmoi apply" +alias ce="chezmoi edit" # tmux alias ta="tmux attach" diff --git a/home/dot_config/zsh/dot_inputrc b/home/dot_config/zsh/dot_inputrc deleted file mode 100644 index 062813b..0000000 --- a/home/dot_config/zsh/dot_inputrc +++ /dev/null @@ -1,3 +0,0 @@ -set show-mode-in-prompt on -set vi-cmd-mode-string "\1\e[2 q\2" -set vi-ins-mode-string "\1\e[6 q\2" diff --git a/home/dot_config/zsh/keybindings.zsh b/home/dot_config/zsh/keybindings.zsh deleted file mode 100644 index 172f103..0000000 --- a/home/dot_config/zsh/keybindings.zsh +++ /dev/null @@ -1,31 +0,0 @@ -# VIM MODE SETTINGS -# 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 () { - case $KEYMAP in - vicmd) echo -ne '\e[1 q';; # block - viins|main) echo -ne '\e[5 q';; # beam - esac -} -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. - -# Edit Command Line in VIM -autoload edit-command-line; zle -N edit-command-line -bindkey '^e' edit-command-line diff --git a/home/dot_zshenv b/home/dot_zshenv index 7afede1..3fa39b8 100644 --- a/home/dot_zshenv +++ b/home/dot_zshenv @@ -1,8 +1,5 @@ #!/bin/zsh -# Set zsh config location -export ZDOTDIR=$HOME/.config/zsh - # set xdg paths export XDG_CACHE_HOME="$HOME/.cache" export XDG_CONFIG_HOME="$HOME/.config" diff --git a/home/dot_config/zsh/dot_zshrc b/home/dot_zshrc similarity index 61% rename from home/dot_config/zsh/dot_zshrc rename to home/dot_zshrc index a33bf6a..b6e2c79 100644 --- a/home/dot_config/zsh/dot_zshrc +++ b/home/dot_zshrc @@ -1,14 +1,8 @@ # Enable colors and change prompt: autoload -U colors && colors # Load colors -# install plugin manager (zinit) -ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" -[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)" -[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" -source "${ZINIT_HOME}/zinit.zsh" - -# opts -HISTFILE="$ZDOTDIR/.zsh_history" +# Enable history +HISTFILE="~/.zsh_history" HISTSIZE=5000 # Maximum events for internal history SAVEHIST=5000 # Maximum events in history file @@ -22,31 +16,67 @@ setopt hist_find_no_dups # Do not display a previously found event. setopt hist_save_no_dups # Do not write a duplicate event to the history file. setopt hist_verify # Do not execute immediately upon history expansion. -# completions -autoload -Uz compinit && compinit - -zinit cdreplay -q - +# Configure completions zstyle ':completion:*' menu no # Disable zsh complete menus (because plugin handles them) zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' # Case insensitive completion zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" # Color the completions +# _comp_options+=(globdots) # Complete hidden(dot)files + +# Configure fzf-tab completions zstyle ':fzf-tab:*' fzf-bindings 'tab:accept' # Use tab as enter instead of going down the list zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath' # Use fzf tab for cd completions -#TODO: Do I need these? -# zmodload zsh/complist -# compinit -C -# _comp_options+=(globdots) # Complete hidden(dot)files +# Initialize completion system +autoload -Uz compinit && compinit + +# enable and configure vi mode +bindkey -v +export KEYTIMEOUT=1 + +bindkey '^H' backward-delete-char # For ^H to work globally +bindkey '^?' backward-delete-char # For ^? to work globally + +# Use vim keys in tab complete menu (currently not needed because fzf is used) +# 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 + +# Change cursor shape for different vi modes. +function zle-keymap-select () { + case $KEYMAP in + vicmd) echo -ne '\e[1 q';; # block + viins|main) echo -ne '\e[5 q';; # beam + esac +} +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. + +# Allow editing cli in nvim +autoload edit-command-line; zle -N edit-command-line +bindkey '^e' edit-command-line # CTRL-E to edit cli prompt in NVIM # load modules -[ -f "$ZDOTDIR/aliases.zsh" ] && source "$ZDOTDIR/aliases.zsh" -[ -f "$ZDOTDIR/keybindings.zsh" ] && source "$ZDOTDIR/keybindings.zsh" +source "$HOME/.config/shell/aliases.sh" + +# Install plugin manager (zinit) +ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" +[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)" +[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" +source "${ZINIT_HOME}/zinit.zsh" # add zsh plugins zinit light Aloxaf/fzf-tab -zinit light zsh-users/zsh-syntax-highlighting zinit light zsh-users/zsh-completions +zinit light zsh-users/zsh-syntax-highlighting zinit light zsh-users/zsh-autosuggestions +zinit cdreplay -q # apparently speeds completions loading up # editor and prompt config export NVIM_APPNAME="lazyvim"