dotfiles/main
2024-10-06 09:59:51 +02:00

179 lines
4.4 KiB
Text

# My .zshrc the core for everything
#
# Set the path(s) to the config file(s)
CONFIG_PATH="$HOME/.config/dotfiles/config"
DEFAULT_CONFIG_PATH="$HOME/.config/dotfiles/config.default"
#
# Give an Error if the default configuration could not be found
if [ ! -f "${DEFAULT_CONFIG_PATH}" ]
then
echo "Error: The default configuration file (${DEFAULT_CONFIG_PATH}) could not be found"
exit 1
fi
#
# Source the default configuration to prevent errors
source "${DEFAULT_CONFIG_PATH}"
#
# Copy the default configuration file if it does not exist
if [ ! -f "${CONFIG_PATH}" ]
then
cp "${DEFAULT_CONFIG_PATH}" "${CONFIG_PATH}"
fi
#
# Source the normal configuration
source "${CONFIG_PATH}"
#
# Detect Device Arch
arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
case "${arch}" in
x86_64) arch="amd64" ;;
armv*) arch="arm" ;;
arm64) arch="arm64" ;;
aarch64) arch="arm64" ;;
i686) arch="386" ;;
esac
if [ "${arch}" = "arm64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then
arch=arm
fi
#
# Detect Device Platform
platform="$(uname -s | awk '{print tolower($0)}')"
case "${platform}" in
linux) platform="linux" ;;
darwin) platform="darwin" ;;
esac
#
# Set the OMP Path and create the directory
OMP_PATH="$HOME/.config/dotfiles/oh-my-posh"
[ ! -d $OMP_PATH ] && mkdir -p "$(dirname $OMP_PATH)"
#
# Set the path to the OMP Theme
OMP_THEME_PATH="$OMP_PATH/$OMP_THEME.toml"
#
# Set the OMP target Platform
OMP_TARGET="$platform-$arch"
#
# Set the path to the OMP Executeable
OMP_EXE="$OMP_PATH/posh-$OMP_TARGET"
#
# Download OMP if it does not exist
if [ ! -f $OMP_EXE ]; then
echo "Downloading Oh My Posh for $OMP_TARGET"
curl -s -L -o $OMP_EXE "https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-$OMP_TARGET"
chmod +x $OMP_EXE
fi
#
# Alias OMP
alias oh-my-posh=$OMP_EXE
#
# Initialize OMP
eval "$(oh-my-posh init zsh --config $OMP_THEME_PATH)"
#
# Get and download zinit
ZINIT_HOME="$HOME/.config/dotfiles/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
#
# Initialize zinit
source "${ZINIT_HOME}/zinit.zsh"
#
# Command Syntax Highlighting
zinit light zsh-users/zsh-syntax-highlighting
#
# Command Completions
zinit light zsh-users/zsh-completions
#
# Inline Command Suggestions based on history
zinit light zsh-users/zsh-autosuggestions
#
# Load the zsh completion system
autoload -U compinit && compinit
#
# Initialize Zoxide if it exists
if command -v zoxide &> /dev/null
then
eval "$(zoxide init --cmd cd zsh)"
fi
#
# Initialize TheF*ck if it exists
if command -v thefuck &> /dev/null
then
eval "$(thefuck --alias)"
fi
#
# Add boundaries to the path if it exists
if [ -f "$HOME/.bndpath" ]
then
PATH="$(cat $HOME/.bndpath)/exec/bin:$PATH"
elif [ -d "$HOME/boundaries" ]
then
PATH="$HOME/boundaries/exec/bin:$PATH"
fi
#
# Colored ls
alias ls="ls --color=auto"
#
# ls like colored completions
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
#
# Alias please to run0, doas, sudo or su
if command -v run0 &> /dev/null
then
alias please='run0 env WAYLAND_DISPLAY="$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" DISPLAY="$DISPLAY"'
elif command -v doas &> /dev/null
then
alias please='doas env WAYLAND_DISPLAY="$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" DISPLAY="$DISPLAY"'
elif command -v sudo &> /dev/null
then
alias please='sudo env WAYLAND_DISPLAY="$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" DISPLAY="$DISPLAY"'
elif command -v su &> /dev/null
then
alias please='su -c env WAYLAND_DISPLAY="$WAYLAND_DISPLAY" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" DISPLAY="$DISPLAY"'
fi
#
# Alias la to ls -la
alias la="ls -la"
#
# Enable emacs keybindings
bindkey -e
#
# The file the History is written to
HISTFILE=~/.zsh_history
#
# The maximum History Size
SAVEHIST=$HISTSIZE
#
# Erease duplicates
HISTDUP=erase
#
# Share History between Sessions
setopt appendhistory
setopt sharehistory
#
# Ignore when Space is in front
setopt hist_ignore_space
#
# Ingore Duplicates
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
#
# Command to update Dotfiles
update-dotfiles () {
pushd "$HOME/.config/dotfiles"
git pull
oh-my-posh upgrade
popd
echo "Dotfiles updated. You might need to restart your shell with exec zsh."
}
#
# Show pfetch if it is enabled and installed
if [ "${SHOW_PFETCH}" = "1" ] && command -v pfetch &> /dev/null
then
alias clear="clear && pfetch"
pfetch
fi