Switch to home manager and move off of ohmyzsh

This commit is contained in:
2024-12-03 20:55:46 -08:00
parent e73044a1ca
commit afcb55d5c4
14 changed files with 277 additions and 152 deletions

21
zsh/aliases Normal file
View File

@@ -0,0 +1,21 @@
# Git
alias gcl='git clone'
alias gp='git push'
alias gs='git status'
# ls
alias ll='ls -lah'
alias l='ls -CF'
# System Utils
alias rebuild='darwin-rebuild switch --flake ~/dotfiles/nix#macbook'
alias cl='clear'
alias wthr='curl wttr.in/san_luis_obispo'
alias nf='cl && fastfetch && shownetinfo && batt'
alias src='source ~/.zshrc'
alias fps='if [[ $(launchctl getenv MTL_HUD_ENABLED) -eq 1 ]]; then
launchctl unsetenv MTL_HUD_ENABLED && echo "Metal FPS disabled"
else
launchctl setenv MTL_HUD_ENABLED 1 && echo "Metal FPS enabled"
fi'

50
zsh/functions Normal file
View File

@@ -0,0 +1,50 @@
function shownetinfo() {
OSTYPE=$(uname -s)
LANIP=""
WANIP=""
ROUTR=""
if [ "$OSTYPE" = "Linux" ]; then
LANIP=$(ip addr show | grep -v "127.0.0.1" | grep "inet " | head -1 | cut -d " " -f6 | cut -d "/" -f1)
ROUTR=$(ip route | grep default | cut -d " " -f3)
if [ "$ROUTR" != "" ]; then
WANIP=$(timeout 0.25s curl -s ipv4.icanhazip.com)
fi
elif [ "$OSTYPE" = "Darwin" ]; then
ROUTR=$(system_profiler SPNetworkDataType | grep "Router:" | cut -c 19-30 | head -1)
LANIP=$(ifconfig | grep -v "127.0.0.1" | grep "inet " | head -1 | cut -d " " -f2)
if [ "$ROUTR" != "" ]; then
WANIP=$(timeout 0.25s curl -s ipv4.icanhazip.com)
fi
fi
tput setaf 7; tput bold; echo -en "Net: "
tput sgr0
tput setaf 7; echo -en "internal $LANIP"
if [ "$ROUTR" != "" ]; then
echo -en ", external $WANIP"
echo -en ", router $ROUTR"
fi
tput sgr0
}
function batt() {
tput setaf 7
tput bold
echo -en " | "
tput sgr0
tput setaf 7; tput bold; echo -en "Bat: "
tput sgr0
tput setaf 7
echo -en $(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
echo "%"
tput sgr0
}
function lab() {
tput setaf 7; tput bold; echo -en "Lab: "
tput sgr0
tput setaf 7
echo $(curl -s https://cpsecurity.club/api/v1/status | jq ".data.status" | tr -d "\"")
tput sgr0
}

72
zsh/theme Normal file
View File

@@ -0,0 +1,72 @@
git_branch_info() {
local git_status_full=$(git status --porcelain=v2 --branch -z 2>/dev/null)
[[ -n "$git_status_full" ]] || return
local branch=""
local status_indicators=""
local line
local -a status_lines=("${(0)git_status_full}")
for line in $status_lines; do
case $line in
\#' 'branch.head' '*) branch=${line##* }; continue ;;
\#' 'branch.ab' '*)
local -a counts=("${(s: :)line}")
[[ ${counts[3]#+} -gt 0 ]] && status_indicators+="%B%F{magenta}↑%f%b"
[[ ${counts[4]#+} -gt 0 ]] && status_indicators+="%B%F{green}↓%f%b"
;;
'?'*) ((untracked)) || { untracked=1; status_indicators+="%B%F{white}●%f%b" } ;;
'u'*) ((unmerged)) || { unmerged=1; status_indicators+="%B%F{red}✕%f%b" } ;;
[12]' '*)
if [[ ${line[3]} != "." && $staged -eq 0 ]]; then
staged=1
status_indicators+="%B%F{green}●%f%b"
fi
if [[ ${line[4]} != "." && $unstaged -eq 0 ]]; then
unstaged=1
status_indicators+="%B%F{red}●%f%b"
fi
;;
esac
done
[[ -n "$branch" ]] && echo " %B%F{white} %B%F{yellow}${branch}%f${status_indicators:+ $status_indicators}%B%F{white}%f "
}
local CACHED_PWD=""
local CACHED_SHORT_PWD=""
shrink_path() {
if [[ $CACHED_PWD != $PWD ]]; then
CACHED_PWD=$PWD
local directory=${PWD/#$HOME/\~}
if [[ $directory == '~' || $directory == '/' ]]; then
CACHED_SHORT_PWD=$directory
echo $CACHED_SHORT_PWD
return
fi
local parts=("${(@s:/:)directory}")
local output=()
for part in $parts[1,-2]; do
if [[ -n $part && $part != "~" ]]; then
output+=$part[1]
else
output+=$part
fi
done
output+=$parts[-1]
CACHED_SHORT_PWD=${(j:/:)output}
fi
echo $CACHED_SHORT_PWD
}
# SSH connection indicator
ssh_connection() {
if [[ -n $SSH_CONNECTION ]]; then
echo "%B%F{red}(ssh)%f%b "
fi
}
# Prompt configuration
PROMPT='$(ssh_connection)%B%F{green}%n@%m%f%b$(git_branch_info) %f%b: $(shrink_path)
[%(?:%B%F{green}%?%f%b:%B%F{red}%?%f%b)]  '
setopt PROMPT_SUBST

76
zsh/zshrc Normal file
View File

@@ -0,0 +1,76 @@
# Get basic stuff out of the way
source ~/.zsh.d/theme
source ~/.zsh.d/functions
source ~/.zsh.d/aliases
# History search with started text
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search # Up arrow
bindkey "^[[B" down-line-or-beginning-search # Down arrow
# Initialize completion system
autoload -U compinit && compinit
# Case insensitive completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Menu selection for completion
zstyle ':completion:*' menu select
zstyle ':completion:*' file-sort name
zstyle ':completion:*' list-colors ''
bindkey '^[[Z' reverse-menu-complete
# Configure history to be longer
HISTSIZE=10000000
SAVEHIST=10000000
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.
# Use vim as editor
export EDITOR=vim
export VISUAL=vim
# Enable colors in ls
export CLICOLOR=1
# For Linux/BSD ls colors
if whence dircolors >/dev/null; then
eval "$(dircolors -b)"
alias ls='ls --color=auto'
else
# For macOS ls colors
export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
alias ls='ls -G'
fi
shownetinfo
if [ "$OSTYPE" = "Linux" ]; then
echo ""
elif [ "$OSTYPE" = "Darwin" ]; then
# set up iterm integration
source ~/.iterm2_shell_integration.zsh
# set up auto suggestions and syntax highlighting
source /nix/store/*zsh-autosuggestions*/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /nix/store/*zsh-syntax-highlighting*/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ssh-add -K ~/.ssh/id_rsa 2>/dev/null
LAPTOP=$(system_profiler SPHardwareDataType | grep "Model Name" | grep "Book")
if [ "$LAPTOP" != "" ]; then
batt
else
echo ""
fi
fi