From 2585c0102ad1e55207690d2a70b9abb1540cbfbf Mon Sep 17 00:00:00 2001 From: pika <67532734+pik4li@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:01:06 +0100 Subject: [PATCH] changed config for a more structurized approach --- .zsh/.aliases.zsh | 401 ++++++++++++++++++++++++++++++++++++ .zsh/.defaults.zsh | 33 +++ .zsh/.plugins.zsh | 35 ++++ .zshrc | 498 +++------------------------------------------ 4 files changed, 494 insertions(+), 473 deletions(-) create mode 100644 .zsh/.aliases.zsh create mode 100644 .zsh/.defaults.zsh create mode 100644 .zsh/.plugins.zsh diff --git a/.zsh/.aliases.zsh b/.zsh/.aliases.zsh new file mode 100644 index 0000000..09e68aa --- /dev/null +++ b/.zsh/.aliases.zsh @@ -0,0 +1,401 @@ +__autopackager__() { + . /etc/os-release + case "$ID" in + # Debian-based + ubuntu | debian | pop | kali | zorin | rhinoh | raspbian) + 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 + ;; + + # RHEL-based + fedora | centos) + alias search="dnf search" + alias install="$_sudo dnf install" + 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" + ;; + + # Alpine + alpine) + alias install="$_sudo apk add" + alias update="$_sudo apk update && $_sudo apk upgrade" + alias remove="$_sudo apk del" + ;; + esac +} + +_alias() { + alias please="sudo" + + # ─< easier dir up >──────────────────────────────────────────────────────────────────────── + alias ..="cd .." + + # ─< weather >────────────────────────────────────────────────────────────────────────────── + alias www="curl wttr.in/Ulm" + + # ─< colored ip >─────────────────────────────────────────────────────────────────── + alias ip="ip --color=always" + + # ─< check for rg >───────────────────────────────────────────────────────────────────────── + if command_exists rg; then + alias grep="rg --color=always" + else + alias grep="grep --color=always" + fi + + # ─< linutil >──────────────────────────────────────────────────────────────────────────── + alias linutil="curl -fsSL https://christitus.com/linux | sh" + alias "linutil-dev"="curl -fsSL https://christitus.com/linuxdev | sh" + + # ─< telnet (starwars) >──────────────────────────────────────────────────────────────────── + if command_exists telnet; then + alias starwars="telnet -a telehack.com" + fi + + [[ -f "$HOME/go/bin/lazygit" ]] && + alias lazygit="$HOME/go/bin/lazygit" && + alias lg="lazygit" + + # ─< 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" + elif command_exists lf; then + echo_info "lf is the explorer of choise" + fi + + # ─< rsync >──────────────────────────────────────────────────────────────────────────────── + if command_exists rsync; then + alias scp="rsync -avP" + alias cp="scp" + fi + + # ─< colorized ls >───────────────────────────────────────────────────────────────────────── + if command_exists exa; then + alias ls="exa --icons -l --git" + alias l="exa --long --no-filesize --no-permissions --no-time --git --colour-scale --icons" + alias ll="exa --all --long --no-filesize --no-permissions --no-time --git --colour-scale --icons" + alias tree="exa --icons -l --tree" + elif command_exists lsd; then + alias ls="lsd -l -1 -h1 --almost-all --git" + alias l="lsd -1" + alias ll="lsd -1 --almost-all" + alias clearl="command clear && l" + alias tree="lsd --tree" + elif command_exists eza; then + alias ls="eza --icons --long --git" + alias l="eza --icons -l" + alias ll="eza --icons -laa" + alias tree="eza --icons -l --tree" + else + alias ls="ls --color=always -lAph" + alias l="ls --color=always -lph -w1" + alias ll="ls --color=always -lph" + fi + + # ─< t stands for tmux >──────────────────────────────────────────────────────────────────── + if command_exists tmux; then + local tmux_y="$(echo '-- tmux-session active! | connecting to active session --')" + local tmux_n="$(echo '-- no tmux-session found! | creating one --')" + ta() { + command tmux list-sessions >/dev/null 2>&1 + if [ $? -eq 0 ]; then + if command_exists notify-send; then + notify-send "TMUX" "${tmux_y}" + sleep 0.5 + tmux attach + else + echo_info "${tmux_y}" + sleep 0.5 + tmux attach + fi + else + if command_exists notify-send; then + notify-send "TMUX" "${tmux_n}" + sleep 0.5 + tmux + else + echo_info "$tmux_n" + sleep 0.5 + tmux + fi + fi + } + alias ts="tmux source $HOME/.tmux.conf" + fi + + # ─< t stands for trash(-cli) >─────────────────────────────────────────────────────────────── + if command_exists trash; then + alias rm="trash" + alias t="trash" + alias tlist="trash -list" + elif command_exists trash-cli; then + alias rm="trash-cli" + alias t="trash-cli" + alias tlist="trash-list" + else + echo_error "-- You do not have trash or trash-cli installed! Your 'rm' will be permanent! --" + fi + + # ─< bat alias >──────────────────────────────────────────────────────────────────────────── + if command_exists batcat; then + alias cat="batcat --color=always -p --paging=never" + alias less="batcat --paging always --color=always" + elif command_exists bat; then + alias cat="bat --color=always -p" + alias less="bat --paging always --color=always" + fi + + # ─< wireguard alias >──────────────────────────────────────────────────────────────────── + if command_exists wg-quick; then + alias wgup="wg-quick up" + alias wgdown="wg-quick down" + fi + + # ─< wireshark / termshark alias >──────────────────────────────────────────────────────── + if command_exists termshark; then + alias ws="$_sudo termshark" + fi + + # ─< fastfetch >──────────────────────────────────────────────────────────────────────────── + if command_exists fastfetch; then + alias ff="fastfetch" + alias clearff="command clear & fastfetch" + alias clearf="command clear & fastfetch" + if fastfetch --config os >/dev/null 2>&1; then + alias f="fastfetch --config os" + else + git clone https://git.k4li.de/mirrors/fastfetch.git "$HOME/.local/share/fastfetch" >/dev/null 2>&1 + exec "$SHELL" + fi + fi + + # ─< d stands for docker >────────────────────────────────────────────────────────────────── + if command_exists docker; then + alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash" + + alias up="docker compose up" + alias down="docker compose down" + alias pull="docker compose pull" + alias d="docker" + alias dr="docker run --rm -it" + alias drs="docker compose down && docker compose up -d --remove-orphans --force-recreate" + alias ds="docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" + alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" + alias dl="docker compose logs -f" + alias dc="docker compose" + alias appupdate="docker compose pull && docker compose up -d --force-recreate" + drweb() { + drweb_help() { + echo "Usage: drweb [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 + drweb_help + return + fi + + local server_type="$1" + local dir="${2:-./}" + local port="${3:-8080}" + + if [[ ! -d "$dir" ]]; then + echo "Error: Directory $dir does not exist" + drweb_help + return 1 + 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 + } + fi + + # ─< g stands for GIT >───────────────────────────────────────────────────────────────────── + if command_exists git; then + alias g="git" + alias gs="git status -sb" + alias gsl="git status" + alias gm='git checkout main && git merge' + alias gc="git clone --recurse-submodule" + gcl() { + if [ -z "$2" ]; then + git clone --depth=1 "https://github.com/$1" + else + git clone --depth=1 "https://github.com/$1" "$2" + fi + } + gck() { + if [ -z "$2" ]; then + git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" + else + git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" "$2" + fi + } + gcs() { + if [ -z "$2" ]; then + git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1" + else + git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1" "$2" + fi + } + alias gd="git diff" + alias ga="gd $1 && git add" + alias gp="git pull --recurse-submodule" + alias gms='git maintenance start' + alias gsu="git submodule foreach git pull && git add . && git commit -m ' updated 📌submodules' && echo '-- Committed changes, pushing now..' && sleep 1 && git push" + alias gcm="git commit -m" + alias gpu="git push --recurse-submodule=on-demand" + if command_exists lazygit; then + alias lg="lazygit" + fi + fi + +} + +_coding_() { + # ─< h stands for HUGO >────────────────────────────────────────────────────────────────── + if command_exists hugo; then + alias h='hugo' + alias hs='if [ -d ./public ]; then; echo "found public folder, cleaning it.." && command rm -rf ./public && hugo server -D --noHTTPCache --disableFastRender; else; hugo server -D --noHTTPCache --disableFastRender; fi' # --bind "$(get_ip)"' + fi + + # ─< VSCodium >───────────────────────────────────────────────────────────────────────────── + if command_exists codium; then + alias code="codium" + export EDITOR="codium" + fi + + # ─< neovide, the best frontend for any neovim-config >─────────────────────────────────── + if command_exists nvim; then + alias cnvim="command nvim" + if command_exists neovide; then + alias nvim="neovide --fork" + fi + + if [ -d "$HOME/.config/nvchad" ]; then + alias nvchad='NVIM_APPNAME="nvchad" command nvim' + alias neochad='NVIM_APPNAME="nvchad" neovide --fork' + fi + fi + + # Function to get the IP address + get_ip() { + ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1 + } + + # Check if npm is available, then create the alias + if command_exists npm; then + 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 + npmrun_help + return + fi + + local env="$1" + local port="${2:-8080}" + + npm run "$env" -- --host="$(get_ip)" --port="$port" + + } + fi + + if command_exists bc; then + math() { + echo "$*" | bc -l + } + else + echo_error "No bc, so no math will work" + fi +} + +main() { + __autopackager__ + _alias + _coding_ +} + +main diff --git a/.zsh/.defaults.zsh b/.zsh/.defaults.zsh new file mode 100644 index 0000000..69826f4 --- /dev/null +++ b/.zsh/.defaults.zsh @@ -0,0 +1,33 @@ +# 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 diff --git a/.zsh/.plugins.zsh b/.zsh/.plugins.zsh new file mode 100644 index 0000000..6e4f865 --- /dev/null +++ b/.zsh/.plugins.zsh @@ -0,0 +1,35 @@ +# ─< environment variables for zsh >────────────────────────────────────────────────────── +local zplug="$HOME/.zsh/plugins" + +local zFzfCd="$zplug/custom/zsh-interactive-cd.plugin.zsh" +local zTruecolor="$zplug/custom/256color.zsh" +local zAgentManagement="$zplug/custom/agent.zsh" +local zCommandNotFound="$zplug/custom/command-not-found.plugin.zsh" + +local zFzf="$zplug/fzf-zsh-plugin/fzf-zsh-plugin.plugin.zsh" +local zAutosg="$zplug/autosuggestions/zsh-autosuggestions.zsh" +local zSynthl="$zplug/syntax-highlighting/zsh-syntax-highlighting.zsh" +local zAutopairs="$zplug/autopairs/autopair.zsh" +local zExtraction="$zplug/extract/extract.plugin.zsh" + +local _pluginlist=( + "$zAutosg" + "$zSynthl" + "$zTruecolor" + "$zAutopairs" + "$zFzf" + "$zFzfCd" + "$zAgentManagement" + "$zCommandNotFound" + "$zExtraction" +) + +DEBUG_PLUG="" + +# ─< init plugis >──────────────────────────────────────────────────────────────────────── +for zPlug in "${_pluginlist[@]}"; do + [[ -f "$zPlug" ]] && + . $zPlug + DEBUG_PLUG="$DEBUG_PLUG + plugin $zPlug loadet." +done diff --git a/.zshrc b/.zshrc index e85452f..809e513 100644 --- a/.zshrc +++ b/.zshrc @@ -78,44 +78,12 @@ check_root() { fi } -# 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 - -# ─< init fzf for zsh >─────────────────────────────────────────────────────────────────── -if command_exists fzf; then - source <(fzf --zsh) -fi +git_installs() { + if [ -e "$HOME/.zsh/.install.sh" ]; then + echo_info "Git installs activated by '_install '" + . "$HOME/.zsh/.install.sh" + fi +} _init() { if command_exists oh-my-posh; then @@ -127,441 +95,34 @@ _init() { curl -s https://ohmyposh.dev/install.sh | $_sudo bash --norc -s -- -d /usr/bin/ fi + # ─< init fzf for zsh >─────────────────────────────────────────────────────────────────── + if command_exists fzf; then + source <(fzf --zsh) + fi + if command_exists zoxide; then eval "$(zoxide init zsh)" eval "$(zoxide init zsh --cmd cd)" fi +} - # ─< environment variables for zsh >────────────────────────────────────────────────────── - local zplug="$HOME/.zsh/plugins" - - local zFzfCd="$zplug/custom/zsh-interactive-cd.plugin.zsh" - local zTruecolor="$zplug/custom/256color.zsh" - local zAgentManagement="$zplug/custom/agent.zsh" - local zCommandNotFound="$zplug/custom/command-not-found.plugin.zsh" - - local zFzf="$zplug/fzf-zsh-plugin/fzf-zsh-plugin.plugin.zsh" - local zAutosg="$zplug/autosuggestions/zsh-autosuggestions.zsh" - local zSynthl="$zplug/syntax-highlighting/zsh-syntax-highlighting.zsh" - local zAutopairs="$zplug/autopairs/autopair.zsh" - local zExtraction="$zplug/extract/extract.plugin.zsh" - - local _pluginlist=( - "$zAutosg" - "$zSynthl" - "$zTruecolor" - "$zAutopairs" - "$zFzf" - "$zFzfCd" - "$zAgentManagement" - "$zCommandNotFound" - "$zExtraction" +_sources() { + local sourceDir="$HOME/.zsh" + local sourceOptions=( + "aliases" + "defaults" + "plugins" ) - DEBUG_PLUG="" - - # ─< init plugis >──────────────────────────────────────────────────────────────────────── - for zPlug in "${_pluginlist[@]}"; do - [[ -f "$zPlug" ]] && - . $zPlug - DEBUG_PLUG="$DEBUG_PLUG - plugin $zPlug loadet." + for _s in "${sourceOptions[@]}"; do + local _source_="${sourceDir}/.${_s}.zsh" + if [ -e "$_source_" ]; then + . $_source_ + fi + local _source_"" done } -_alias() { - alias please="sudo" - - # ─< easier dir up >──────────────────────────────────────────────────────────────────────── - alias ..="cd .." - # ─< weather >────────────────────────────────────────────────────────────────────────────── - alias www="curl wttr.in/Ulm" - - # ─< colored ip >─────────────────────────────────────────────────────────────────── - alias ip="ip --color=always" - - # ─< check for rg >───────────────────────────────────────────────────────────────────────── - if command_exists rg; then - alias grep="rg --color=always" - else - alias grep="grep --color=always" - fi - - # ─< linutil >──────────────────────────────────────────────────────────────────────────── - alias linutil="curl -fsSL https://christitus.com/linux | sh" - alias "linutil-dev"="curl -fsSL https://christitus.com/linuxdev | sh" - - # ─< telnet (starwars) >──────────────────────────────────────────────────────────────────── - if command_exists telnet; then - alias starwars="telnet -a telehack.com" - fi - - [[ -f "$HOME/go/bin/lazygit" ]] && - alias lazygit="$HOME/go/bin/lazygit" && - alias lg="lazygit" - - # ─< 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" - elif command_exists lf; then - echo_info "lf is the explorer of choise" - fi - - # ─< colorized ls >───────────────────────────────────────────────────────────────────────── - if command_exists exa; then - alias ls="exa --icons -l --git" - alias l="exa --long --no-filesize --no-permissions --no-time --git --colour-scale --icons" - alias ll="exa --all --long --no-filesize --no-permissions --no-time --git --colour-scale --icons" - alias tree="exa --icons -l --tree" - elif command_exists lsd; then - alias ls="lsd -l -1 -h1 --almost-all --git" - alias l="lsd -1" - alias ll="lsd -1 --almost-all" - alias clearl="command clear && l" - alias tree="lsd --tree" - elif command_exists eza; then - alias ls="eza --icons --long --git" - alias l="eza --icons -l" - alias ll="eza --icons -laa" - alias tree="eza --icons -l --tree" - else - alias ls="ls --color=always -lAph" - alias l="ls --color=always -lph -w1" - alias ll="ls --color=always -lph" - fi - - # ─< t stands for tmux >──────────────────────────────────────────────────────────────────── - if command_exists tmux; then - local tmux_y="$(echo '-- tmux-session active! | connecting to active session --')" - local tmux_n="$(echo '-- no tmux-session found! | creating one --')" - ta() { - command tmux list-sessions >/dev/null 2>&1 - if [ $? -eq 0 ]; then - if command_exists notify-send; then - notify-send "TMUX" "${tmux_y}" - sleep 0.5 - tmux attach - else - echo_info "${tmux_y}" - sleep 0.5 - tmux attach - fi - else - if command_exists notify-send; then - notify-send "TMUX" "${tmux_n}" - sleep 0.5 - tmux - else - echo_info "$tmux_n" - sleep 0.5 - tmux - fi - fi - } - alias ts="tmux source $HOME/.tmux.conf" - fi - - # ─< t stands for trash(-cli) >─────────────────────────────────────────────────────────────── - if command_exists trash; then - alias rm="trash" - alias t="trash" - alias tlist="trash -list" - elif command_exists trash-cli; then - alias rm="trash-cli" - alias t="trash-cli" - alias tlist="trash-list" - else - echo_error "-- You do not have trash or trash-cli installed! Your 'rm' will be permanent! --" - fi - - # ─< bat alias >──────────────────────────────────────────────────────────────────────────── - if command_exists batcat; then - alias cat="batcat --color=always -p --paging=never" - alias less="batcat --paging always --color=always" - elif command_exists bat; then - alias cat="bat --color=always -p" - alias less="bat --paging always --color=always" - fi - - # ─< wireguard alias >──────────────────────────────────────────────────────────────────── - if command_exists wg-quick; then - alias wgup="wg-quick up" - alias wgdown="wg-quick down" - fi - - # ─< wireshark / termshark alias >──────────────────────────────────────────────────────── - if command_exists termshark; then - alias ws="$_sudo termshark" - fi - - # ─< fastfetch >──────────────────────────────────────────────────────────────────────────── - if command_exists fastfetch; then - alias ff="fastfetch" - alias clearff="command clear & fastfetch" - alias clearf="command clear & fastfetch" - if fastfetch --config os >/dev/null 2>&1; then - alias f="fastfetch --config os" - else - git clone https://git.k4li.de/mirrors/fastfetch.git "$HOME/.local/share/fastfetch" >/dev/null 2>&1 - exec "$SHELL" - fi - fi - - # ─< d stands for docker >────────────────────────────────────────────────────────────────── - if command_exists docker; then - alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash" - - alias up="docker compose up" - alias down="docker compose down" - alias pull="docker compose pull" - alias d="docker" - alias dr="docker run --rm -it" - alias drs="docker compose down && docker compose up -d --remove-orphans --force-recreate" - alias ds="docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" - alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" - alias dl="docker compose logs -f" - alias dc="docker compose" - alias appupdate="docker compose pull && docker compose up -d --force-recreate" - drweb() { - drweb_help() { - echo "Usage: drweb [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 - drweb_help - return - fi - - local server_type="$1" - local dir="${2:-./}" - local port="${3:-8080}" - - if [[ ! -d "$dir" ]]; then - echo "Error: Directory $dir does not exist" - drweb_help - return 1 - 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 - } - fi - - # ─< g stands for GIT >───────────────────────────────────────────────────────────────────── - if command_exists git; then - alias g="git" - alias gs="git status -sb" - alias gsl="git status" - alias gm='git checkout main && git merge' - alias gc="git clone --recurse-submodule" - gcl() { - if [ -z "$2" ]; then - git clone --depth=1 "https://github.com/$1" - else - git clone --depth=1 "https://github.com/$1" "$2" - fi - } - gck() { - if [ -z "$2" ]; then - git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" - else - git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" "$2" - fi - } - gcs() { - if [ -z "$2" ]; then - git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1" - else - git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1" "$2" - fi - } - alias gd="git diff" - alias ga="gd $1 && git add" - alias gp="git pull --recurse-submodule" - alias gms='git maintenance start' - alias gsu="git submodule foreach git pull && git add . && git commit -m ' updated 📌submodules' && echo '-- Committed changes, pushing now..' && sleep 1 && git push" - alias gcm="git commit -m" - alias gpu="git push --recurse-submodule=on-demand" - if command_exists lazygit; then - alias lg="lazygit" - fi - fi - -} - -_coding_() { - # ─< h stands for HUGO >────────────────────────────────────────────────────────────────── - if command_exists hugo; then - alias h='hugo' - alias hs='if [ -d ./public ]; then; echo "found public folder, cleaning it.." && command rm -rf ./public && hugo server -D --noHTTPCache --disableFastRender; else; hugo server -D --noHTTPCache --disableFastRender; fi' # --bind "$(get_ip)"' - fi - - # ─< VSCodium >───────────────────────────────────────────────────────────────────────────── - if command_exists codium; then - alias code="codium" - export EDITOR="codium" - fi - - # ─< neovide, the best frontend for any neovim-config >─────────────────────────────────── - if command_exists nvim; then - alias cnvim="command nvim" - if command_exists neovide; then - alias nvim="neovide --fork" - fi - - if [ -d "$HOME/.config/nvchad" ]; then - alias nvchad='NVIM_APPNAME="nvchad" command nvim' - alias neochad='NVIM_APPNAME="nvchad" neovide --fork' - fi - fi - - # Function to get the IP address - get_ip() { - ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1 - } - - # Check if npm is available, then create the alias - if command_exists npm; then - 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 - npmrun_help - return - fi - - local env="$1" - local port="${2:-8080}" - - npm run "$env" -- --host="$(get_ip)" --port="$port" - - } - fi - - if command_exists bc; then - math() { - echo "$*" | bc -l - } - else - echo_error "No bc, so no math will work" - fi -} - -# ─< rsync >──────────────────────────────────────────────────────────────────────────────── -if command_exists rsync; then - alias scp="rsync -avP" - alias cp="scp" -fi - -get_packager() { - . /etc/os-release - case "$ID" in - # Debian-based - ubuntu | debian | pop | kali | zorin | rhinoh) - 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 - ;; - - # RHEL-based - fedora | centos) - alias search="dnf search" - alias install="$_sudo dnf install" - 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" - ;; - - # Alpine - alpine) - alias install="$_sudo apk add" - alias update="$_sudo apk update && $_sudo apk upgrade" - alias remove="$_sudo apk del" - ;; - esac -} - _environment() { if command_exists nvim; then export EDITOR="$(which nvim)" @@ -587,13 +148,6 @@ _environment() { [ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH" } -git_installs() { - if [ -e "$HOME/.zsh/.install.sh" ]; then - echo_info "Git installs activated by '_install '" - . "$HOME/.zsh/.install.sh" - fi -} - _end() { if command_exists fastfetch; then clear && @@ -609,11 +163,9 @@ _end() { } main() { - get_packager _init + _sources _environment - _coding_ - _alias git_installs _end }