Dotfiles update 2025-12-24 19:26

This commit is contained in:
Aaron D. Lee
2025-12-24 19:26:21 -05:00
parent a42198383e
commit 509fd51879
3 changed files with 41 additions and 41 deletions

View File

@@ -44,7 +44,7 @@ source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m' DF_RED=$'\033[0;31m'
DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m'
DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
}
# ============================================================================
@@ -60,10 +60,10 @@ print_header() {
local datetime=$(date '+%a %b %d %H:%M')
local width=66
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_DIM}dotfiles-update${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-update${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi

View File

@@ -23,14 +23,14 @@ source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-vault"
df_print_header "dotfiles-vault "
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local width=66
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_DIM}dotfiles-vault${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
@@ -73,10 +73,10 @@ get_cipher() {
init_vault() {
print_section "Initializing Vault"
mkdir -p "$VAULT_DIR"
chmod 700 "$VAULT_DIR"
if [[ ! -f "$VAULT_FILE" ]]; then
echo "{}" | $(get_cipher) > "$VAULT_FILE"
print_success "Vault initialized"
@@ -90,9 +90,9 @@ decrypt_vault() {
echo "{}"
return
fi
local cipher=$(get_cipher)
case "$cipher" in
age)
age -d -i "$HOME/.age/keys.txt" "$VAULT_FILE" 2>/dev/null || echo "{}"
@@ -106,7 +106,7 @@ decrypt_vault() {
encrypt_vault() {
local data="$1"
local cipher=$(get_cipher)
case "$cipher" in
age)
echo "$data" | age -R "$HOME/.age/keys.txt" > "$VAULT_FILE"
@@ -124,39 +124,39 @@ encrypt_vault() {
vault_set() {
local key="$1"
local value="${2:-}"
if [[ -z "$key" ]]; then
print_error "Usage: vault set <key> [value]"
exit 1
fi
if [[ -z "$value" ]]; then
read -s -p "Enter value for $key: " value
echo ""
fi
local current=$(decrypt_vault)
if command -v jq &> /dev/null; then
local updated=$(echo "$current" | jq --arg k "$key" --arg v "$value" '.[$k] = $v')
else
local updated="{\"$key\": \"$value\"}"
fi
encrypt_vault "$updated"
print_success "Secret stored: $key"
}
vault_get() {
local key="$1"
if [[ -z "$key" ]]; then
print_error "Usage: vault get <key>"
exit 1
fi
local vault=$(decrypt_vault)
if command -v jq &> /dev/null; then
echo "$vault" | jq -r ".\"$key\" // \"\"" | grep -v "^$"
else
@@ -166,9 +166,9 @@ vault_get() {
vault_list() {
print_section "Secrets"
local vault=$(decrypt_vault)
if command -v jq &> /dev/null; then
echo "$vault" | jq -r 'keys[]' | while read key; do
echo -e " ${DF_CYAN}${DF_NC} $key"
@@ -178,36 +178,36 @@ vault_list() {
echo -e " ${DF_CYAN}${DF_NC} $key"
done
fi
echo ""
}
vault_delete() {
local key="$1"
if [[ -z "$key" ]]; then
print_error "Usage: vault delete <key>"
exit 1
fi
local vault=$(decrypt_vault)
if command -v jq &> /dev/null; then
local updated=$(echo "$vault" | jq "del(.\"$key\")")
else
print_error "jq required for delete operation"
exit 1
fi
encrypt_vault "$updated"
print_success "Secret deleted: $key"
}
vault_shell() {
print_section "Loading secrets into environment"
local vault=$(decrypt_vault)
if command -v jq &> /dev/null; then
echo "$vault" | jq -r 'to_entries[] | "export \(.key)=\"\(.value)\""'
else
@@ -218,17 +218,17 @@ vault_shell() {
vault_export() {
local dest="${1:-.}"
if [[ -z "$dest" ]]; then
print_error "Usage: vault export <filename>"
exit 1
fi
if [[ -f "$dest" ]]; then
print_error "File already exists: $dest"
exit 1
fi
cp "$VAULT_FILE" "$dest"
chmod 600 "$dest"
print_success "Vault exported to: $dest"
@@ -236,17 +236,17 @@ vault_export() {
vault_import() {
local src="${1:-}"
if [[ -z "$src" ]]; then
print_error "Usage: vault import <filename>"
exit 1
fi
if [[ ! -f "$src" ]]; then
print_error "File not found: $src"
exit 1
fi
cp "$src" "$VAULT_FILE"
chmod 600 "$VAULT_FILE"
print_success "Vault imported from: $src"
@@ -254,26 +254,26 @@ vault_import() {
vault_status() {
print_section "Vault Status"
if [[ ! -d "$VAULT_DIR" ]]; then
echo -e " ${DF_YELLOW}${DF_NC} Vault not initialized"
return
fi
if [[ ! -f "$VAULT_FILE" ]]; then
echo -e " ${DF_YELLOW}${DF_NC} Vault file not found"
return
fi
local size=$(du -h "$VAULT_FILE" | cut -f1)
local modified=$(stat -c %y "$VAULT_FILE" 2>/dev/null | cut -d' ' -f1 || stat -f '%Sm' "$VAULT_FILE" 2>/dev/null)
echo -e " ${DF_CYAN}Location:${DF_NC} $VAULT_FILE"
echo -e " ${DF_CYAN}Size:${DF_NC} $size"
echo -e " ${DF_CYAN}Modified:${DF_NC} $modified"
echo -e " ${DF_CYAN}Encryption:${DF_NC} $(get_cipher)"
echo -e " ${DF_CYAN}Permissions:${DF_NC} $(stat -c '%a' $VAULT_FILE 2>/dev/null || stat -f '%a' "$VAULT_FILE")"
echo ""
}
@@ -283,11 +283,11 @@ vault_status() {
main() {
print_header
if [[ ! -d "$VAULT_DIR" ]]; then
init_vault
fi
case "${1:-list}" in
init)
init_vault

View File

@@ -47,7 +47,7 @@ done
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-version"
df_print_header "dotfiles-version "
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"