# fish config

## Paths
set -xU GOPATH $HOME/.go
set -xU DOTFILES $HOME/.dotfiles
set SITE $HOME/Devel/kirby

set KEYFILE $HOME/.ssh/id_ed25519

fish_add_path $HOME/.local/bin $HOME/.mix $HOME/.mix/escripts $HOME/.cargo/bin $GOPATH/bin $HOME/.config/emacs/bin

## Environment setup
set -xU TERMINAL 'foot'
set -xU TERM 'xterm'
set -xU EDITOR 'helix'

## Functions

function backup --argument filename
    cp $filename $filename.bak
end

## Useful aliases

alias r='source ~/.config/fish/config.fish && echo "Config reloaded."'
alias c="clear"
alias dot="$EDITOR $DOTFILES"
alias site="$EDITOR $SITE"

# Add apt aliases for updating / upgrading if available
if type -q (which apt &> /dev/null)
    alias up="sudo apt update && sudo apt list --upgradable"
    alias ug="sudo apt upgrade"
    alias install="sudo apt install"
end

# Replace ls with lsd if available
if type -q (which lsd &> /dev/null)
    alias ls="lsd"
    alias la="lsd -a"
    alias ll="lsd -l"
end

# Initialize zoxide
zoxide init fish | source

# Docker Compose
alias dcu="docker compose up -d --build"
alias dcd="docker compose down --remove-orphans"
alias dcr="dcd && dcu"

# Elixir / phoenix aliases
alias phx="iex -S mix phx.server"
alias kirb="php -S localhost:4000 kirby/router.php"

# Systemd alias
alias start="sudo systemctl start"
alias restart="sudo systemctl restart"
alias stop="sudo systemctl stop"
alias enable="sudo systemctl enable"
alias disable="sudo systemctl disable"
alias sta="sudo systemctl status"

## Helpers
# Generate SSH key
alias sshkey='ssh-keygen -t ed25519 -f $HOME/.ssh/id_ed25519 -C "(whoami)@(hostname)-(date +'%y%m%d')"'

# Get the error messages from journalctl
alias jctl="journalctl -p 3 -xb"

# Display a calender
alias cal="ncal -3Mb"

if status is-interactive
    if type -q (which keychain &> /dev/null)
        keychain --quick --quiet --eval $KEYFILE | source
    end
end

## Load asdf if available
if test -e ~/.asdf/asdf.fish
    source ~/.asdf/asdf.fish
end

#source ~/.dotfiles/submodules/fisher/functions/fisher.fish
