1
0

reworking zsh

This commit is contained in:
brenozd
2025-01-10 19:22:58 -03:00
parent 529efbee4d
commit 039db34350
4 changed files with 70 additions and 68 deletions

49
.zshrc
View File

@@ -1,14 +1,3 @@
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
# if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
# source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
# fi
# [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# ZSH_THEME="gozilla"
# ZSH_THEME="powerlevel10k/powerlevel10k"
ZSH_THEME=""
export ZSH="$HOME/.oh-my-zsh"
@@ -16,8 +5,8 @@ export ZSH="$HOME/.oh-my-zsh"
source "$HOME/.config/zsh/utilities.sh"
# Path
path_add "$HOME/.local/bin"
path_add "$HOME/.local/go/bin"
_path_add "$HOME/.local/bin"
_path_add "$HOME/.local/go/bin"
# Initializing plugins
plugins=(
@@ -33,6 +22,7 @@ plugins=(
virtualenv
)
# Completion setup
source $ZSH/oh-my-zsh.sh
autoload -Uz compinit
compinit -i -u
@@ -44,41 +34,22 @@ zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
zstyle ':completion:*' menu select
source <(kubectl completion zsh)
# FZF Setup
export FZF_DEFAULT_OPTS="--cycle --no-sort --reverse --border=rounded --header-first --prompt='󰍉 ' --pointer='' --marker='󰆤 '"
bindkey '\t' menu-select "$terminfo[kcbt]" menu-select
bindkey -M menuselect '\t' menu-complete "$terminfo[kcbt]" reverse-menu-complete
source "$HOME/.config/zsh/aliases.sh"
source "$HOME/.config/zsh/aws.sh"
# Generated for envman. Do not edit.
[ -s "$HOME/.config/envman/load.sh" ] && source "$HOME/.config/envman/load.sh"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/brenozd/.miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/brenozd/.miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/brenozd/.miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/brenozd/.miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
#
# Initialize toolbox env
source "$HOME/.config/zsh/toolbox.sh"
container=${container:-""}
if [ "$container" = "oci" ]; then
toolbox_entrypoint
_toolbox_entrypoint
else
alias docker="podman"
export GOPATH="$HOME/.local/"
fi
export GOPATH="$HOME/.local/"
# Pure theme setup
fpath+=($HOME/.zsh/pure)
autoload -U promptinit; promptinit
zstyle :prompt:pure:path color '#eeeeee'
@@ -89,3 +60,9 @@ prompt pure
# https://github.com/sindresorhus/pure/issues/545#issuecomment-706630230
export CONDA_DEFAULT_ENV=""
# Load cargo
. "$HOME/.cargo/env"
source "$HOME/.config/zsh/aliases.sh"
source "$HOME/.config/zsh/aws.sh"

View File

@@ -5,10 +5,10 @@ alias findtext="rg --smart-case --field-match-separator ' ' --line-number --with
alias ff=findfiles
alias ft=findtext
alias cd="z"
alias ls="eza --icons"
alias ll="eza -lah --icons"
alias ls="eza --icons auto"
alias ll="eza -lah --icons auto"
alias cat="bat"
alias tree="eza -Tah --icons"
alias tree="eza -Tah --icons auto"
alias vim="nvim"
alias man="batman"
alias clc="clipcopy"

View File

@@ -4,50 +4,76 @@
TOOLBOXES_DIR="$HOME/.toolboxes"
get_container_id() {
_get_container_id() {
_ret_var=${1:-"CONTAINER_ID"}
_container_id=$(grep '^id=' /run/.containerenv | sed -e 's/^id="\(.*\)"$/\1/')
eval "$_ret_var='$_container_id'"
}
get_container_name() {
_get_container_name() {
_ret_var=${1:-"CONTAINER_NAME"}
_container_name=$(grep '^name=' /run/.containerenv | sed -e 's/^id="\(.*\)"$/\1/')
_container_name=$(grep '^name=' /run/.containerenv | sed -e 's/^name="\(.*\)"$/\1/')
eval "$_ret_var='$_container_name'"
}
toolbox_entrypoint() {
get_container_id "CONTAINER_ID"
get_container_name "CONTAINER_NAME"
_setup_toolbox_sysroot() {
mkdir -p "$_env_location"/bin
mkdir -p "$_env_location"/lib
_env_location="$TOOLBOXES_DIR/$CONTAINER_ID"
if [ ! -d "$_env_location" ]; then
conda create --prefix "$_env_location" --yes >/dev/null 2>&1
mkdir -p "$_env_location"/bin
mkdir -p "$_env_location"/lib
# Setup podman to use host engine
ln -sf "$(which podman-remote)" "$_env_location"/bin/podman
ln -sf "$(which podman-remote)" "$_env_location"/bin/docker
# Setup podman to use host engine
ln -sf "$(which podman-remote)" "$_env_location"/bin/podman
ln -sf "$(which podman-remote)" "$_env_location"/bin/docker
fi
# Setup python venv
virtualenv "$SYSROOT"
podman-remote system connection add "$USER" unix:///run/user/"$(id -u)"/podman/podman.sock
}
conda activate "$_env_location" --no-stack
_toolbox_entrypoint() {
_get_container_id "CONTAINER_ID"
_get_container_name "CONTAINER_NAME"
_env_location="$TOOLBOXES_DIR/$CONTAINER_NAME"
# Setup environment variables to use container env
SYSROOT="$_env_location"
BIN="$_env_location/bin"
LIB="$_env_location/lib"
PYTHONHOME="$SYSROOT"
path_add "$BIN"
library_path_add "$LIB"
if [ ! -d "$_env_location" ]; then
_setup_toolbox_sysroot
fi
podman-remote system connection add "$USER" unix:///run/user/"$(id -u)"/podman/podman.sock
# Activating venv
# Do not need to manually add path, virtualenv does it for us
# _path_add "$BIN"
_library_path_add "$LIB"
. "$SYSROOT/bin/activate"
# Setup GOPATH
export GOPATH="$SYSROOT"
}
toolbox_exitpoint() {
_toolbox_exitpoint() {
[ -n "${SYSROOT+x}" ] && unset ROOT
[ -n "${BIN+x}" ] && unset BIN
[ -n "${LIB+x}" ] && unset LIB
[ -n "${PYTHONHOME+x}" ] && unset PYTHONHOME
}
change_python_version() {
_version=${1:?"change_python_version requires a version"}
# Check if the desired Python version is installed
if ! rpm -q "python$_version" &>/dev/null; then
# Install the requested Python version if not installed
echo "Python $_version not found. Installing..."
sudo dnf install -y "python$_version" "python$_version-devel"
else
echo "Python $_version is already installed."
fi
# Create the virtual environment with the specified Python version
virtualenv --clear --python "$(which "python$_version")" "$SYSROOT"
}

View File

@@ -1,6 +1,6 @@
#!/bin/sh
path_add() {
_path_add() {
case ":${PATH:=$1}:" in
*:"$1":*)
;;
@@ -10,7 +10,7 @@ path_add() {
esac;
}
library_path_add() {
_library_path_add() {
case ":${LD_LIBRARY_PATH:=$1}:" in
*:"$1":*)
;;
@@ -20,7 +20,7 @@ library_path_add() {
esac;
}
path_remove() {
_path_remove() {
path_to_remove=$1
new_path=""
@@ -43,7 +43,7 @@ path_remove() {
PATH="$new_path"
}
library_path_remove() {
_library_path_remove() {
path_to_remove=$1
new_path=""
@@ -66,9 +66,8 @@ library_path_remove() {
LD_LIBRARY_PATH="$new_path"
}
open() {
_folder=${1:-$PWD}
xdg-open "$_folder"
_path=${1:-$PWD}
xdg-open "$_path"
}