dotfiles/zsh/zshrc.org
Tom Willemse 67aa5e6021 [zsh] Get rid of a unicode character
This character was causing some issues in Kitty. The terminal would get confused
about the length of RPROMPT when it showed up.
2022-09-22 23:52:01 -07:00

4.6 KiB

ZSH

Autoload any ZSH function from $HOME/.zsh/functions.

  fpath=($HOME/.zsh/functions $fpath)
  autoload -U $HOME/.zsh/functions/*(:t)

Aliases

Use rlwrap on some less-than-pleasant REPLs that don't have GNU Readline-like features themselves.

  alias csi="rlwrap csi"
  alias scsh="rlwrap scsh"
  alias sbcl="rlwrap sbcl"

This alias is useful for when I'm trying something new with herbstluftwm.

  alias hc=herbstclient

Systemd supports user-level services, it's easy to manage them with this simple alias.

  alias myctl="systemctl --user"

By default scrot will take a screenshot in whatever the current working directory is, but I prefer having it all in the same location.

  alias scrot="/usr/bin/scrot -e 'mv \$f ~/pictures/screenshots/'"

Show colors and an indicator of what type each file is when using ls, like directory, pipe, link, etc.

  alias ls="ls --classify --color=always"

Always show color in pacman output.

  alias pacman="pacman --color=always"

History

Store ZSH history in a non-intrusive place.

  HISTFILE=$HOME/.zsh/histfile

Keep at most 1000 previous commands in memory.

  HISTSIZE=1000

Save at most 1000 previous commands to disk.

  SAVEHIST=1000

Allow multiple shell instances to share the same history.

  setopt SHARE_HISTORY

Don't remember duplicated commands.

  setopt HIST_IGNORE_ALL_DUPS

Plug-ins

Load zplug, a next generation zsh plugin manager.

  source /usr/share/zsh/scripts/zplug/init.zsh

Add zsh-syntax-highlighting.

  zplug "zsh-users/zsh-syntax-highlighting", defer:3

Add zsh-autosuggestions.

  zplug "zsh-users/zsh-autosuggestions"

Add bgnotify from oh-my-zsh to show when long-running commands finish.

  zplug "plugins/bgnotify", from:oh-my-zsh

Make sure all plugins are installed.

  if ! zplug check --verbose; then
      printf "Install? [y/N]: "
      if read -q; then
          echo; zplug install
      fi
  fi

Load all plugins.

  zplug load

X Interaction

Make some widgets for interacting with the clipboard.

  zle -N x-copy-region-as-kill
  zle -N x-kill-region
  zle -N x-yank

Bind them to keyboard shortcuts.

  bindkey -e '^[w' x-copy-region-as-kill
  bindkey -e '^W' x-kill-region
  bindkey -e '^Y' x-yank

Completion

Initialize completion. This triggers loading of zsh-syntax-highlighting as well.

  autoload -Uz compinit
  compinit

Less

I use a terminal that's always 80 columns wide. This means that a lot of output doesn't fit on a single line. I use the less command a lot to look at output that's too big and wide to view in my terminal. The default doesn't make this any better though, so I use these switches. Most of these I originally got from what git uses.

  export LESS="FXRSi"

This causes less to immediately quit if there is no need to use a pager (everything fits in a single screen) (-F). Doesn't clear the screen when less is closed (-X). Handles ANSI colors (-R). Stops long lines from wraping (-S). And makes searches case-insensitive (-i).

Prompt

First off, do some setup. Allow the use of functions inside the prompt, initialize colors and load the add-zsh-hook function.

  setopt PROMPT_SUBST

  autoload -U colors
  autoload -Uz add-zsh-hook
  autoload -Uz vcs_info

  colors

Setup VCS info.

  add-zsh-hook precmd vcs_info

  zstyle ':vcs_info:*' actionformats '%u%c%B%F{1}%a%f%%b %F{3}%s%f:%F{5}%r%f:%F{4}%b%f'
  zstyle ':vcs_info:*' enable bzr git hg svn
  zstyle ':vcs_info:*' formats '%u%c%F{3}%s%f:%F{5}%r%f:%F{4}%b%f'
  zstyle ':vcs_info:*' nvcsformats ''
  zstyle ':vcs_info:bzr:*' branchformat '%b'
  zstyle ':vcs_info:git:*' check-for-changes 1
  zstyle ':vcs_info:*' stagedstr '%F{2}*%f'
  zstyle ':vcs_info:*' unstagedstr '%F{1}*%f'

Set the actual prompts.

  PROMPT='%T $(spwd) %B%(?.%F{2}.%F{1}[%?])>%b%f '
  RPROMPT='${vcs_info_msg_0_}'