Skip to content

Instantly share code, notes, and snippets.

@septicwolf818
Last active June 16, 2026 15:57
Show Gist options
  • Select an option

  • Save septicwolf818/f059f7d8d2cfba318a4df8736664dccc to your computer and use it in GitHub Desktop.

Select an option

Save septicwolf818/f059f7d8d2cfba318a4df8736664dccc to your computer and use it in GitHub Desktop.
My ZSH config
# You have to install ZSH shell first, then neofetch to make it work
autoload -Uz vcs_info
autoload -Uz compinit && compinit
autoload virtualenv
zstyle ':vcs_info:*' enable git svn
setopt PROMPT_SUBST
zstyle ':vcs_info:git*' formats "→ (%b) "
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ↠ '
}
precmd() {
vcs_info
PROMPT=$'\n'"%F{red}┌───%f%F{green}[%f%F{cyan} %n%F{red}@%f%F{cyan}%M%f %F{green}]%f %F{green}{%f %F{cyan}%T%f %F{green}}%f"$'\n'"%F{red}│%f"$'\n'"%F{red}└───%f%F{green}[%f %F{cyan}%~ %f%F{green}]%f %F{yellow}${vcs_info_msg_0_}%f%F{red}»%f "
PROMPT+='%F{magenta}$(virtualenv_info)%f'
}
merge_changes_from_master() {
local default_branch=${1:-master}
if [ "$default_branch" = "master" ]; then
print -P "\nℹ️ You can specify the %F{green}default branch%f as an argument when calling the function. Example: \n\n$ merge_changes_from_master %F{green}my_default_branch%f"
fi
if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
print -P "\n✅ %F{green}Current directory is a Git repository.%f"
else
print -P "\n❌ %F{red}Current directory is not a Git repository.%f"
return
fi
current_branch=$(git branch | grep \* | sed 's/.* //')
print -P "\nℹ️ Current branch is %F{yellow}$current_branch%f\n"
print -Pn "❓ Do you want to proceed with merging changes from %F{green}$default_branch%f into %F{yellow}$current_branch%f?"
read -q "REPLY? (y/n) "
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print -P "\nℹ️ Switching to %F{green}$default_branch%f\n"
git checkout "$default_branch"
print -P "\nℹ️ Pulling latest changes from origin %F{green}$default_branch%f\n"
git pull
print -P "\nℹ️ Switching back to %F{yellow}$current_branch%f\n"
git checkout "$current_branch"
print -P "\nℹ️ Merging changes from %F{green}$default_branch%f into %F{yellow}$current_branch%f\n"
git merge "$default_branch"
else
print -P "%F{red}\n❌ Merge operation aborted."
fi
}
git-prune-local-branches() {
emulate -L zsh
local RED=$'\033[0;31m'
local GREEN=$'\033[0;32m'
local YELLOW=$'\033[1;33m'
local BLUE=$'\033[0;34m'
local CYAN=$'\033[0;36m'
local BOLD=$'\033[1m'
local NC=$'\033[0m'
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
printf "${RED}Not inside a git repository.${NC}\n"
return 1
fi
local current_branch
current_branch=$(git branch --show-current)
local default_branch
default_branch=$(
git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null |
sed 's#^origin/##'
)
if [[ -z "$default_branch" ]]; then
local b
for b in main master develop; do
if git show-ref --verify --quiet "refs/heads/$b"; then
default_branch="$b"
break
fi
done
fi
if [[ -z "$default_branch" ]]; then
printf "${RED}Could not determine default branch.${NC}\n"
return 1
fi
local -a all_branches
local _b
while read -r _b; do
[[ "$_b" == "$default_branch" ]] && continue
all_branches+=("$_b")
done < <(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads)
if (( ${#all_branches} == 0 )); then
printf "${YELLOW}No deletable local branches found.${NC}\n"
return 0
fi
local -a selected
local _i
for (( _i = 1; _i <= ${#all_branches}; _i++ )); do selected[_i]=0; done
local -a selected_branches
local cursor=0
local old_stty
old_stty=$(stty -g)
_gpb_enter() {
printf '\033[?1049h'
printf '\033[?25l'
stty -echo -icanon min 1 time 0
}
_gpb_exit() {
stty "$old_stty" 2>/dev/null
printf '\033[?25h'
printf '\033[?1049l'
}
_gpb_clear() {
printf '\033[H\033[2J'
}
_gpb_header() {
local title=${1:-"Git — prune local branches"}
printf " ${BOLD}${CYAN}%s${NC}\n" "$title"
printf " ${CYAN}default: ${YELLOW}%s${NC} ${CYAN}current: ${YELLOW}%s${NC}\n\n" "$default_branch" "$current_branch"
}
_gpb_render_selector() {
local rows
rows=$(tput lines 2>/dev/null || echo 24)
local visible_max=$(( rows - 5 ))
(( visible_max < 1 )) && visible_max=1
local total=${#all_branches}
local win_start=0
if (( total > visible_max )); then
win_start=$(( cursor - visible_max / 2 ))
(( win_start < 0 )) && win_start=0
(( win_start + visible_max > total )) && win_start=$(( total - visible_max ))
fi
local win_end=$(( win_start + visible_max - 1 ))
(( win_end >= total )) && win_end=$(( total - 1 ))
_gpb_clear
_gpb_header
local idx branch chk cur ann
for (( idx = win_start; idx <= win_end; idx++ )); do
branch=${all_branches[idx+1]}
if [[ ${selected[idx+1]} == 1 ]]; then
chk="${GREEN}${NC}"
else
chk=" "
fi
if (( idx == cursor )); then
cur="${BLUE}${BOLD}${NC}"
else
cur=" "
fi
ann=""
[[ "$branch" == "$current_branch" ]] && ann=" ${YELLOW}(current)${NC}"
printf " %s [%s] %s%s\n" "$cur" "$chk" "$branch" "$ann"
done
if (( total > visible_max )); then
printf "\n ${CYAN}showing %d–%d of %d${NC}\n" \
$(( win_start + 1 )) $(( win_end + 1 )) "$total"
fi
printf "\n ${YELLOW}↑/↓ j/k: move SPACE: toggle ENTER: confirm ESC: cancel${NC}\n"
}
_gpb_cancelled() {
_gpb_clear
_gpb_header
printf " ${YELLOW}%s${NC}\n" "$1"
sleep 1
}
trap '_gpb_exit; return 1' INT TERM
_gpb_enter
_gpb_render_selector
local aborted=0
local key key2 key3
while true; do
IFS= read -r -s -k1 key
case "$key" in
$'\x1b')
IFS= read -r -s -k1 -t 0.05 key2 || key2=""
IFS= read -r -s -k1 -t 0.05 key3 || key3=""
if [[ "$key2$key3" == "[A" ]]; then
(( cursor = (cursor - 1 + ${#all_branches}) % ${#all_branches} ))
elif [[ "$key2$key3" == "[B" ]]; then
(( cursor = (cursor + 1) % ${#all_branches} ))
else
aborted=1
break
fi
;;
k)
(( cursor = (cursor - 1 + ${#all_branches}) % ${#all_branches} ))
;;
j)
(( cursor = (cursor + 1) % ${#all_branches} ))
;;
' ')
if [[ ${selected[cursor+1]} == 1 ]]; then
selected[cursor+1]=0
else
selected[cursor+1]=1
fi
;;
$'\n'|$'\r')
break
;;
esac
_gpb_render_selector
done
if (( aborted )); then
_gpb_cancelled "Cancelled."
trap - INT TERM
_gpb_exit
return 0
fi
unset key key2 key3
sleep 0.1
local _drain
while IFS= read -r -s -k1 -t 0.1 _drain 2>/dev/null; do :; done
for (( _i = 0; _i < ${#all_branches}; _i++ )); do
[[ ${selected[_i+1]} == 1 ]] && selected_branches+=("${all_branches[_i+1]}")
done
if (( ${#selected_branches} == 0 )); then
_gpb_cancelled "No branches selected."
trap - INT TERM
_gpb_exit
return 0
fi
# ── confirmation (stays in alt buffer) ────────────────────────────────────
local confirm_choice="n"
_gpb_render_confirm() {
_gpb_clear
_gpb_header "Confirm deletion"
printf " ${YELLOW}Branches to delete:${NC}\n\n"
local branch
for branch in "${selected_branches[@]}"; do
if [[ "$branch" == "$current_branch" ]]; then
printf " ${RED}✗ %s${NC} ${YELLOW}(will switch to %s first)${NC}\n" \
"$branch" "$default_branch"
else
printf " ${RED}✗ %s${NC}\n" "$branch"
fi
done
printf "\n"
printf " ${BOLD}Delete these %d branch(es)?${NC}\n\n" "${#selected_branches}"
local yes_label no_label
if [[ "$confirm_choice" == "y" ]]; then
yes_label="${BOLD}${GREEN}[ Yes ]${NC}"
no_label="${NC}[ No ]${NC}"
else
yes_label="${NC}[ Yes ]${NC}"
no_label="${BOLD}${RED}[ No ]${NC}"
fi
printf " %s %s\n" "$yes_label" "$no_label"
printf "\n ${YELLOW}←/→ switch Enter = confirm ESC = cancel${NC}\n"
}
_gpb_render_confirm
local confirm_aborted=0
local key key2 key3
while true; do
IFS= read -r -s -k1 key
case "$key" in
$'\x1b')
key2="" key3=""
IFS= read -r -s -k1 -t 0.1 key2 || key2=""
if [[ "$key2" == "[" ]]; then
IFS= read -r -s -k1 -t 0.1 key3 || key3=""
case "$key3" in
D) confirm_choice="y" ;;
C) confirm_choice="n" ;;
esac
else
confirm_aborted=1
break
fi
;;
h|y|Y)
confirm_choice="y"
;;
l|n|N)
confirm_choice="n"
;;
$'\t')
if [[ "$confirm_choice" == "y" ]]; then
confirm_choice="n"
else
confirm_choice="y"
fi
;;
$'\n'|$'\r')
break
;;
*)
;;
esac
_gpb_render_confirm
done
if (( confirm_aborted )) || [[ "$confirm_choice" != "y" ]]; then
_gpb_cancelled "Cancelled."
trap - INT TERM
_gpb_exit
return 0
fi
# ── deletion (stays in alt buffer) ────────────────────────────────────────
_gpb_clear
_gpb_header "Deleting branches"
local return_code=0
if (( ${selected_branches[(Ie)$current_branch]} )); then
printf " ${BLUE}Switching to %s...${NC} " "$default_branch"
if git switch "$default_branch" >/dev/null 2>&1; then
printf "${GREEN}${NC}\n"
else
printf "${RED}✗ failed${NC}\n"
_gpb_cancelled "Aborting."
trap - INT TERM
_gpb_exit
return 1
fi
fi
local branch
for branch in "${selected_branches[@]}"; do
printf " Deleting ${BOLD}%s${NC} ... " "$branch"
if git branch -D "$branch" >/dev/null 2>&1; then
printf "${GREEN}${NC}\n"
else
printf "${RED}✗ failed${NC}\n"
return_code=1
fi
done
printf "\n"
if (( return_code == 0 )); then
printf " ${GREEN}${BOLD}All done.${NC}\n"
else
printf " ${YELLOW}Done with errors.${NC} Some branches could not be deleted.\n"
fi
sleep 1
trap - INT TERM
_gpb_exit
return $return_code
}
clear && neofetch
alias ls="ls -laGh"
alias dir="ls"
alias nano="nano -lm"
alias edit="nano"
alias cls="clear"
alias update="brew update && brew upgrade"
alias neofetch="clear && neofetch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment