Files
dotfiles/home/.zshrc
2025-08-30 20:23:00 +02:00

105 lines
2.6 KiB
Bash

# Main zsh configuration
# Common modules
source $HOME/.common_shell
bindkey '^R' history-incremental-search-backward
bindkey -v
function rgnvim() {
rg --vimgrep "$@" \
| fzf --delimiter : --nth 1,2,3,4 \
--preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \
| awk -F: '{print $1, $2}' \
| xargs -r sh -c 'nvim +"$1" "$0"'
}
# Functions
function battery_status() {
# Get the percentage of both batteries using acpi and extract the percentage values
#
perc1=$(acpi | grep -i 'Battery 0' | sed 's/^[^,]*, //' | awk '{print $1}' | tr -d '%,')
perc2=$(acpi | grep -i 'Battery 1' | sed 's/^[^,]*, //' | awk '{print $1}' | tr -d '%,')
echo -e "$(((perc1 + perc2) / 2))"
}
function time_status_custom() {
# Get the current local time without seconds
time=$(timedatectl | grep Local | awk '{print $5}' | awk -F: '{print $1 ":" $2 }')
echo -e "$time"
}
function up() {
# TODO: implement this function do autodetect what unison script to run
# Depending on the home user
user=$(pwd)
echo $user
}
function bdata() {
cd ~/shelter/projects/bigdata2025/
nvim .
}
function sc() {
cd ~/shelter/projects/scripts/
nvim . -c
}
function tm() {
if [[ -n "$TMUX" ]]; then
tmux detach
else
tmux attach 2>/dev/null || tmux new-session
fi
}
function r() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# Update the terminal colors
if [ "$TERM" = "linux" ]; then
echo -en "\e]P0000000" #black
echo -en "\e]P8393939" #darkgrey
echo -en "\e]P1D75F5F" #darkred
echo -en "\e]P9E33636" #red
echo -en "\e]P287AF5F" #darkgreen
echo -en "\e]PA98E34D" #green
echo -en "\e]P3D7AF87" #brown
echo -en "\e]PBFFD75F" #yellow
echo -en "\e]P49292E3" #darkblue
echo -en "\e]PCB9B9F3" #blue
echo -en "\e]P5BD53A5" #darkmagenta
echo -en "\e]PDD633B2" #magenta
echo -en "\e]P65FAFAF" #darkcyan
echo -en "\e]PE44C9C9" #cyan
echo -en "\e]P7AAAAAA" #lightgrey
echo -en "\e]PFCCCCCC" #white
clear #for background artifacting
fi
# useful fror checking for nix or other
if [ -f "/etc/NIXOS" ]; then
# nachbesserungen
alias cd="z"
alias ls="eza"
alias cat="bat"
alias ls='exa'
export TERM='kitty'
# We're on NixOS
eval "$(starship init zsh)"
else
# Custom manual prompt
alias z="cd"
#Default prompt
if [ -f "$HOME/programs_local/starship" ]; then
export STARSHIP_CONFIG=~/configuration/other/starship.toml
eval "$(starship init zsh)"
else
PS1="%n@%m %1~$ "
fi
fi