addet yazi 'y' function

This commit is contained in:
pik4li 2024-12-25 10:07:18 +01:00
parent 2ef1ba0f33
commit 24ec2d6925

322
.zshrc
View file

@ -10,52 +10,52 @@ NC='\033[0m' # No Color
# Message storage
typeset -A _MESSAGES
_MESSAGES=(
[error]=""
[warn]=""
[info]=""
[error]=""
[warn]=""
[info]=""
)
# Logging functions with emojis
echo_error() {
local msg="${RED}$1${NC}\n"
printf "$msg" >&2
_MESSAGES[error]+="$msg"
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"
local msg="${YELLOW}⚠️ $1${NC}\n"
printf "$msg"
_MESSAGES[warn]+="$msg"
}
echo_info() {
local msg="${CYAN} $1${NC}\n"
printf "$msg"
_MESSAGES[info]+="$msg"
local msg="${CYAN} $1${NC}\n"
printf "$msg"
_MESSAGES[info]+="$msg"
}
# Display stored messages
error_log() {
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0
typeset -A headers colors
headers=(
error "❌ Errors"
warn "⚠️ Warnings"
info " Info"
)
colors=(
error "$RED"
warn "$YELLOW"
info "$CYAN"
)
typeset -A headers colors
headers=(
error "❌ Errors"
warn "⚠️ Warnings"
info " Info"
)
colors=(
error "$RED"
warn "$YELLOW"
info "$CYAN"
)
for type in error warn info; do
[[ -n "${_MESSAGES[$type]}" ]] && {
printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n"
printf "${_MESSAGES[$type]}"
}
done
for type in error warn info; do
[[ -n "${_MESSAGES[$type]}" ]] && {
printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n"
printf "${_MESSAGES[$type]}"
}
done
}
# ─< Check if the given command exists silently >─────────────────────────────────────────
@ -119,7 +119,7 @@ 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:*' 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'
@ -131,7 +131,7 @@ if command_exists fzf; then
source <(fzf --zsh)
fi
_init (){
_init() {
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 '~/.zsh/themes/sim-web.toml')"
@ -146,7 +146,7 @@ _init (){
eval "$(zoxide init zsh --cmd cd)"
fi
# ─< environment variables for zsh >──────────────────────────────────────────────────────
# ─< environment variables for zsh >──────────────────────────────────────────────────────
local zplug="$HOME/.zsh/plugins"
local zFzfCd="$zplug/custom/zsh-interactive-cd.plugin.zsh"
@ -161,34 +161,34 @@ _init (){
local zExtraction="$zplug/extract/extract.plugin.zsh"
local _pluginlist=(
"$zAutosg"
"$zSynthl"
"$zTruecolor"
"$zAutopairs"
"$zFzf"
"$zFzfCd"
"$zAgentManagement"
"$zCommandNotFound"
"$zExtraction"
)
"$zAutosg"
"$zSynthl"
"$zTruecolor"
"$zAutopairs"
"$zFzf"
"$zFzfCd"
"$zAgentManagement"
"$zCommandNotFound"
"$zExtraction"
)
DEBUG_PLUG=""
DEBUG_PLUG=""
# ─< init plugis >────────────────────────────────────────────────────────────────────────
# ─< init plugis >────────────────────────────────────────────────────────────────────────
for zPlug in "${_pluginlist[@]}"; do
[[ -f "$zPlug" ]] &&
. $zPlug
[[ -f "$zPlug" ]] &&
. $zPlug
DEBUG_PLUG="$DEBUG_PLUG
plugin $zPlug loadet."
done
}
_alias(){
_alias() {
alias please="sudo"
# ─< easier dir up >────────────────────────────────────────────────────────────────────────
alias ..="cd .."
# ─< weather >──────────────────────────────────────────────────────────────────────────────
# ─< weather >──────────────────────────────────────────────────────────────────────────────
alias www="curl wttr.in/Ulm"
# ─< colored ip >───────────────────────────────────────────────────────────────────
@ -214,10 +214,18 @@ _alias(){
alias lazygit="$HOME/go/bin/lazygit" &&
alias lg="lazygit"
# ─< cli explorer >───────────────────────────────────────────────────────────────────────
# ─< cli explorer >───────────────────────────────────────────────────────────────────────
if command_exists yazi; then
echo_info "yazi is the explorer of choise"
alias lf="yazi || ya pack -i"
function y() {
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"
}
elif command_exists ranger; then
echo_info "ranger is the explorer of choise"
alias lf="ranger"
@ -279,7 +287,7 @@ _alias(){
alias ts="tmux source $HOME/.tmux.conf"
fi
# ─< v stands vor virtual-machine (kvm) >─────────────────────────────────────────────────
# ─< v stands vor virtual-machine (kvm) >─────────────────────────────────────────────────
if command_exists virsh; then
alias vm="virsh"
alias vms="virsh start"
@ -287,7 +295,7 @@ _alias(){
alias vmsd="virsh shutdown"
fi
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
if command_exists trash; then
alias rm="trash"
alias t="trash"
@ -346,58 +354,58 @@ _alias(){
alias dl="docker compose logs -f"
alias dc="docker compose"
alias appupdate="docker compose pull && docker compose up -d --force-recreate"
drweb() {
drweb_help() {
drweb() {
drweb_help() {
echo "Usage: drweb <server_type> [directory] [port]"
echo " server_type: Type of server to use (nginx or php)"
echo " directory: Directory to serve (default: current directory)"
echo " port: Port to use (default: 8080)"
return
}
}
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
drweb_help
return
fi
fi
local server_type="$1"
local dir="${2:-./}"
local port="${3:-8080}"
local server_type="$1"
local dir="${2:-./}"
local port="${3:-8080}"
if [[ ! -d "$dir" ]]; then
if [[ ! -d "$dir" ]]; then
echo "Error: Directory $dir does not exist"
drweb_help
return 1
fi
fi
case "$server_type" in
nginx)
if [[ -f "$dir/index.html" || -f "$dir/index.php" ]]; then
docker run -p "$port:80" -v "$dir:/usr/share/nginx/html:ro" nginx:alpine
echo "Nginx is serving $dir on port $port"
else
echo "Error: No index.html or index.php found in $dir"
drweb_help
return 1
fi
;;
php)
if [[ -f "$dir/index.php" || -f "$dir/index.html" ]]; then
docker run -p "$port:80" -v "$dir:/var/www/html" php:7.4-apache
echo "PHP Apache is serving $dir on port $port"
else
echo "Error: No index.php or index.html found in $dir"
drweb_help
return 1
fi
;;
*)
echo "Error: Unsupported server type '$server_type'"
drweb_help
return 1
;;
esac
}
case "$server_type" in
nginx)
if [[ -f "$dir/index.html" || -f "$dir/index.php" ]]; then
docker run -p "$port:80" -v "$dir:/usr/share/nginx/html:ro" nginx:alpine
echo "Nginx is serving $dir on port $port"
else
echo "Error: No index.html or index.php found in $dir"
drweb_help
return 1
fi
;;
php)
if [[ -f "$dir/index.php" || -f "$dir/index.html" ]]; then
docker run -p "$port:80" -v "$dir:/var/www/html" php:7.4-apache
echo "PHP Apache is serving $dir on port $port"
else
echo "Error: No index.php or index.html found in $dir"
drweb_help
return 1
fi
;;
*)
echo "Error: Unsupported server type '$server_type'"
drweb_help
return 1
;;
esac
}
fi
# ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
@ -459,7 +467,7 @@ _coding_() {
export EDITOR="codium"
fi
# ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
# ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
if command_exists nvim; then
if command_exists neovide; then
if [ -n "$TMUX" ]; then
@ -486,22 +494,22 @@ _coding_() {
# Check if npm is available, then create the alias
if command_exists npm; then
npmrun(){
npmrun() {
npmrun_help() {
echo "Usage: npmrun [environment] [optional:port]"
echo " environment: The npm environment you want to run (e.g. dev)"
echo " port: Port to use (default: 8000)"
return
}
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
}
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
npmrun_help
return
fi
fi
local env="$1"
local port="${2:-8080}"
local env="$1"
local port="${2:-8080}"
npm run "$env" -- --host="$(get_ip)" --port="$port"
npm run "$env" -- --host="$(get_ip)" --port="$port"
}
fi
@ -524,68 +532,68 @@ fi
get_packager() {
. /etc/os-release
case "$ID" in
# Debian-based
ubuntu|debian|pop|kali|zorin)
if command_exists nala; then
alias search="nala search"
alias install="$_sudo nala install --assume-yes"
alias update="$_sudo nala update && $_sudo nala upgrade --full"
alias remove="$_sudo nala purge"
else
alias search="apt-cache search"
alias install="$_sudo apt-get install --yes"
alias update="$_sudo apt-get update && $_sudo apt-get upgrade"
alias remove="$_sudo apt-get purge"
fi
alias unbreak="$_sudo dpkg --configure -a"
;;
# Debian-based
ubuntu | debian | pop | kali | zorin)
if command_exists nala; then
alias search="nala search"
alias install="$_sudo nala install --assume-yes"
alias update="$_sudo nala update && $_sudo nala upgrade --full"
alias remove="$_sudo nala purge"
else
alias search="apt-cache search"
alias install="$_sudo apt-get install --yes"
alias update="$_sudo apt-get update && $_sudo apt-get upgrade"
alias remove="$_sudo apt-get purge"
fi
alias unbreak="$_sudo dpkg --configure -a"
;;
# Arch-based
arch|manjaro|endevouros|garuda)
if command_exists paru; then
alias search="paru -Ss"
alias install="paru -S --noconfirm"
alias update="paru -Syu"
alias remove="paru -R"
elif command_exists yay; then
alias search="yay -Ss"
alias install="yay -S --noconfirm"
alias update="yay -Syu"
alias remove="yay -R"
else
alias search="$_sudo pacman -Ss"
alias install="$_sudo pacman -S --noconfirm"
alias update="$_sudo pacman -Syu"
alias remove="$_sudo pacman -R"
fi
;;
# Arch-based
arch | manjaro | endevouros | garuda)
if command_exists paru; then
alias search="paru -Ss"
alias install="paru -S --noconfirm"
alias update="paru -Syu"
alias remove="paru -R"
elif command_exists yay; then
alias search="yay -Ss"
alias install="yay -S --noconfirm"
alias update="yay -Syu"
alias remove="yay -R"
else
alias search="$_sudo pacman -Ss"
alias install="$_sudo pacman -S --noconfirm"
alias update="$_sudo pacman -Syu"
alias remove="$_sudo pacman -R"
fi
;;
# RHEL-based
fedora|centos)
alias search="dnf search"
alias install="$_sudo dnf install --yes"
alias update="$_sudo dnf update"
alias remove="$_sudo dnf remove"
;;
# RHEL-based
fedora | centos)
alias search="dnf search"
alias install="$_sudo dnf install --yes"
alias update="$_sudo dnf update"
alias remove="$_sudo dnf remove"
;;
# openSUSE
opensuse-*)
alias search="zypper search"
alias install="$_sudo zypper install --no-confirm"
alias update="$_sudo zypper update"
alias remove="$_sudo zypper remove"
;;
# openSUSE
opensuse-*)
alias search="zypper search"
alias install="$_sudo zypper install --no-confirm"
alias update="$_sudo zypper update"
alias remove="$_sudo zypper remove"
;;
# Alpine
alpine)
alias install="$_sudo apk add"
alias update="$_sudo apk update && $_sudo apk upgrade"
alias remove="$_sudo apk del"
;;
# Alpine
alpine)
alias install="$_sudo apk add"
alias update="$_sudo apk update && $_sudo apk upgrade"
alias remove="$_sudo apk del"
;;
esac
}
_tools_(){
_tools_() {
if ! command_exists has; then
$(git clone https://github.com/kdabir/has.git /tmp/has && cd /tmp/has && sudo make install && rm -rf /tmp/has)
else
@ -596,7 +604,7 @@ _tools_(){
fi
}
_environment(){
_environment() {
if command_exists nvim; then
export EDITOR="nvim"
fi
@ -605,7 +613,7 @@ _environment(){
export RANGER_LOAD_DEFAULT_RC="FALSE"
fi
# ─< paths >──────────────────────────────────────────────────────────────────────────────
# ─< paths >──────────────────────────────────────────────────────────────────────────────
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
if [ -e "$HOME/.local/bin/lazydocker" ]; then
@ -625,7 +633,7 @@ _environment(){
[ -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
clear &&
fastfetch
@ -639,7 +647,7 @@ _end(){
error_log
}
main(){
main() {
get_packager
_init
_environment