chore(zsh): cleanup some of the config

This commit is contained in:
Afonso Franco 2025-06-16 09:24:03 +01:00
parent dacffcdc35
commit ebe7a7effb
Signed by: afonso
SSH key fingerprint: SHA256:gkVPzsQQJzqi21ntQBV6pXTx4bYI53rFGI4XtvCpwd4
9 changed files with 15 additions and 571 deletions

View file

@ -30,16 +30,16 @@ function append_path() {
eval export $1="$p:$2"
}
export EDITOR=nvim
export VISUAL=nvim
export READER=mupdf
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_STATE_HOME="${HOME}/.local/state"
export XDG_RUNTIME_DIR=/tmp
export EDITOR=nvim
export VISUAL=nvim
export READER=mupdf
export GOPATH="$HOME/go"
export GOBIN="$GOPATH/bin"
@ -47,12 +47,13 @@ export GOBIN="$GOPATH/bin"
if [[ $(uname) == "Darwin" ]]; then
export JAVA_HOME=$(/usr/libexec/java_home)
export GEM_HOME=$HOME/.gem
export GOROOT=$(brew --prefix golang)/libexec
prepend_path PATH "/opt/homebrew/bin"
prepend_path PATH "/opt/homebrew/opt/texlive/bin"
append_path PATH $GEM_HOME/bin
fi
#BOTH
# Common Paths
append_path PATH "/usr/sbin:/sbin"
append_path PATH "$HOME/.local/share/nvim/mason/bin"
append_path PATH "$HOME/.local/bin"

View file

@ -1,12 +1,18 @@
if [[ -o interactive ]]; then
if [[ -z "$TMUX" ]]; then
tmux new-session -A -s 0
fi
fi
source $ZDOTDIR/setup-history.zsh
source $ZDOTDIR/prompts/simple-two-line.zsh
source $ZDOTDIR/functions.zsh
source $ZDOTDIR/plugins.zsh
source $ZDOTDIR/theme.zsh
if [[ $(uname) == "Darwin" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
eval "$(atuin init zsh --disable-up-arrow)"

View file

@ -11,11 +11,8 @@ source $ZDOTDIR/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
source $ZDOTDIR/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
# Fzf-Tab
zvm_after_init_commands+=('source <(fzf --zsh) && enable-fzf-tab')
source $ZDOTDIR/plugins/fzf-tab/fzf-tab.plugin.zsh
# Vi mode
source $ZDOTDIR/plugins/zsh-vi-mode/zsh-vi-mode.plugin.zsh
enable-fzf-tab
# MacOS
source $ZDOTDIR/plugins/zsh-macos.plugin.zsh

View file

@ -1,258 +0,0 @@
# Git version checking
autoload -Uz is-at-least
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
#
# Functions Current
# (sorted alphabetically by function name)
# (order should follow README)
#
# The name of the current branch
# Back-compatibility wrapper for when this function was defined here in
# the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
# to fix the core -> git plugin dependency.
function current_branch() {
git_current_branch
}
# Check for develop and similarly named branches
function git_develop_branch() {
command git rev-parse --git-dir &>/dev/null || return
local branch
for branch in dev devel develop development; do
if command git show-ref -q --verify refs/heads/$branch; then
echo $branch
return 0
fi
done
echo develop
return 1
}
# Check if main exists and use instead of master
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return 0
fi
done
# If no main branch was found, fall back to master but return error
echo master
return 1
}
function grename() {
if [[ -z "$1" || -z "$2" ]]; then
echo "Usage: $0 old_branch new_branch"
return 1
fi
# Rename branch locally
git branch -m "$1" "$2"
# Rename branch in origin remote
if git push origin :"$1"; then
git push --set-upstream origin "$2"
fi
}
#
# Functions Work in Progress (WIP)
# (sorted alphabetically by function name)
# (order should follow README)
#
# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
function gunwipall() {
local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
# Check if a commit without "--wip--" was found and it's not the same as HEAD
if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
git reset $_commit || return 1
fi
}
# Warn if the current branch is a WIP
function work_in_progress() {
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
}
#
# Aliases
# (sorted alphabetically by command)
# (order should follow README)
# (in some cases force the alisas order to match README, like for example gke and gk)
#
alias grt='cd "$(git rev-parse --show-toplevel || echo .)"'
function ggpnp() {
if [[ "$#" == 0 ]]; then
ggl && ggp
else
ggl "${*}" && ggp "${*}"
fi
}
compdef _git ggpnp=git-checkout
alias ggpur='ggu'
alias g='git'
alias gaa='git add --all'
alias gb='git branch'
alias gbd='git branch --delete'
function gbda() {
git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null
}
# Copied and modified from James Roeder (jmaroeder) under MIT License
# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish
function gbds() {
local default_branch=$(git_main_branch)
(( ! $? )) || default_branch=$(git_develop_branch)
git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch; do
local merge_base=$(git merge-base $default_branch $branch)
if [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) = -* ]]; then
git branch -D $branch
fi
done
}
alias gcb='git checkout -b'
alias gcm='git checkout $(git_main_branch)'
alias gcl='git clone --recurse-submodules'
function gccd() {
setopt localoptions extendedglob
# get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS
local repo="${${@[(r)(ssh://*|git://*|ftp(s)#://*|http(s)#://*|*@*)(.git/#)#]}:-$_}"
# clone repository and exit if it fails
command git clone --recurse-submodules "$@" || return
# if last arg passed was a directory, that's where the repo was cloned
# otherwise parse the repo URI and use the last part as the directory
[[ -d "$_" ]] && cd "$_" || cd "${${repo:t}%.git/#}"
}
compdef _git gccd=git-clone
alias gcam='git commit --all --message'
alias gd='git diff'
function gdv() { git diff -w "$@" | view - }
compdef _git gdv=git-diff
alias gdup='git diff @{upstream}'
function gdnolock() {
git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock"
}
compdef _git gdnolock=git-diff
alias gf='git fetch'
alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
# Pretty log messages
function _git_log_prettily(){
if ! [ -z $1 ]; then
git log --pretty=$1
fi
}
compdef _git _git_log_prettily=git-log
alias gm='git merge'
alias gma='git merge --abort'
alias gl='git pull'
function ggu() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git pull --rebase origin "${b:=$1}"
}
compdef _git ggu=git-checkout
alias ggpull='git pull origin "$(git_current_branch)"'
function ggl() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git pull origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git pull origin "${b:=$1}"
fi
}
compdef _git ggl=git-checkout
alias gp='git push'
function ggf() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force origin "${b:=$1}"
}
compdef _git ggf=git-checkout
alias gpf!='git push --force'
is-at-least 2.30 "$git_version" \
&& alias gpf='git push --force-with-lease --force-if-includes' \
|| alias gpf='git push --force-with-lease'
function ggfl() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force-with-lease origin "${b:=$1}"
}
compdef _git ggfl=git-checkout
alias ggpush='git push origin "$(git_current_branch)"'
function ggp() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git push origin "${b:=$1}"
fi
}
compdef _git ggp=git-checkout
alias gpu='git push upstream'
alias gra='git remote add'
alias grhh='git reset --hard'
alias gpristine='git reset --hard && git clean --force -dfx'
alias grm='git rm'
alias gsps='git show --pretty=short --show-signature'
alias gst='git status'
alias gsw='git switch'
function gcpr(){
git fetch -fu upstream refs/pull/$1/head:pr/$1
git checkout pr/$1
}
unset git_version
# Logic for adding warnings on deprecated aliases
local old_alias new_alias
for old_alias new_alias (
# TODO(2023-10-19): remove deprecated `git pull --rebase` aliases
gup gpr
gupv gprv
gupa gpra
gupav gprav
gupom gprom
gupomi gpromi
); do
aliases[$old_alias]="
print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_alias}%F{yellow}' is a deprecated alias, using '%F{green}${new_alias}%F{yellow}' instead.%f\"
$new_alias"
done
unset old_alias new_alias

@ -1 +0,0 @@
Subproject commit 87ce96b1862928d84b1afe7c173316614b30e301

View file

@ -1,108 +0,0 @@
# ------------------------------------------------------------------------------
# Description
# -----------
#
# sudo or sudo -e (replacement for sudoedit) will be inserted before the command
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Dongweiming <ciici123@gmail.com>
# * Subhaditya Nath <github.com/subnut>
# * Marc Cornellà <github.com/mcornella>
# * Carlo Sala <carlosalag@protonmail.com>
#
# ------------------------------------------------------------------------------
__sudo-replace-buffer() {
local old=$1 new=$2 space=${2:+ }
# if the cursor is positioned in the $old part of the text, make
# the substitution and leave the cursor after the $new text
if [[ $CURSOR -le ${#old} ]]; then
BUFFER="${new}${space}${BUFFER#$old }"
CURSOR=${#new}
# otherwise just replace $old with $new in the text before the cursor
else
LBUFFER="${new}${space}${LBUFFER#$old }"
fi
}
sudo-command-line() {
# If line is empty, get the last run command from history
[[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)"
# Save beginning space
local WHITESPACE=""
if [[ ${LBUFFER:0:1} = " " ]]; then
WHITESPACE=" "
LBUFFER="${LBUFFER:1}"
fi
{
# If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR
# Else use the default $EDITOR
local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}}
# If $EDITOR is not set, just toggle the sudo prefix on and off
if [[ -z "$EDITOR" ]]; then
case "$BUFFER" in
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;;
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
*) LBUFFER="sudo $LBUFFER" ;;
esac
return
fi
# Check if the typed command is really an alias to $EDITOR
# Get the first part of the typed command
local cmd="${${(Az)BUFFER}[1]}"
# Get the first part of the alias of the same name as $cmd, or $cmd if no alias matches
local realcmd="${${(Az)aliases[$cmd]}[1]:-$cmd}"
# Get the first part of the $EDITOR command ($EDITOR may have arguments after it)
local editorcmd="${${(Az)EDITOR}[1]}"
# Note: ${var:c} makes a $PATH search and expands $var to the full path
# The if condition is met when:
# - $realcmd is '$EDITOR'
# - $realcmd is "cmd" and $EDITOR is "cmd"
# - $realcmd is "cmd" and $EDITOR is "cmd --with --arguments"
# - $realcmd is "/path/to/cmd" and $EDITOR is "cmd"
# - $realcmd is "/path/to/cmd" and $EDITOR is "/path/to/cmd"
# or
# - $realcmd is "cmd" and $EDITOR is "cmd"
# - $realcmd is "cmd" and $EDITOR is "/path/to/cmd"
# or
# - $realcmd is "cmd" and $EDITOR is /alternative/path/to/cmd that appears in $PATH
if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \
|| "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \
|| builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then
__sudo-replace-buffer "$cmd" "sudo -e"
return
fi
# Check for editor commands in the typed command and replace accordingly
case "$BUFFER" in
$editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;;
\$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;;
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;;
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
*) LBUFFER="sudo $LBUFFER" ;;
esac
} always {
# Preserve beginning space
LBUFFER="${WHITESPACE}${LBUFFER}"
# Redisplay edit buffer (compatibility with zsh-syntax-highlighting)
zle && zle redisplay # only run redisplay if zle is enabled
}
}
zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey -M emacs '\e\e' sudo-command-line
bindkey -M vicmd '\e\e' sudo-command-line
bindkey -M viins '\e\e' sudo-command-line

View file

@ -1,2 +0,0 @@
set -g default-terminal $ZSH_TMUX_TERM
source-file $ZSH_TMUX_CONFIG

View file

@ -1 +0,0 @@
set -g default-terminal $ZSH_TMUX_TERM

View file

@ -1,190 +0,0 @@
if ! (( $+commands[tmux] )); then
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2
return 1
fi
# CONFIGURATION VARIABLES
# Automatically start tmux
if [[ ! $(tty) =~ ^/dev/tty[0-9]*$ ]]; then
: ${ZSH_TMUX_AUTOSTART:=true}
else
: ${ZSH_TMUX_AUTOSTART:=false}
fi
# Only autostart once. If set to false, tmux will attempt to
# autostart every time your zsh configs are reloaded.
: ${ZSH_TMUX_AUTOSTART_ONCE:=true}
# Automatically connect to a previous session if it exists
: ${ZSH_TMUX_AUTOCONNECT:=true}
# Automatically close the terminal when tmux exits
: ${ZSH_TMUX_AUTOQUIT:=false}
# Automatically name the new session based on the basename of PWD
: ${ZSH_TMUX_AUTONAME_SESSION:=false}
# Set term to screen or screen-256color based on current terminal support
: ${ZSH_TMUX_DETACHED:=false}
# Set detached mode
: ${ZSH_TMUX_FIXTERM:=true}
# Set '-CC' option for iTerm2 tmux integration
: ${ZSH_TMUX_ITERM2:=false}
# The TERM to use for non-256 color terminals.
# Tmux states this should be tmux|screen, but you may need to change it on
# systems without the proper terminfo
if [[ -e /usr/share/terminfo/t/tmux ]]; then
: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=tmux}
else
: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen}
fi
# The TERM to use for 256 color terminals.
# Tmux states this should be (tmux|screen)-256color, but you may need to change it on
# systems without the proper terminfo
if [[ -e /usr/share/terminfo/t/tmux-256color ]]; then
: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=tmux-256color}
else
: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color}
fi
# Set the configuration path
if [[ -e $HOME/.tmux.conf ]]; then
: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf}
elif [[ -e ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf ]]; then
: ${ZSH_TMUX_CONFIG:=${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf}
else
: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf}
fi
# Set -u option to support unicode
: ${ZSH_TMUX_UNICODE:=false}
# ALIASES
function _build_tmux_alias {
setopt localoptions no_rc_expand_param
eval "function $1 {
if [[ -z \$1 ]] || [[ \${1:0:1} == '-' ]]; then
tmux $2 \"\$@\"
else
tmux $2 $3 \"\$@\"
fi
}"
local f s
f="_omz_tmux_alias_${1}"
s=(${(z)2})
eval "function ${f}() {
shift words;
words=(tmux ${@:2} \$words);
((CURRENT+=${#s[@]}+1))
_tmux
}"
compdef "$f" "$1"
}
alias tksv='tmux kill-server'
alias tl='tmux list-sessions'
alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG'
_build_tmux_alias "ta" "attach" "-t"
_build_tmux_alias "tad" "attach -d" "-t"
_build_tmux_alias "ts" "new-session" "-s"
_build_tmux_alias "tkss" "kill-session" "-t"
unfunction _build_tmux_alias
# Determine if the terminal supports 256 colors
if [[ $terminfo[colors] == 256 ]]; then
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
else
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
fi
# Handle $0 according to the standard:
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
# Set the correct local config file to use.
if [[ "$ZSH_TMUX_ITERM2" == "false" && -e "$ZSH_TMUX_CONFIG" ]]; then
export ZSH_TMUX_CONFIG
export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.extra.conf"
else
export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.only.conf"
fi
# Wrapper function for tmux.
function _zsh_tmux_plugin_run() {
if [[ -n "$@" ]]; then
command tmux "$@"
return $?
fi
local -a tmux_cmd
tmux_cmd=(command tmux)
[[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC)
[[ "$ZSH_TMUX_UNICODE" == "true" ]] && tmux_cmd+=(-u)
local _detached=""
[[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d"
local session_name
if [[ "$ZSH_TMUX_AUTONAME_SESSION" == "true" ]]; then
# Name the session after the basename of the current directory
session_name=${PWD##*/}
# If the current directory is the home directory, name it 'HOME'
[[ "$PWD" == "$HOME" ]] && session_name="HOME"
# If the current directory is the root directory, name it 'ROOT'
[[ "$PWD" == "/" ]] && session_name="ROOT"
else
session_name="$ZSH_TMUX_DEFAULT_SESSION_NAME"
fi
# Try to connect to an existing session.
if [[ -n "$session_name" ]]; then
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t "$session_name"
else
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached
fi
# If failed, just run tmux, fixing the TERM variable if requested.
if [[ $? -ne 0 ]]; then
if [[ "$ZSH_TMUX_FIXTERM" == "true" ]]; then
tmux_cmd+=(-f "$_ZSH_TMUX_FIXED_CONFIG")
elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then
tmux_cmd+=(-f "$ZSH_TMUX_CONFIG")
fi
if [[ -n "$session_name" ]]; then
$tmux_cmd new-session -s "$session_name"
else
$tmux_cmd new-session
fi
fi
if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then
exit
fi
}
# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run
# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run
function _tmux_directory_session() {
# current directory without leading path
local dir=${PWD##*/}
# md5 hash for the full working directory path
local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1)
# human friendly unique session name for this directory
local session_name="${dir}-${md5:0:6}"
# create or attach to the session
tmux new -As "$session_name"
}
alias tds=_tmux_directory_session
# Autostart if not already in tmux and enabled.
if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then
# Actually don't autostart if we already did and multiple autostarts are disabled.
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then
export ZSH_TMUX_AUTOSTARTED=true
_zsh_tmux_plugin_run
fi
fi