addet clean zsh config

This commit is contained in:
pika 2024-08-20 21:04:18 +02:00
parent 35bc61756e
commit 19facff384
6 changed files with 241 additions and 290 deletions

279
.zshrc
View file

@ -1,47 +1,34 @@
# Source/Load zinit
source "$HOME/.config/zsh/upin-alias.zsh"
source "$HOME/.config/zsh/dependencies.zsh"
source "$HOME/.config/zsh/init.zsh"
source "$HOME/.config/zsh/roundy-theme.zsh"
#source "$HOME/.config/zsh/toolbox.zsh"
# ─< Helper functions >─────────────────────────────────────────────────────────────────
function echo_error() { echo -e "\033[0;1;31merror:\033[0;31m\t${*}\033[0m"; }
function echo_binfo() { echo -e "\033[0;1;34mInfo:\033[0;34m\t${*}\033[0m"; }
function echo_info() { echo -e "\033[0;35m${*}\033[0m"; }
# Set the directory we want to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# Download Zinit, if it's not there yet
if [ ! -d "$ZINIT_HOME" ]; then
mkdir -p "$(dirname $ZINIT_HOME)"
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
source "${ZINIT_HOME}/zinit.zsh"
# Add in zsh plugins
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light Aloxaf/fzf-tab
# Add in snippets
zinit snippet OMZP::git
zinit snippet OMZP::sudo
zinit snippet OMZP::archlinux
zinit snippet OMZP::aws
zinit snippet OMZP::docker-compose
zinit snippet OMZP::kubectl
zinit snippet OMZP::kubectx
zinit snippet OMZP::command-not-found
# 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_binfo "User 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."
return 1
fi
else
echo_binfo "Root access confirmed."
_sudo=""
fi
}
# Load completions
autoload -Uz compinit && compinit
zinit cdreplay -q
bindkey -e
# History
HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
@ -51,12 +38,228 @@ setopt hist_ignore_dups
setopt hist_find_no_dups
autoload -Uz select-word-style
select-word-style shell
# 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/pika/.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'
if command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
setopt autocd notify
# End of lines configured by zsh-newuser-install
_init (){
if command_exists oh-my-posh; then
# eval "$(oh-my-posh init zsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/amro.omp.json')"
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 '~/gitea/dotfiles/oh-my-posh/amro.toml')"
else
curl -s https://ohmyposh.dev/install.sh | sudo bash --norc -s -- -d /usr/bin/
fi
if command_exists zoxide; then
eval "$(zoxide init zsh)"
fi
}
_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"
# ─< telnet (starwars) >────────────────────────────────────────────────────────────────────
if command_exists telnet; then
alias starwars="telnet -a telehack.com"
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
tmux_y="-- tmux-session active! | connecting to active session --"
tmux_n="-- 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_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_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"
elif command_exists trash-cli; then
alias rm="trash-cli"
alias t="trash-cli"
else
echo_error "-- You do not have trash or trash-cli installed! Your 'rm' will be permanent! --"
fi
}
# ─< rsync >────────────────────────────────────────────────────────────────────────────────
_rsync_() {
_rrsync() {
if command_exists find; then
numbers=0
for source in "${@:1:$#-1}"; do
numbers=$(($numbers + $(find "$source" -type f | wc -l)))
done
destination="${@: -1}"
rsync -avP --info=progress2 "${@:1:$#-1}" "$destination" | pv -lpes $numbers
else
echo_error "-- We could not find 'find'. Please install 'find' to enable the progress bar. (hit 'CTRL + C' to exit now) --"
sleep 5
rsync -avP --info=progress2 "$@"
fi
}
if command_exists rsync; then
alias cp="_rrsync"
alias scp="rsync -avP"
fi
}
get_packager() {
search=""
install=""
update=""
upgrade=""
refresh=""
remove=""
. /etc/os-release
case "$ID" in
ubuntu | debian)
if command_exists nala; then
search="nala search"
install="nala install --assume-yes"
refresh="nala update"
upgrade="nala upgrade --full"
remove="nala purge"
clean="nala autoremove --assume-yes"
alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $remove"
alias search="$search"
elif command_exists apt-get; then
search="apt-cache search"
install="apt-get install --yes"
refresh="apt-get update"
upgrade="apt-get upgrade"
remove="apt-get purge"
clean="apt-get autoremove"
alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $remove"
alias search="$search"
fi
;;
arch | manjaro | endevouros)
if command_exists yay; then
alias install="yay -S --noconfirm"
alias update="yay -Syu"
alias remove="yay -R"
alias search="yay -Ss"
elif command_exists paru; then
alias install="paru -S --noconfirm"
alias update="paru -Syu"
alias remove="paru -R"
alias search="paru -Ss"
elif command_exists pacman; then
alias install="$_sudo pacman -S --noconfirm"
alias update="$_sudo pacman -Syu"
alias remove="$_sudo pacman -R"
alias search="$_sudo pacman -Ss"
fi
;;
fedora | centos)
alias install="dnf install --yes"
alias update="dnf update"
alias remove="dnf remove"
alias search="dnf search"
;;
alpine)
install="apk add"
update="apk update"
upgrade="apk upgrade"
remove="apk del"
alias install="$_sudo $install"
alias update="$_sudo $update && $_sudo $upgrade"
alias remove="$_sudo $remove"
;;
esac
}
main(){
get_packager
_init
_alias
_rsync_
}
if check_root; then
main
fi
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

View file

@ -1 +0,0 @@
#!/usr/bin/zsh

112
init.zsh
View file

@ -1,112 +0,0 @@
#!/bin/zsh
# Initial file for zsh
# sudo/please
alias please='sudo'
# Aliases
alias vim='nvim'
alias c='clear'
#colored everything
alias ip="ip -c"
#ripgrep
if command -v rg >/dev/null 2>&1; then
alias grep="rg --color=always"
else
alias grep="grep --color=always"
fi
#weather
alias www='curl wttr.in/Ulm'
# ls alias
if command -v lsd >/dev/null 2>&1; then
alias ls='lsd --icon always'
alias ll='lsd --icon always -lA'
alias l='lsd --icon always -l'
LS="lsd"
elif command -v exa >/dev/null 2>&1; then
alias ls='exa --icons=always'
alias ll='exa --icons=always -lA'
alias l='exa --icons=always -l'
LS="exa"
elif command -v eza >/dev/null 2>&1; then
alias ls='eza --icons=always'
alias ll='eza --icons=always -lA'
alias l='eza --icons=always -l'
LS="eza"
else
alias ls='ls --color=always -lph'
alias ll='ls --color=always -lAph'
alias l='ls --color=always -l'
fi
# pfetch alias
if command -v fastfetch >/dev/null 2>&1; then
alias ff='fastfetch'
alias fetch='fastfetch'
alias f='fastfetch --config examples/8'
alias clear='command clear && f'
alias clearl='command clear && f && l && pwd'
elif command -v pfetch >/dev/null 2>&1; then
alias p='pfetch'
alias clear='command clear && pfetch'
alias clearl='command clear && p && l && pwd'
else
function iff {
echo "$ZSH_UPDATE fastfetch" | zsh
}
iff
fi
# git alias
if command -v git >/dev/null 2>&1; then
alias g='git'
alias gc='git clone'
alias gs='git status'
alias ga='git add'
alias gcm='git commit'
alias gp='git pull'
fi
# docker alias
if command -v docker >/dev/null 2>&1; then
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 ds='docker ps -a'
alias dc='docker compose'
alias db='docker build'
alias appupdate='docker pull && docker compose up -d --force-recreate'
fi
# z stands for zoxide
if command -v zoxide >/dev/null 2>&1; then
alias z='cd'
eval "$(zoxide init --cmd cd zsh)"
if command -v fzf >/dev/null 2>&1; then
# Shell integrations
eval "$(fzf --zsh)"
else
function ifzf {
echo "$ZSH_UPDATE fastfetch" | zsh
exec zsh
}
ifzf
fi
fi
# rsync alias
if command -v rsync >/dev/null 2>&1; then
alias cp='rsync -avP'
alias scp='rsync -avP'
fi
# tmux alias
if command -v tmux >/dev/null 2>&1; then
alias ts="tmux source $HOME/.tmux.conf"
alias ta="tmux a"
alias t="tmux"
fi

View file

@ -1,29 +0,0 @@
# Icon definition for Command's Exit Status
# Note: If your custom symbol overlaps the background or didn't have enough width,
# you can add space at the end of your defined symbol.
ROUNDY_EXITSTATUS_OK="●"
# You can also using hex code like this
ROUNDY_EXITSTATUS_NO="✖"
# Icon definition for Time Execution
ROUNDY_TEXC_ICON="▲"
# ROUNDY_TEXC_ICON=""
# Minimal time (in ms) for the Time Execution of Command is displayed in prompt
# Set to 0 to disable it
ROUNDY_TEXC_MIN_MS=5
# Overriding username info
ROUNDY_USER_CONTENT_NORMAL=" %n "
ROUNDY_USER_CONTENT_ROOT=" %n "
# Working Directory Info Mode
# Valid choice are : "full", "short", or "dir-only"
# Example Output
# full : /etc/httpd/conf/extra
# short : /e/h/c/extra
# dir-only : extra
ROUNDY_DIR_MODE="dir-only"
# Whether drawing a gap between a prompt
ROUNDY_PROMPT_HAS_GAP=true

View file

@ -1,22 +0,0 @@
#!/bin/zsh
# variables
toolbox_on="The following tools are installed:
"
toolbox_off="The following tools are NOT installed:
"
# various tools/cmdlets to check for
tools=("nvim" "tmux" "git" "zoxide" "docker" "fzf" "distrobox")
for tool in "$tools[@]" do
if command -v "$tool" >/dev/null 2>&1; then
toolbox_on="$toolbox_on
$tool"
else
toolbox_off="$toolbox_off
$tool"
fi
done
TOOLBOX="$toolbox_on
$toolbox_off"

View file

@ -1,88 +0,0 @@
#!/usr/bin/zsh
# check for sudo
if [ "$USER" != "root" ]; then
sudo="sudo"
else
sudo=""
fi
# APT/NALA - Debian
if command -v nala >/dev/null 2>&1; then
pkg="$sudo nala"
install="$pkg update && $pkg install"
remove="$pkg prune"
update="$pkg update && $pkg upgrade"
ref="$pkg update --assume-yes"
search="$pkg search"
elif command -v apt-get >/dev/null 2>&1; then
pkg="$sudo apt-get"
install="$pkg update && $pkg install"
remove="$pkg remove"
update="$pkg update && $pkg upgrade"
ref="$pkg update --assume-yes"
search="$pkg search"
fi
# DNF - Fedora
if command -v dnf >/dev/null 2>&1; then
pkg="$sudo dnf"
install="$pkg install"
remove="$pkg remove"
update="$pkg update"
ref="$update"
search="$pkg search"
fi
# Pacman - Arch
if command -v paru >/dev/null 2>&1; then
pkg="paru"
install="$pkg -S"
remove="$pkg -R"
update="$pkg -Syu"
ref="$pkg -S --noconfirm"
search="$pkg -Ss"
elif command -v yay >/dev/null 2>&1; then
pkg="yay"
install="$pkg -S"
remove="$pkg -R"
update="$pkg -Syu"
ref="$pkg -Sy --noconfirm"
search="$pkg -Ss"
elif command -v pacman >/dev/null 2>&1; then
pkg="$sudo pacman"
install="$pkg -S"
remove="$pkg -R"
update="$pkg -Syu"
ref="$pkg -Sy --needet --noconfirm"
search="$pkg -Ss"
fi
# Zypper - OpenSuse
if command -v zypper >/dev/null 2>&1; then
pkg="$sudo zypper"
install="$pkg install"
remove="$pkg remove"
update="$pkg dup"
ref="$pkg refresh"
search="$pkg search"
fi
# APK - Alpine
if command -v apk >/dev/null 2>&1; then
pkg="$sudo apk"
install="$pkg add"
update="$pkg upgrade"
ref="$pkg update"
search="$pkg search"
fi
ZSH_INSTALL="$install"
ZSH_UPDATE="$ref"
alias install="$install"
alias update="$update"
alias remove="$remove"
alias refresh="$ref"
alias search="$search"