diff options
| author | Ibrahim Muftee <ibrahim@muftee.net> | 2024-04-11 23:57:14 -0500 |
|---|---|---|
| committer | Ibrahim Muftee <ibrahim@muftee.net> | 2026-07-01 00:23:31 -0400 |
| commit | 15eda9cae989b28ca8547be00232cb09c77246b3 (patch) | |
| tree | d0e2ada115c53269f460a630dfb0fb34c5b09c59 /dot_zshrc.tmpl | |
| parent | 0de87e9ecffd71fd2af8c323a81d653cb31ccf4a (diff) | |
feat(zsh): add zsh configuration
Diffstat (limited to 'dot_zshrc.tmpl')
| -rw-r--r-- | dot_zshrc.tmpl | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl new file mode 100644 index 0000000..ab8fbb8 --- /dev/null +++ b/dot_zshrc.tmpl @@ -0,0 +1,109 @@ +# 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 " +setopt autocd # Automatically cd into typed directory. +stty stop undef # Disable ctrl-s to freeze terminal. +setopt interactive_comments + +# History in cache directory: +HISTSIZE=10000000 +SAVEHIST=10000000 + +# Add ~/.local/bin to $PATH +export PATH="$PATH:$HOME/.local/bin" + +# 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 () { + 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. + +# Use lf to switch directories and bind it to ctrl-o +lfcd () { + tmp="$(mktemp)" + lf -last-dir-path="$tmp" "$@" + if [ -f "$tmp" ]; then + dir="$(cat "$tmp")" + rm -f "$tmp" >/dev/null + [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" + fi +} +bindkey -s '^o' 'lfcd\n' + +bindkey -s '^a' 'bc -lq\n' + +bindkey -s '^f' 'cd "$(dirname "$(fzf)")"\n' + +bindkey '^[[P' delete-char + +# Edit line in vim with ctrl-e: +autoload edit-command-line; zle -N edit-command-line +bindkey '^e' edit-command-line + + +### ALIASES ### + + +# Use neovim for vim if present. +[ -x "$(command -v nvim)" ] && alias vim="nvim" vimdiff="nvim -d" + +# Verbosity and settings that you pretty much just always are going to want. +alias \ + cp="cp -iv" \ + mv="mv -iv" \ + rm="rm -vI" \ + bc="bc -ql" \ + mkd="mkdir -pv" \ + ffmpeg="ffmpeg -hide_banner" + +# Colorize commands when possible. +alias \ + ls="ls -hN --color=auto --group-directories-first" \ + grep="grep --color=auto" \ + diff="diff --color=auto" \ + ip="ip -color=auto" + +# These common commands are just too long! Abbreviate them. +alias \ + ka="killall" \ + g="git" \ + e="$EDITOR" \ + v="$EDITOR" \ + +# Changing "ls" to "exa" +alias ls='exa -al --color=always --group-directories-first' # my preferred listing +alias la='exa -a --color=always --group-directories-first' # all files and dirs +alias ll='exa -l --color=always --group-directories-first' # long format +alias lt='exa -aT --color=always --group-directories-first' # tree listing +alias l.='exa -a | egrep "^\."' + +# Load Starship +eval "$(starship init zsh)" |
