You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

241 lines
6.4 KiB

# Start configuration added by Zim install {{{
#
# User configuration sourced by interactive shells
#
# -----------------
# Zsh configuration
# -----------------
#
# Input/output
#
setopt CLOBBER # enable >>
# Set editor default keymap to emacs (`-e`) or vi (`-v`)
bindkey -e
# Prompt for spelling correction of commands.
#setopt CORRECT
# Customize spelling correction prompt.
#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
# Remove path separator from WORDCHARS.
WORDCHARS=${WORDCHARS//[\/]}
# -----------------
# Zim configuration
# -----------------
# Use degit instead of git as the default tool to install and update modules.
#zstyle ':zim:zmodule' use 'degit'
# --------------------
# Module configuration
# --------------------
#
# git
#
# Set a custom prefix for the generated aliases. The default prefix is 'G'.
#zstyle ':zim:git' aliases-prefix 'g'
#
# input
#
# Append `../` to your input for each `.` you type after an initial `..`
#zstyle ':zim:input' double-dot-expand yes
#
# termtitle
#
# Set a custom terminal title format using prompt expansion escape sequences.
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
# If none is provided, the default '%n@%m: %~' is used.
#zstyle ':zim:termtitle' format '%1~'
#
# zsh-autosuggestions
#
# Disable automatic widget re-binding on each precmd. This can be set when
# zsh-users/zsh-autosuggestions is the last module in your ~/.zimrc.
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
# Customize the style that the suggestions are shown with.
# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style
#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242'
#
# zsh-syntax-highlighting
#
# Set what highlighters will be used.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
# Customize the main highlighter styles.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
#typeset -A ZSH_HIGHLIGHT_STYLES
#ZSH_HIGHLIGHT_STYLES[comment]='fg=242'
# ------------------
# Initialize modules
# ------------------
ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
if (( ${+commands[curl]} )); then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
else
mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
fi
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
# Initialize modules.
source ${ZIM_HOME}/init.zsh
# ------------------------------
# Post-init module configuration
# ------------------------------
#
# History
#
unsetopt SHARE_HISTORY
setopt EXTENDED_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
export HISTTIMEFORMAT="[%F %T] "
export HISTFILE=~/.zsh_history
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
#alias history='history -E 0'
#
# zsh-history-substring-search
#
zmodload -F zsh/terminfo +p:terminfo
# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
#for key ('^[[A' '^P' ${terminfo[kcuu1]}) bindkey ${key} history-substring-search-up
#for key ('^[[B' '^N' ${terminfo[kcud1]}) bindkey ${key} history-substring-search-down
#for key ('k') bindkey -M vicmd ${key} history-substring-search-up
#for key ('j') bindkey -M vicmd ${key} history-substring-search-down
#unset key
# }}} End configuration added by Zim install
# screen window naming
if [[ "$TERM" == screen* ]]; then
screen_set_window_title () {
if [ -z "$SLABEL" ]
then
local HPWD="$PWD"
case $HPWD in
$HOME) HPWD="~";;
$HOME/*) HPWD="~${HPWD#$HOME}";;
esac
printf '\ek%s\e\\' "$HPWD"
else
printf '\ek%s\e\\' "$SLABEL"
fi
}
PROMPT_COMMAND="screen_set_window_title; $PROMPT_COMMAND"
fi
edit_secure() {
# Using $HOME is safer than ~ inside scripts
local plain_file="$HOME/.scripts/secure_functions.sh"
local encrypted_file="${plain_file}.gpg"
# 1. Check if the encrypted file exists
if [[ -f "$encrypted_file" ]]; then
# It exists: Decrypt it so we can edit
gpg -q -o "$plain_file" -d "$encrypted_file" || return 1
else
# It doesn't exist: Create the directory just in case
mkdir -p "$(dirname "$plain_file")"
echo "Creating new secure file..."
fi
# 2. Open editor (Defaults to nano if EDITOR is not set)
${EDITOR:-nano} "$plain_file"
# 3. Encrypt and Cleanup
# Only encrypt if the file actually exists (in case you exited editor without saving)
if [[ -f "$plain_file" ]]; then
echo "Encrypting..."
# Encrypt (-c) AND THEN remove the plaintext file (rm) only if encryption succeeded (&&)
gpg -c "$plain_file" && rm "$plain_file"
echo "Done. Secrets saved to $encrypted_file"
else
echo "Aborted: No file saved."
fi
}
_run_secure_func() {
local func_name="$1"
local encrypted_file="$HOME/.scripts/secure_functions.sh.gpg"
[[ -f "$encrypted_file" ]] || {
echo "Error: Encrypted file not found" >&2
return 1
}
# SECURITY CRITICAL: Run in isolated subshell with history disabled
(
# Cross-shell history disabling
unset HISTFILE # Disables history file in BOTH shells
HISTSIZE=0 # Bash: disable in-memory history
SAVEHIST=0 # Zsh: disable history saving
# Zsh-specific hardening (safe to run in bash too)
[ -n "${ZSH_VERSION:-}" ] && setopt no_history no_hist_save no_hist_verify 2>/dev/null || true
# Decrypt → source → execute (all in-memory)
gpg --quiet --decrypt "$encrypted_file" 2>/dev/null | {
source /dev/stdin
"$func_name"
}
)
# Optional: Invalidate cache after use (prevents lingering secrets)
#{ sleep 1; echo RELOADAGENT | gpg-connect-agent >/dev/null 2>&1; } &
}
test_secure() {
_run_secure_func _test_secure
}
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
alias bat=batcat
alias ll='eza --icons=auto -T --level 2 -lah --group-directories-first --color=always | less'
alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
export VCPKG_ROOT=/opt/vcpkg
. "$HOME/.local/bin/env"