From: Ruben Beltran del Rio Date: Mon, 29 Jan 2024 16:41:49 +0000 (+0000) Subject: Merge branch 'main' of git.sr.ht:~rbdr/dotfiles X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/commitdiff_plain/9f9934bad16668fcf0a768cdaa03383d73780e15?hp=44d3b9991efdf49979ec18a676be26c54a0b737e Merge branch 'main' of git.sr.ht:~rbdr/dotfiles --- diff --git a/runcoms/zshrc b/runcoms/zshrc index 3b61e08..07d4269 100644 --- a/runcoms/zshrc +++ b/runcoms/zshrc @@ -6,6 +6,7 @@ source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/graphviz.zsh" source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/short-uptime.zsh" source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/figlet-sample.zsh" source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/prettify-json.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/status.zsh" ################################################################################ # Load Modules @@ -23,23 +24,17 @@ source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/aliases.zsh" # ENV VARIABLES ################################################################################ # Terminal related -export TERM=xterm-256color-italic +export TERM=xterm-256color # Paths # export JAVA_HOME=$(/usr/libexec/java_home) # Enable if using JDK, otherwise disable for performance export XDG_CONFIG_HOME=$HOME/.config -export GOPATH=$HOME/Projects/go +export GOPATH=$HOME/projects/go export ANDROID_HOME=$HOME/Library/Android/sdk export ANDROID_NDK_HOME=$HOME/Library/Android/sdk/ndk-bundle -export NVM_DIR=$HOME/.nvm export PATH=$PATH:$HOME:${GOPATH//://bin:}/bin export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_NDK_HOME:/Applications/calibre.app/Contents/MacOS -# Python related variables -export VIRTUAL_ENV_DISABLE_PROMPT=1 -export WORKON_HOME=$HOME/.virtualenvs -export PROJECT_HOME=$HOME/Documents/projects - # GPG export GPG_TTY=$(tty) @@ -50,15 +45,6 @@ export GPG_TTY=$(tty) export FZF_DEFAULT_COMMAND='/usr/bin/env rg --color never --files --hidden -g \!.git' export FZF_DEFAULT_OPTS='--preview ''bat --style=numbers --color=always {} | head -500''' -if [[ -s "/opt/homebrew/bin/brew" ]]; then - export FZF_VIM_PATH=/opt/homebrew/opt/fzf -else - if [[ -s "/usr/local/bin/brew" ]]; then - export FZF_VIM_PATH=/usr/local/opt/fzf - else - export FZF_VIM_PATH=/usr/share/doc/fzf/examples - fi -fi ################################################################################ # SECRET ENV VARS!! @@ -75,13 +61,20 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zshrc.local" ]]; then fi if [[ -s "/opt/homebrew/bin/brew" ]]; then + # Brew Setup export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH -fi - -# Z -if [[ -s "/opt/homebrew/bin/brew" ]]; then + export FZF_VIM_PATH=/opt/homebrew/opt/fzf . /opt/homebrew/etc/profile.d/z.sh + . /opt/homebrew/opt/asdf/libexec/asdf.sh else + # FZF Vim (Linux) + if [[ -s "/usr/local/bin/brew" ]]; then + export FZF_VIM_PATH=/usr/local/opt/fzf + else + export FZF_VIM_PATH=/usr/share/doc/fzf/examples + fi + + # Z (Linux) if [[ -s "/usr/libexec/z.sh" ]]; then . /usr/libexec/z.sh else @@ -91,19 +84,16 @@ else . /usr/local/etc/profile.d/z.sh fi fi -fi -# ASDF -if ! command -v brew &> /dev/null; then + # ASDF (Linux) if [[ -s "/opt/asdf-vm/asdf.sh" ]]; then . /opt/asdf-vm/asdf.sh else . $HOME/.asdf/asdf.sh fi -else - . $(brew --prefix asdf)/libexec/asdf.sh fi +# ASDF Java if [[ -s "~/.asdf/plugins/java/set-java-home.zsh" ]]; then . ~/.asdf/plugins/java/set-java-home.zsh fi diff --git a/zsh/functions/status.zsh b/zsh/functions/status.zsh new file mode 100644 index 0000000..3da8977 --- /dev/null +++ b/zsh/functions/status.zsh @@ -0,0 +1,61 @@ +function tool_versions() { + if [[ -s ".tool-versions" ]]; then + echo '.tool-versions' + return + fi + echo "${HOME}/.tool-versions" +} + +function env_info_provider() { echo "%{%F{green}%}n/a"; } +function env_info { + echo "[%{%F{cyan}%}ENV%{%F{black}%} $(env_info_provider)%{%F{black}%}]" +} + +function python_info { + pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2` + pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo} + venv="${VIRTUAL_ENV##*/}" + echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}" +} + +function rust_info { + rustinfo=`cat "$(tool_versions)" | rg rust | cut -d ' ' -f 2` + rustinfo=${ASDF_RUST_VERSION:-$rustinfo} + echo "%{%F{red}%}rs%{%F{black}%} ${rustinfo:-no}" +} + +function node_info { + nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2` + nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo} + echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}" +} + +function git_info { + branch=$(git branch --show-current 2> /dev/null) + + if [ ! -z $branch ]; then + echo -n "@%F{cyan}$branch%f" + + status_output=$(git status --short) + + if echo "$status_output" | rg -q '^??'; then + echo -n "%{%F{magenta}%}?%f" + fi + + if echo "$status_output" | rg -q '^ M'; then + echo -n "%{%F{magenta}%}!%f" + fi + + if echo "$status_output" | rg -q '^ D'; then + echo -n "%{%F{magenta}%}×%f" + fi + + if echo "$status_output" | rg -q '^A '; then + echo -n "%{%F{green}%}+%f" + fi + fi +} + +function status { + print -P '%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)' +} diff --git a/zsh/modules/aliases.zsh b/zsh/modules/aliases.zsh index 2037e9e..0ff13f2 100644 --- a/zsh/modules/aliases.zsh +++ b/zsh/modules/aliases.zsh @@ -27,17 +27,5 @@ alias gl="git pull" alias gm='git merge' alias gp='git push' -# Graphicsmagick override -if command -v brew &> /dev/null; then - alias grm="$(brew --prefix)/bin/gm" -fi - # JS friendly tree alias arbol="tree -I 'node_modules|bower_components|doc|__pycache__|\.pyc'" - -# Load Script Version Managers because they slow -alias enable-nvm='source $(brew --prefix nvm)/nvm.sh' -alias workon="echo 'DISABLED: run enable-virtualenvwrapper to enable'" -alias enable-virtualenvwrapper="unalias workon; source /usr/local/bin/virtualenvwrapper.sh" -alias enable-rvm="source $HOME/.rvm/scripts/rvm" -alias t="things.sh" diff --git a/zsh/modules/prompt.zsh b/zsh/modules/prompt.zsh index 18e5cc4..615ca95 100644 --- a/zsh/modules/prompt.zsh +++ b/zsh/modules/prompt.zsh @@ -1,75 +1,9 @@ autoload -Uz promptinit && promptinit -function tool_versions() { - if [[ -s ".tool-versions" ]]; then - echo '.tool-versions' - return - fi - echo "${HOME}/.tool-versions" -} - if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then prompt 'off' fi -# -# Functions -# - -function env_info_provider() { echo "%{%F{green}%}n/a"; } -function env_info { - echo "[%{%F{cyan}%}ENV%{%F{black}%} $(env_info_provider)%{%F{black}%}]" -} - -function python_info { - pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2` - pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo} - venv="${VIRTUAL_ENV##*/}" - echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}" -} - -function rust_info { - rustinfo=`cat "$(tool_versions)" | rg rust | cut -d ' ' -f 2` - rustinfo=${ASDF_RUST_VERSION:-$rustinfo} - echo "%{%F{red}%}rs%{%F{black}%} ${rustinfo:-no}" -} - -function node_info { - nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2` - nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo} - echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}" -} - -function git_info { - branch=$(git branch --show-current 2> /dev/null) - - if [ ! -z $branch ]; then - echo -n "@%F{cyan}$branch%f" - - status_output=$(git status --short) - - if echo "$status_output" | grep -q '^??'; then - echo -n "%{%F{magenta}%}?%f" - fi - - if echo "$status_output" | grep -q '^ M'; then - echo -n "%{%F{magenta}%}!%f" - fi - - if echo "$status_output" | grep -q '^ D'; then - echo -n "%{%F{magenta}%}×%f" - fi - - if echo "$status_output" | grep -q '^A '; then - echo -n "%{%F{green}%}+%f" - fi - fi -} - -function box_name { - [ -f ~/.box-name ] && cat ~/.box-name || hostname -s -} - # # ZLE widgets # @@ -113,7 +47,7 @@ function prompt_setup { # Define prompts. PROMPT=' %{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info) -%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%} +%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(hostname -s)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%} %(?,,%{${%B%F{white}%}[%?]%{%f%b%} )%% ' }