some changes

This commit is contained in:
piecka 2025-03-12 08:58:13 +01:00
parent cea0b562e9
commit 47a2952674
3 changed files with 149 additions and 94 deletions

86
.zshdef Normal file
View file

@ -0,0 +1,86 @@
# ─< Helper functions >─────────────────────────────────────────────────────────────────
# ANSI color codes
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Logging functions with emojis
echo_error() {
local msg="${RED}❌ $1${NC}\n"
# printf "$msg" >&2
_MESSAGES[error]+="$msg"
}
echo_warning() {
local msg="${YELLOW}⚠️ $1${NC}\n"
# printf "$msg"
_MESSAGES[warn]+="$msg"
}
echo_info() {
local msg="${CYAN} $1${NC}\n"
# printf "$msg"
_MESSAGES[info]+="$msg"
}
# ─< proxy config >───────────────────────────────────────────────────────────────────────
proxy() {
local ip="172.22.11.69"
local port="8080"
# Check if the IP and port are reachable
if nc -z -w5 $ip $port; then
# If reachable, set the proxy environment variables
export http_proxy="http://$ip:$port"
export https_proxy="http://$ip:$port"
export HTTP_PROXY="http://$ip:$port"
export HTTPS_PROXY="http://$ip:$port"
echo_info "Proxy set to: http://$ip:$port"
else
echo_error "IP $ip with port $port is not reachable."
fi
alias proxy='echo "http: $HTTP_PROXY"; echo "https: $HTTPS_PROXY"'
}
# ─< unset proxy >────────────────────────────────────────────────────────────────────────
noproxy() {
unset {HTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy}
}
# Load completions
autoload -Uz compinit && compinit
bindkey -e
# # Define custom word style that treats special characters as word boundaries
autoload -Uz select-word-style
select-word-style bash
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
# Huge history. Doesn't appear to slow things down, so why not?
HISTSIZE=500000
HISTFILESIZE=100000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
# Completion styling
zstyle :compinstall filename "$HOME/.zshrc"
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath'
setopt autocd notify
# End of lines configured by zsh-newuser-install

37
.zshenv Normal file
View file

@ -0,0 +1,37 @@
# ─< paths >──────────────────────────────────────────────────────────────────────────────
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
if [ -e "$HOME/.local/bin/lazydocker" ]; then
alias ld="$HOME/.local/bin/lazydocker"
fi
fi
# ─< linux binary via script installation >───────────────────────────────────────────────
[ -d "$HOME/.bin/nvim-linux64/bin" ] && {
export PATH="$HOME/.bin/nvim-linux64/bin:$PATH"
echo_info "neovim at $HOME/.bin/nvim-linux64/bin/nvim"
}
# ─< go bin path >────────────────────────────────────────────────────────────────────────
[ -d "$HOME/go/bin" ] && {
export PATH="$HOME/go/bin:$PATH"
echo_info "Go programs at $HOME/go/bin/"
}
# ─< cargo bin path >─────────────────────────────────────────────────────────────────────
if [ -e "$HOME/.cargo/env" ]; then
echo_info "Loadet $HOME/.cargo/env"
. "$HOME/.cargo/env"
else
[ -d "$HOME/.cargo/bin" ] && {
export PATH="$HOME/.cargo/bin:$PATH"
echo_info "Cargo programs at $HOME/.cargo/bin/"
}
fi
# bun completions
# [ -s "$HOME/.bun/_bun" ] && . "$HOME/.bun/_bun"
# [ -s "$HOME/.bun/_bun" ] && export BUN_INSTALL="$HOME/.bun" && export PATH="$BUN_INSTALL/bin:$PATH"
# ─< fzf plugin >─────────────────────────────────────────────────────────────────────────
[ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH"

120
.zshrc
View file

@ -1,36 +1,26 @@
# ─< Helper functions >───────────────────────────────────────────────────────────────── [[ -e "$HOME/.zshdef" ]] && . "$HOME/.zshdef" # <-- Defaults like echos and colors
# ANSI color codes
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
LIGHT_GREEN='\033[0;92m'
BOLD='\033[1m'
NC='\033[0m' # No Color
proxy() { # ─< Check if the given command exists silently >─────────────────────────────────────────
local ip="172.22.11.69" command_exists() {
local port="8080" command -v "$@" >/dev/null 2>&1
}
# Check if the IP and port are reachable #
if nc -z -w5 $ip $port; then # Check if the user is root and set sudo variable if necessary
# If reachable, set the proxy environment variables check_root() {
export http_proxy="http://$ip:$port" if [[ "${EUID}" -ne 0 ]]; then
export https_proxy="http://$ip:$port" if command_exists sudo; then
export HTTP_PROXY="http://$ip:$port" echo_info "User <$(whoami)> is not root. Using sudo for privileged operations."
export HTTPS_PROXY="http://$ip:$port" _sudo="sudo"
echo_info "Proxy set to: http://$ip:$port"
else else
echo_error "IP $ip with port $port is not reachable." echo_error "No sudo found and you're not root! Can't install packages."
fi
else
echo_info "Root access confirmed."
_sudo=""
fi fi
alias proxy='echo "http: $HTTP_PROXY"; echo "https: $HTTPS_PROXY"'
} }
noproxy() { # ───────────────────────────────────< Message storage >─────────────────────────────────
unset {HTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy}
}
# Message storage
typeset -A _MESSAGES typeset -A _MESSAGES
_MESSAGES=( _MESSAGES=(
[error]="" [error]=""
@ -38,25 +28,6 @@ _MESSAGES=(
[info]="" [info]=""
) )
# Logging functions with emojis
echo_error() {
local msg="${RED}$1${NC}\n"
printf "$msg" >&2
_MESSAGES[error]+="$msg"
}
echo_warning() {
local msg="${YELLOW}⚠️ $1${NC}\n"
printf "$msg"
_MESSAGES[warn]+="$msg"
}
echo_info() {
local msg="${CYAN} $1${NC}\n"
printf "$msg"
_MESSAGES[info]+="$msg"
}
# Display stored messages # Display stored messages
error_log() { error_log() {
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0 [[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0
@ -81,26 +52,6 @@ error_log() {
done done
} }
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# Check if the user is root and set sudo variable if necessary
check_root() {
if [[ "${EUID}" -ne 0 ]]; then
if command_exists sudo; then
echo_info "User <$(whoami)> is not root. Using sudo for privileged operations."
_sudo="sudo"
else
echo_error "No sudo found and you're not root! Can't install packages."
fi
else
echo_info "Root access confirmed."
_sudo=""
fi
}
_init() { _init() {
if command_exists oh-my-posh; then if command_exists oh-my-posh; then
# eval "$(oh-my-posh init zsh --config 'https://git.k4li.de/dotfiles/oh-my-posh/raw/branch/main/amro.toml')" # eval "$(oh-my-posh init zsh --config 'https://git.k4li.de/dotfiles/oh-my-posh/raw/branch/main/amro.toml')"
@ -123,11 +74,18 @@ _init() {
} }
_sources() { _sources() {
if [ -e "$HOME/.zshenv" ]; then
echo_info "Loadet zshenv"
. "$HOME/.zshenv"
fi
if [ -e "$HOME/.bash_aliases" ]; then if [ -e "$HOME/.bash_aliases" ]; then
echo_info "Loadet bash_aliases"
. "$HOME/.bash_aliases" . "$HOME/.bash_aliases"
else else
if command_exists curl; then if command_exists curl; then
curl -fsSL https://git.k4li.de/dotfiles/bash/raw/branch/main/.bash_aliases -o "$HOME/.bash_aliases" curl -fsSL https://git.k4li.de/dotfiles/bash/raw/branch/main/.bash_aliases -o "$HOME/.bash_aliases"
echo_info "(Down)loadet bash_aliases"
. "$HOME/.bash_aliases" . "$HOME/.bash_aliases"
else else
echo_warning "Couldn't setup aliases properly.." echo_warning "Couldn't setup aliases properly.."
@ -136,7 +94,6 @@ _sources() {
local sourceDir="$HOME/.zsh" local sourceDir="$HOME/.zsh"
local sourceOptions=( local sourceOptions=(
# "$_alias"
"defaults" "defaults"
"plugins" "plugins"
"installs" "installs"
@ -151,31 +108,6 @@ _sources() {
done done
} }
_environment() {
if command_exists nvim; then
export EDITOR="$(which nvim)"
fi
# ─< paths >──────────────────────────────────────────────────────────────────────────────
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
if [ -e "$HOME/.local/bin/lazydocker" ]; then
alias ld="$HOME/.local/bin/lazydocker"
fi
fi
[ -d "$HOME/go/bin" ] && export PATH="$HOME/go/bin:$PATH"
[ -d "$HOME/.cargo/bin" ] && export PATH="$HOME/.cargo/bin:$PATH"
[ -e "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
# bun completions
[ -s "$HOME/.bun/_bun" ] && . "$HOME/.bun/_bun"
[ -s "$HOME/.bun/_bun" ] && export BUN_INSTALL="$HOME/.bun" && export PATH="$BUN_INSTALL/bin:$PATH"
[ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH"
}
_end() { _end() {
if command_exists fastfetch; then if command_exists fastfetch; then
clear && clear &&
@ -191,7 +123,7 @@ _end() {
} }
main() { main() {
_environment proxy
_init _init
_sources _sources
_end _end