From afcb55d5c4395dc1b6230dac552dd9f3c6589a98 Mon Sep 17 00:00:00 2001 From: Stephen Parkinson Date: Tue, 3 Dec 2024 20:55:46 -0800 Subject: [PATCH] Switch to home manager and move off of ohmyzsh --- aliases | 27 --------- gitconfig => git/gitconfig | 0 gitignore_global => git/gitignore_global | 0 newstephen.zsh-theme | 65 -------------------- nix/flake.lock | 33 ++++++++-- nix/flake.nix | 53 +++++++++++++++-- nix/home.nix | 33 ++++++++++ tmux.conf => tmux/tmux.conf | 0 vimrc => vim/vimrc | 0 zsh/aliases | 21 +++++++ functions => zsh/functions | 0 zsh/theme | 72 ++++++++++++++++++++++ zsh/zshrc | 76 ++++++++++++++++++++++++ zshrc | 49 --------------- 14 files changed, 277 insertions(+), 152 deletions(-) delete mode 100644 aliases rename gitconfig => git/gitconfig (100%) rename gitignore_global => git/gitignore_global (100%) delete mode 100644 newstephen.zsh-theme create mode 100644 nix/home.nix rename tmux.conf => tmux/tmux.conf (100%) rename vimrc => vim/vimrc (100%) create mode 100644 zsh/aliases rename functions => zsh/functions (100%) create mode 100644 zsh/theme create mode 100644 zsh/zshrc delete mode 100644 zshrc diff --git a/aliases b/aliases deleted file mode 100644 index 1822aac..0000000 --- a/aliases +++ /dev/null @@ -1,27 +0,0 @@ -# Git -alias gcl='git clone' -alias gp='git push' -alias gs='git status' - -# ls -alias ll='ls -alh' - -# System Utils -alias brewup='cl && brew update && brew upgrade && brew upgrade --cask && brew cleanup -s && brew doctor --verbose | grep -A 1 --color=never "Homebrew Version" && brew autoremove' -alias cl='clear' -alias ta="tmux a -t" -alias tn="tmux new-session -s" -alias gcc="gcc -g" -alias wthr='curl wttr.in/san_luis_obispo' -alias nf='cl && neofetch && shownetinfo && batt' -alias hekate='python3 /Users/smparkin/Development/fusee-launcher/fusee-launcher.py /Users/smparkin/Development/fusee-launcher/hekate/hekate.bin' -alias src='omz reload' -alias python='python3' - -# Music -alias amp='python3 ~/Developer/abandoned/SSiTerm/music.py play' -alias amn='python3 ~/Developer/abandoned/SSiTerm/music.py next' -alias amr='python3 ~/Developer/abandoned/SSiTerm/music.py prev' -alias amv='python3 ~/Developer/abandoned/SSiTerm/music.py playback --volume ' - -alias fps='[[ $(launchctl getenv MTL_HUD_ENABLED) -eq 1 ]]&&launchctl unsetenv MTL_HUD_ENABLED||launchctl setenv MTL_HUD_ENABLED 1' diff --git a/gitconfig b/git/gitconfig similarity index 100% rename from gitconfig rename to git/gitconfig diff --git a/gitignore_global b/git/gitignore_global similarity index 100% rename from gitignore_global rename to git/gitignore_global diff --git a/newstephen.zsh-theme b/newstephen.zsh-theme deleted file mode 100644 index 0d7e6b5..0000000 --- a/newstephen.zsh-theme +++ /dev/null @@ -1,65 +0,0 @@ -function my_git_prompt() { - tester=$(git rev-parse --git-dir 2> /dev/null) || return - - INDEX=$(git status --porcelain 2> /dev/null) - STATUS="" - - # is branch ahead? - if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" - fi - - # is branch behind? - if $(echo "$(git log HEAD..origin/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" - fi - - # is anything staged? - if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED" - fi - - # is anything unstaged? - if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" - fi - - # is anything untracked? - if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" - fi - - # is anything unmerged? - if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then - STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" - fi - - if [[ -n $STATUS ]]; then - STATUS=" $STATUS" - fi - - echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(my_current_branch)$STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX" -} - -function my_current_branch() { - echo $(git_current_branch || echo "(no branch)") -} - -function ssh_connection() { - if [[ -n $SSH_CONNECTION ]]; then - echo "%{$fg_bold[red]%}(ssh) " - fi -} - -local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" -PROMPT=$'$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : $(shrink_path -f)\n[${ret_status}]  ' - -ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" -ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}" -ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑" -ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[green]%}↓" -ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●" -ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[red]%}●" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[white]%}●" -ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕" -ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]%{$reset_color%}›" diff --git a/nix/flake.lock b/nix/flake.lock index cd38416..f74feb0 100644 --- a/nix/flake.lock +++ b/nix/flake.lock @@ -35,6 +35,26 @@ "type": "github" } }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733175814, + "narHash": "sha256-zFOtOaqjzZfPMsm1mwu98syv3y+jziAq5DfWygaMtLg=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "bf23fe41082aa0289c209169302afd3397092f22", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, "nix-darwin": { "inputs": { "nixpkgs": [ @@ -42,11 +62,11 @@ ] }, "locked": { - "lastModified": 1732603785, - "narHash": "sha256-AEjWTJwOmSnVYsSJCojKgoguGfFfwel6z/6ud6UFMU8=", + "lastModified": 1733047432, + "narHash": "sha256-fQUKxgxAEHlL5bevRkdsQB7sSpAMhlvxf7Zw0KK8QIg=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "6ab87b7c84d4ee873e937108c4ff80c015a40c7a", + "rev": "e30a3622b606dffc622305b4bbe1cfe37e78fa40", "type": "github" }, "original": { @@ -125,11 +145,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1732238832, - "narHash": "sha256-sQxuJm8rHY20xq6Ah+GwIUkF95tWjGRd1X8xF+Pkk38=", + "lastModified": 1733024928, + "narHash": "sha256-n/DOfpKH1vkukuBnach91QBQId2dr5tkE7/7UrkV2zw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8edf06bea5bcbee082df1b7369ff973b91618b8d", + "rev": "2c27ab2e60502d1ebb7cf38909de38663f762a79", "type": "github" }, "original": { @@ -141,6 +161,7 @@ }, "root": { "inputs": { + "home-manager": "home-manager", "nix-darwin": "nix-darwin", "nix-homebrew": "nix-homebrew", "nixpkgs": "nixpkgs_3" diff --git a/nix/flake.nix b/nix/flake.nix index 09b0a62..0496800 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -6,9 +6,11 @@ nix-darwin.url = "github:LnL7/nix-darwin"; nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew }: + outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew, home-manager }: let configuration = { pkgs, config, ... }: { @@ -20,8 +22,14 @@ [ pkgs.fastfetch pkgs.coreutils + pkgs.nmap pkgs.openjdk17 pkgs.openjdk21 + pkgs.tree + pkgs.zstd + # zsh plugins + pkgs.zsh-autosuggestions + pkgs.zsh-syntax-highlighting ]; homebrew = { @@ -49,6 +57,7 @@ "scroll-reverser" "sf-symbols" "steam" + "utm" "visual-studio-code" ]; brews = [ @@ -69,7 +78,7 @@ "TheUnarchiver" = 425424353; "Unread" = 1363637349; "WiFiMan" = 1385561119; - "Wipr" = 1320666476; + "Wipr2" = 1662217862; "WireGuard" = 1451685025; "Xcode" = 497799835; }; @@ -85,6 +94,8 @@ # Necessary for using flakes on this system. nix.settings.experimental-features = "nix-command flakes"; + # Defaults + security.pam.enableSudoTouchIdAuth = true; system.defaults = { dock.autohide = true; trackpad.Clicking = true; @@ -100,6 +111,12 @@ # The platform the configuration will be used on. nixpkgs.hostPlatform = "aarch64-darwin"; + programs.zsh.enable = true; + + # Home Manager + users.users.smparkin.home = "/Users/smparkin"; + nix.configureBuildUsers = true; + nix.useDaemon = true; }; in { @@ -114,13 +131,39 @@ enable = true; enableRosetta = true; user = "smparkin"; - autoMigrate = true; + }; + } + home-manager.darwinModules.home-manager + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + users.smparkin = import ./home.nix; }; } ]; }; - # Expose the package set, including overlays, for convenience. - darwinPackages = self.darwinConfigurations."macbook".pkgs; + darwinConfigurations."workbook" = nix-darwin.lib.darwinSystem { + modules = [ + configuration + nix-homebrew.darwinModules.nix-homebrew + { + nix-homebrew = { + enable = true; + enableRosetta = true; + user = "parkist"; + }; + } + home-manager.darwinModules.home-manager + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + users.parkist = import ./work.nix; + }; + } + ]; + }; }; } diff --git a/nix/home.nix b/nix/home.nix new file mode 100644 index 0000000..30131b5 --- /dev/null +++ b/nix/home.nix @@ -0,0 +1,33 @@ +{ config, pkgs, ... }: + +{ + # Home Manager needs a bit of information about you and the + # paths it should manage. + home.username = "smparkin"; + home.homeDirectory = "/Users/smparkin"; + + # This value determines the Home Manager release that your + # configuration is compatible with. This helps avoid breakage + # when a new Home Manager release introduces backwards + # incompatible changes. + # + # You can update Home Manager without changing this value. See + # the Home Manager release notes for a list of state version + # changes in each release. + home.stateVersion = "24.11"; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; + + # Home dir + home.file = { + ".zshrc".source = ../zsh/zshrc; + ".zsh.d/aliases".source = ../zsh/aliases; + ".zsh.d/functions".source = ../zsh/functions; + ".zsh.d/theme".source = ../zsh/theme; + ".gitconfig".source = ../git/gitconfig; + ".gitignore_global".source = ../git/gitignore_global; + ".tmux.conf".source = ../tmux/tmux.conf; + ".vimrc".source = ../vim/vimrc; + }; +} diff --git a/tmux.conf b/tmux/tmux.conf similarity index 100% rename from tmux.conf rename to tmux/tmux.conf diff --git a/vimrc b/vim/vimrc similarity index 100% rename from vimrc rename to vim/vimrc diff --git a/zsh/aliases b/zsh/aliases new file mode 100644 index 0000000..6c91ade --- /dev/null +++ b/zsh/aliases @@ -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' \ No newline at end of file diff --git a/functions b/zsh/functions similarity index 100% rename from functions rename to zsh/functions diff --git a/zsh/theme b/zsh/theme new file mode 100644 index 0000000..2bb7818 --- /dev/null +++ b/zsh/theme @@ -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 diff --git a/zsh/zshrc b/zsh/zshrc new file mode 100644 index 0000000..024bd8e --- /dev/null +++ b/zsh/zshrc @@ -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 diff --git a/zshrc b/zshrc deleted file mode 100644 index 399bf27..0000000 --- a/zshrc +++ /dev/null @@ -1,49 +0,0 @@ -# Path to your oh-my-zsh installation. -OSTYPE=$(uname -s) -if [ "$OSTYPE" = "Linux" ]; then - export ZSH="/home/smparkin/.oh-my-zsh" -elif [ "$OSTYPE" = "Darwin" ]; then - export ZSH="/Users/smparkin/.oh-my-zsh" -fi - -# Set name of the theme to load -ZSH_THEME="newstephen" - -# Hyphen-insensitive completion -HYPHEN_INSENSITIVE="true" - -# Disable marking untracked files under git as dirty -DISABLE_UNTRACKED_FILES_DIRTY="true" - -# Which plugins would you like to load? -plugins=( - colored-man-pages - iterm2 - zsh-navigation-tools - shrink-path -) - -source $ZSH/oh-my-zsh.sh -source ~/.zsh.d/functions -source ~/.zsh.d/aliases -if [ "$OSTYPE" = "Darwin" ]; then - source ~/.iterm2_shell_integration.zsh -fi - -if [ "$OSTYPE" = "Darwin" ]; then - export EDITOR="/usr/bin/vim" -fi - -shownetinfo -if [ "$OSTYPE" = "Linux" ]; then - echo "" -elif [ "$OSTYPE" = "Darwin" ]; then - 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 -