addet nixos configs

This commit is contained in:
pika 2025-04-04 17:55:16 +02:00
parent c37909dd17
commit f7e6544885

254
.zshrc
View file

@ -2,6 +2,7 @@
command_exists() {
command -v "$@" >/dev/null 2>&1
}
#
# Check if the user is root and set sudo variable if necessary
check_root() {
@ -146,20 +147,145 @@ __get_Packager__() {
alias update="$_sudo apk update && $_sudo apk upgrade"
alias remove="$_sudo apk del"
;;
*)
if command_exists nix-env; then
*nixos*)
echo_info "Using NIX!!"
alias update="$_sudo nixos-rebuild switch"
alias install="$_sudo nix-env -iA"
# alias install="$_sudo nix-env -iA nixos."
install() {
"$_sudo nix-end -iA nixos.$@"
}
alias edit="$_sudo -E $EDITOR /etc/nixos/configuration.nix"
else
;;
*)
echo_error "Unsupported distro: $ID"
return 1
fi
;;
esac
}
__docker__() {
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"
}
__git__() {
# ─< lazygit >────────────────────────────────────────────────────────────────────────────
if command_exists lazygit; then
alias lg="lazygit"
fi
# ───────────────────────────────────────< aliases >─────────────────────────────────────
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"
alias gd="git diff"
alias ga="gd $1 && git add"
alias gp='echo "${CYAN}Updating submodules..${NC}" && git submodule update --init --recursive && echo "${CYAN}Pulling down submodules..${NC}" && git pull --recurse-submodule'
alias gms='git maintenance start'
alias gcm="git commit -m"
alias gpu="git push --recurse-submodule=on-demand"
# ──────────────────────────────────────< functions >────────────────────────────────────
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
}
gsu() {
echo "${CYAN}Updating submodules recursively with -> ${YELLOW}${BOLD}git submodule update --init --recursive${NC}"
git submodule update --init --recursive &&
echo "${CYAN}${BOLD}-- Updated submodules recursively --${NC}"
echo "${CYAN}${BOLD}-- Checking submodule branches... --${NC}"
git submodule foreach '
branch=$(git symbolic-ref --short HEAD 2>/dev/null || echo "detached")
if [ "$branch" = "detached" ]; then
default_branch=$(git config -f $toplevel/.gitmodules submodule.$name.branch || echo "main")
echo "${RED}${BOLD}Submodule $name is detached. Checking out ${YELLOW} $default_branch${RED}...${NC}"
git checkout $default_branch
else
echo "${GREEN}${BOLD}Submodule $name is on branch $branch.${NC}"
fi
'
echo "${CYAN}Pulling down updates recursively with -> ${YELLOW}${BOLD}git submodule foreach git pull --recurse-submodule${NC}"
git submodule foreach git pull --recurse-submodule &&
echo "${GREEN}${BOLD}-- pulled down submodules recursively --${NC}"
gUpdateModules() {
if ! git diff --exit-code .; then
echo "${CYAN}${BOLD}Staging changes...${NC}"
git add . || echo "GIT ADD MISSFUNCTION"
sleep 0.3
if git commit -m " update: submodules"; then
echo "${GREEN}${BOLD}commit message ${RED}' update: submodules'${GREEN} successfully commited${NC}"
else
echo "${RED}${BOLD}Failed to commit changes.${NC}"
return 1
fi
else
echo "${GREEN}${BOLD}No changes to commit.${NC}"
return 1
fi
}
if gUpdateModules; then
if git push; then
echo "${GREEN}${BOLD}Push successful.${NC}"
else
echo "${RED}${BOLD}Failed to push changes.${NC}"
return 1
fi
fi
}
gwip() {
# Fetch the latest changes from the remote
git fetch
# Get the current branch name
local branch
branch=$(git rev-parse --abbrev-ref HEAD)
# Check if there are any changes on the remote branch
if git diff --quiet "$branch" "origin/$branch"; then
local commit_message="${1:-wip}"
echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
git add .
git commit -m "$commit_message"
git push
else
echo "${RED}${BOLD}There are changes on the remote branch. Please pull the latest changes first.${NC}"
fi
}
}
__alias__() {
__get_Packager__
@ -313,124 +439,12 @@ __alias__() {
# ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command_exists docker; 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 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"
__docker__
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='echo "${CYAN}Updating submodules..${NC}" && git submodule update --init --recursive && echo "${CYAN}Pulling down submodules..${NC}" && git pull --recurse-submodule'
alias gms='git maintenance start'
alias gcm="git commit -m"
alias gpu="git push --recurse-submodule=on-demand"
gsu() {
echo "${CYAN}Updating submodules recursively with -> ${YELLOW}${BOLD}git submodule update --init --recursive${NC}"
git submodule update --init --recursive &&
echo "${CYAN}${BOLD}-- Updated submodules recursively --${NC}"
echo "${CYAN}${BOLD}-- Checking submodule branches... --${NC}"
git submodule foreach '
branch=$(git symbolic-ref --short HEAD 2>/dev/null || echo "detached")
if [ "$branch" = "detached" ]; then
default_branch=$(git config -f $toplevel/.gitmodules submodule.$name.branch || echo "main")
echo "${RED}${BOLD}Submodule $name is detached. Checking out ${YELLOW} $default_branch${RED}...${NC}"
git checkout $default_branch
else
echo "${GREEN}${BOLD}Submodule $name is on branch $branch.${NC}"
fi
'
echo "${CYAN}Pulling down updates recursively with -> ${YELLOW}${BOLD}git submodule foreach git pull --recurse-submodule${NC}"
git submodule foreach git pull --recurse-submodule &&
echo "${GREEN}${BOLD}-- pulled down submodules recursively --${NC}"
gUpdateModules() {
if ! git diff --exit-code .; then
echo "${CYAN}${BOLD}Staging changes...${NC}"
git add . || echo "GIT ADD MISSFUNCTION"
sleep 0.3
if git commit -m " update: submodules"; then
echo "${GREEN}${BOLD}commit message ${RED}' update: submodules'${GREEN} successfully commited${NC}"
else
echo "${RED}${BOLD}Failed to commit changes.${NC}"
return 1
fi
else
echo "${GREEN}${BOLD}No changes to commit.${NC}"
return 1
fi
}
if gUpdateModules; then
if git push; then
echo "${GREEN}${BOLD}Push successful.${NC}"
else
echo "${RED}${BOLD}Failed to push changes.${NC}"
return 1
fi
fi
}
gwip() {
# Fetch the latest changes from the remote
git fetch
# Get the current branch name
local branch
branch=$(git rev-parse --abbrev-ref HEAD)
# Check if there are any changes on the remote branch
if git diff --quiet "$branch" "origin/$branch"; then
local commit_message="${1:-wip}"
echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
git add .
git commit -m "$commit_message"
git push
else
echo "${RED}${BOLD}There are changes on the remote branch. Please pull the latest changes first.${NC}"
fi
}
if command_exists lazygit; then
alias lg="lazygit"
fi
__git__
fi
# ─< install lazydocker >─────────────────────────────────────────────────────────────────