alias ls='ls --color=auto'
alias ll='ls -lh --group-directories-first'
alias la='ls -lAh --group-directories-first'
alias grep='grep --color=auto'
alias ip='ip -color=auto'
alias i='tawaki install'
alias up='tawaki update'

HISTSIZE=10000
HISTCONTROL=ignoreboth:erasedups
shopt -s histappend checkwinsize autocd 2>/dev/null

__fl_prompt() {
  local s=$? c='\[\e[38;2;142;197;255m\]'
  [[ $s -ne 0 ]] && c='\[\e[38;2;255;107;107m\]'
  local host=''
  [[ -n $SSH_CONNECTION ]] && host='\[\e[38;2;107;121;136m\]\u@\h '
  PS1="\n${host}\[\e[1;38;2;226;226;226m\]\w\[\e[0m\]\n${c}❯\[\e[0m\] "
}
PROMPT_COMMAND=(__fl_prompt "${PROMPT_COMMAND[@]}")

__fl_fetch() {
  [[ -z $FL_FETCHED && -z $SSH_CONNECTION && -z $TERM_PROGRAM ]] || return
  export FL_FETCHED=1
  command -v fastfetch >/dev/null || return
  grep -qs '"terminalFetch": *false' "${XDG_CONFIG_HOME:-$HOME/.config}/caelestia/shell.json" && return
  fastfetch
}
__fl_fetch

command_not_found_handle() {
  local pkgs
  if command -v pkgfile >/dev/null; then
    mapfile -t pkgs < <(pkgfile -b -- "$1" 2>/dev/null)
  fi
  if (( ${#pkgs[@]} )); then
    printf '%s is not installed. Get it with:\n' "$1" >&2
    local p
    for p in "${pkgs[@]}"; do printf '  tawaki install %s\n' "${p##*/}" >&2; done
  else
    printf 'bash: %s: command not found\n' "$1" >&2
  fi
  return 127
}
