#!/bin/zsh

# emacs-style keybindings
bindkey -e

# Aliases
alias grep='rg'
alias ls='eza'
alias sl='eza'
alias ll='eza -alF'
alias la='eza -a'
alias l='eza'
alias lal='eza -al'
alias cat='bat'
alias ip='ip --color=auto'

# history stuff
HISTSIZE=10000
SAVEHIST=10000
HISTFILE="$XDG_CACHE_HOME/zsh/history"
setopt HIST_IGNORE_DUPS
setopt HIST_REDUCE_BLANKS
setopt HIST_FIND_NO_DUPS

function fzf-history-widget() {
  local selected_command=$(history -rn 1 | fzf --preview 'echo {}' --preview-window=down:3:wrap)
  if [[ -n $selected_command ]]; then
    LBUFFER="$selected_command"
  fi
  zle reset-prompt
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget

# Enable command completion
autoload -Uz compinit && compinit

# completion stuff
zstyle ':completion:*' menu select
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'

# plugins
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

# zoxide
eval "$(zoxide init zsh)"

# prompt
eval "$(starship init zsh)"

[ -f "/home/wball/.local/share/ghcup/env" ] && . "/home/wball/.local/share/ghcup/env" # ghcup-env
