From 6a7885bdbbf6d7d1b107a68ca68055fbbde4c925 Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Sun, 7 Apr 2024 02:02:09 +0200 Subject: [PATCH] Move to a setup using GNU Stow instead of my system which copied files and kept a .lock dir --- .gitignore | 1 - .zshrc | 30 ----------------------------- restore.sh | 39 -------------------------------------- upgrade.sh | 31 ------------------------------ util_lib.sh | 51 -------------------------------------------------- yabai_launcher | 6 ------ zsh/.zshrc | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 50 insertions(+), 158 deletions(-) delete mode 100644 .zshrc delete mode 100755 restore.sh delete mode 100755 upgrade.sh delete mode 100644 util_lib.sh delete mode 100644 yabai_launcher create mode 100644 zsh/.zshrc diff --git a/.gitignore b/.gitignore index 0ff09c0..5ca0973 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .DS_Store -/.lock diff --git a/.zshrc b/.zshrc deleted file mode 100644 index dff5405..0000000 --- a/.zshrc +++ /dev/null @@ -1,30 +0,0 @@ -# CodeWhisperer pre block. Keep at the top of this file. -[[ -f "${HOME}/Library/Application Support/codewhisperer/shell/zshrc.pre.zsh" ]] && builtin source "${HOME}/Library/Application Support/codewhisperer/shell/zshrc.pre.zsh" - -# Created by Zap installer -[ -f "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" ] && source "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" -plug "zsh-users/zsh-autosuggestions" -plug "zap-zsh/supercharge" -plug "zap-zsh/zap-prompt" -plug "zsh-users/zsh-syntax-highlighting" -plug "jeffreytse/zsh-vi-mode" - -# Load and initialise completion system -autoload -Uz compinit -compinit - -# Neovim -export PATH=$HOME/local/nvim/bin:$PATH - -# Aliases -## Eza -alias ls="eza -a" -alias ll="eza --long --header -a" -alias tree="eza --tree --level=2" -## Pygments -alias cat="pygmentize -g" -## Neovim -alias vim="nvim" - -# CodeWhisperer post block. Keep at the bottom of this file. -[[ -f "${HOME}/Library/Application Support/codewhisperer/shell/zshrc.post.zsh" ]] && builtin source "${HOME}/Library/Application Support/codewhisperer/shell/zshrc.post.zsh" diff --git a/restore.sh b/restore.sh deleted file mode 100755 index 581b385..0000000 --- a/restore.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/zsh - -source ./util_lib.sh - -latest_lock=$(get_latest_lock) -has_lock=$(has_lock $latest_lock) - -if [ $has_lock -eq 0 ]; then - echo "No lock exists, nothing to restore." - exit 0 -fi - -lock_dir="$LOCK_ROOT"/"$latest_lock" - -# Iterate through the array of key-value pairs -for mapping in "${mappings[@]}"; do - current_mapping=("${(@s:|:)mapping}") - - src="$lock_dir/$(basename "${current_mapping[1]}")" - dest="${current_mapping[2]}" - - # If src exists at all? No matter if it's a file or directory - if [ ! -e "$src" ]; then - echo "$src does not exist, skipping." - continue - fi - - # Remove destination if it is a directory - if [ -d "$src" ] && [ -d "$dest/${current_mapping[1]}" ]; then - echo "Removing $dest/${current_mapping[1]}" - rm -rf "$dest/${current_mapping[2]}" - fi - - # Create destination directory - mkdir -p "$dest" - - # Copy source to destination - cp -r "$src" "$dest" -done diff --git a/upgrade.sh b/upgrade.sh deleted file mode 100755 index a03abe3..0000000 --- a/upgrade.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/zsh - -source ./util_lib.sh - -# Create a lock dir for our current configs. -((latest_lock=$(get_latest_lock) + 1)) -lock_dir="$LOCK_ROOT"/"$latest_lock" -mkdir -p "$lock_dir" - -# Iterate through the array of key-value pairs -for mapping in "${mappings[@]}"; do - current_mapping=("${(@s:|:)mapping}") - - src="${current_mapping[1]}" - dest="${current_mapping[2]}" - lock_dest="$lock_dir/$(basename "$src")" - - # Check if destination directory exists - final="$dest/$src" - if [ -e "$final" ]; then - # mv "$final"/* "$lock_dest" - mv "$final" "$lock_dest" - echo "Moved \"$final\" to \"$lock_dest\"" - fi - - # Create destination directory - mkdir -p "$dest" - - # Copy source to destination - cp -r "$src" "$dest" -done diff --git a/util_lib.sh b/util_lib.sh deleted file mode 100644 index 94b61b0..0000000 --- a/util_lib.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/zsh - -LOCK_ROOT=".lock" - -# Enable the NULL_GLOB option to handle cases where no subdirectories exist -setopt NULL_GLOB - -# Define a function to create key-value pairs -create_mapping() { - local input="$1" - local output="$2" - echo "$input|$output" -} - -# Define an array of key-value pairs -mappings=( - $(create_mapping "nvim" "$HOME/.config") - $(create_mapping "kitty" "$HOME/.config") - $(create_mapping ".zshrc" "$HOME") - $(create_mapping "yabai" "$HOME/.config") - $(create_mapping "yabai_launcher" "/private/etc/sudoers.d") -) - -function get_latest_lock() { - local latest_lock=0 - for subdir in "$LOCK_ROOT"/*/; do - subdir_name=${subdir%"${subdir##*[!/]}"} - subdir_name=${subdir_name##*/} - - if [[ $subdir_name =~ ^[0-9]+$ ]] && ((subdir_name > latest_lock)); then - latest_lock=$subdir_name - fi - done - - echo $latest_lock -} - -function has_lock() { - local latest_lock=$1 - - # if first parameter does not exist, call get_latest_lock - if [[ -z $latest_lock ]]; then - latest_lock=$(get_latest_lock) - fi - - if [[ $latest_lock -ne 0 ]]; then - echo 1 - else - echo 0 - fi -} diff --git a/yabai_launcher b/yabai_launcher deleted file mode 100644 index 3847e54..0000000 --- a/yabai_launcher +++ /dev/null @@ -1,6 +0,0 @@ -# replace with your username (output of: whoami). -# replace with the sha256 hash of the yabai binary (output of: shasum -a 256 $(which yabai)). -# this hash must be updated manually after running brew upgrade. -# replace with the path to the yabai binary (output of: which yabai). - -larssonmartin1998 ALL=(root) NOPASSWD: sha256:5c729cfc728ec8780c14d6fe0bfd74376bd2f057960b542c41106d8e8c5df787 /opt/homebrew/bin/yabai --load-sa diff --git a/zsh/.zshrc b/zsh/.zshrc new file mode 100644 index 0000000..d50747d --- /dev/null +++ b/zsh/.zshrc @@ -0,0 +1,50 @@ +# Created by Zap installer +[ -f "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" ] && source "${XDG_DATA_HOME:-$HOME/.local/share}/zap/zap.zsh" +plug "zsh-users/zsh-autosuggestions" +plug "zap-zsh/supercharge" +plug "zap-zsh/zap-prompt" +plug "zsh-users/zsh-syntax-highlighting" +plug "jeffreytse/zsh-vi-mode" + +# Load and initialise completion system +autoload -Uz compinit +compinit + +# Neovim +export PATH=$HOME/local/nvim/bin:$PATH + +# Catppuccin for zsh-syntax-highlighting +source ~/.zsh/catppuccin_macchiato-zsh-syntax-highlighting.zsh +# Catppuccin for fzf +export FZF_DEFAULT_OPTS=" \ +--color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 \ +--color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc \ +--color=marker:#f5e0dc,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8" +# Make sure to use the nightly version of Neovim in user space (still running pacman install as root) +export PATH="$HOME/.local/nvim/bin:$PATH" + +# Aliases +## Eza +alias ls="eza -a" +alias ll="eza --long --header -a" +alias tree="eza --tree --level=2" +## Pygments +alias cat="pygmentize -g" +## Neovim +alias vim="nvim" +## Lazygit +alias lgit="lazygit" +## Fastfetch +alias neofetch="fastfetch" +## Bat +alias cat="bat" +## fzf +alias fzf='fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"' + +eval "$(zoxide init zsh --cmd cd)" + +fastfetch + +if [[ -z $ZELLIJ ]]; then + zellij +fi