set -o vi

export LC_ALL=en_US.UTF-8

export PATH=/Users/jetpac/.asdf/shims/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jetpac/work/flutter/bin:$HOME/.rd/bin:$HOME/bin:$PATH:$HOME/.fzf/bin

# homebrew config
# output of brew shellenv
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
fpath[1,0]="/opt/homebrew/share/zsh/site-functions";
eval "$(/usr/bin/env PATH_HELPER_ROOT="/opt/homebrew" /usr/libexec/path_helper -s)"
[ -z "${MANPATH-}" ] || export MANPATH=":${MANPATH#:}";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";



alias oe='open /Applications/Emacs.app'
# Force mc to use bash for its subshell
alias mc='SHELL=/bin/bash mc'

alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
alias -g N="2>&1 "
alias pig='ping'
# export PATH=$HOME/.rd/bin
#

# on speccy only
if [[ "$(hostname)" == "speccy" ]];
then
    # defined via https://github.com/syl20bnr/spacemacs/wiki/Terminal
    export TERM=xterm-24bit
    alias ssh="TERM=xterm-256color ssh"
    alias vi=te
    alias vim=te
fi


# for gems installed in my home direcotry
# inspiration: https://guides.cocoapods.org/using/getting-started.html#installation
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH


# change iTerm & tmux profile 
# doc:
#	https://iterm2.com/documentation-escape-codes.html
#	https://github.com/tmux/tmux/issues/1502

## change color profile in iTerm
##it2prof() { echo -e "\033]50;SetProfile=$1\a" }

function print_osc() {
    if [[ -n $TMUX ]] ; then
        printf '\033Ptmux;\033\033]';
    else printf '\033]'; fi
}

function print_st() {
    if [[ -n $TMUX ]] ; then
        printf '\a\033\\'
    else printf '\a'; fi
}

function set_iterm_profile() {
  readonly profile=${1:?"The profile must be specified."}
  print_osc
  printf "1337;SetProfile=$profile"
  print_st
}

function set_tmux_profile() {
  if [[ -n $TMUX ]]; then
    profile=${1:?"The profile must be specified."}
    tmux source-file $HOME/.tmux/plugins/tmux-colors-solarized/tmuxcolors-${profile}.conf
  fi
}

function set_dark() {
  set_iterm_profile 'Solarized Dark' 
  set_tmux_profile 'dark'
}

function set_light() {
  set_iterm_profile 'Solarized Light' 
  set_tmux_profile 'light'
}

export seznam6='2a02:598:2::1222'

export OPENAI_API_KEY='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'

# for flutter
# export PATH=$PATH:/Users/jetpac/Documents/flutter-dev-env/bin
export NVM_DIR="$HOME/.nvm"
# nvm initialization is commented out; it significantly slows down shell startup
# [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
#

ZSH_AUTOSUGGEST_ACCEPT_WIDGETS='vi-forward-char'
#ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS='end-of-line'
#
# alias km='kubectl --kubeconfig /Users/jetpac/.kube.lenovo/config'


alias nextcloud-shell='k exec -n nextcloud deployments/nextcloud -c nextcloud -it -- runuser --user www-data bash'
alias nextcloud-shell-root='k exec -n nextcloud deployments/nextcloud -c nextcloud -it -- bash'
alias occ='k exec -n nextcloud deployments/nextcloud -c nextcloud -it -- runuser --user www-data /var/www/html/occ'

alias speech_to_text="$HOME/Downloads/whisper.cpp/convert_video_to_txt.sh"


if [ -f "/Users/jetpac/.local/bin/k9s" ]; then
	alias k9s='/Users/jetpac/.local/bin/k9s --logoless'
fi


# lh nodes function for kubectl
if [[ -n ${commands[kubectl]} ]]; then
    lh_nodes() {
        local ns="${1:-longhorn-system}"
        kubectl -n "$ns" get nodes.longhorn.io -o yaml | \
            yq eval '
    .items[] |
    {
      "node": .metadata.name,
      "allowScheduling": .spec.allowScheduling,
      "disks": (
        [ (.spec.disks // {}) | to_entries | .[] |
          {
            "diskName": .key,
            "path": .value.path,
            "allowScheduling": .value.allowScheduling,
            "evictionRequested": .value.evictionRequested,
            "storageReservedGiB": ((.value.storageReserved // 0) / 1073741824)
          }
        ]
      ),
      "diskStatus": (
        [ (.status.diskStatus // {}) | to_entries | .[] |
          {
            "diskName": .key,
            "storageAvailableGiB": ((.value.storageAvailable // 0) / 1073741824),
            "storageMaximumGiB":  ((.value.storageMaximum  // 0) / 1073741824),
            "storageScheduledGiB":((.value.storageScheduled // 0) / 1073741824)
          }
        ]
      )
    }'
    }

fi
alias scm-ssh='/Users/jetpac/.ssh/scm-script.sh'
