Move to a setup using GNU Stow instead of my system which copied files and kept a .lock dir

This commit is contained in:
Martin Larsson 2024-04-07 02:02:09 +02:00
parent 26d27dc457
commit 6a7885bdbb
7 changed files with 50 additions and 158 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
.DS_Store .DS_Store
/.lock

30
.zshrc
View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -1,6 +0,0 @@
# replace <user> with your username (output of: whoami).
# replace <hash> 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 <yabai> with the path to the yabai binary (output of: which yabai).
larssonmartin1998 ALL=(root) NOPASSWD: sha256:5c729cfc728ec8780c14d6fe0bfd74376bd2f057960b542c41106d8e8c5df787 /opt/homebrew/bin/yabai --load-sa

50
zsh/.zshrc Normal file
View file

@ -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