Skip to content

Commit

Permalink
refactor shell config for sharing common things like aliases between …
Browse files Browse the repository at this point in the history
…bash and zsh shells
  • Loading branch information
alex-bue committed Dec 4, 2024
1 parent 95ee73b commit 1e0befb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions home/dot_config/zsh/dot_inputrc

This file was deleted.

31 changes: 0 additions & 31 deletions home/dot_config/zsh/keybindings.zsh

This file was deleted.

3 changes: 0 additions & 3 deletions home/dot_zshenv
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
70 changes: 50 additions & 20 deletions home/dot_config/zsh/dot_zshrc → home/dot_zshrc
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand Down

0 comments on commit 1e0befb

Please sign in to comment.