|
|
|
@ -163,79 +163,15 @@ if [[ "$TERM" == screen* ]]; then |
|
|
|
PROMPT_COMMAND="screen_set_window_title; $PROMPT_COMMAND" |
|
|
|
PROMPT_COMMAND="screen_set_window_title; $PROMPT_COMMAND" |
|
|
|
fi |
|
|
|
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 bat=batcat |
|
|
|
alias ll='eza --icons=auto -T --level 2 -lah --group-directories-first --color=always | less' |
|
|
|
alias ll='eza --icons=auto -T --level 2 -lah --group-directories-first --color=always | less' |
|
|
|
|
|
|
|
alias gl="git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all" |
|
|
|
|
|
|
|
alias git-config-pb='git config user.name "Łukasz Chodyła" && git config user.email "lukasz.chodyla@platformabiznesu.net"' |
|
|
|
|
|
|
|
alias git-cofig-ch='git config user.name "chodak166" && git config user.email "chodak166@op.pl" |
|
|
|
alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME' |
|
|
|
alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME' |
|
|
|
|
|
|
|
|
|
|
|
export VCPKG_ROOT=/opt/vcpkg |
|
|
|
export VCPKG_ROOT=/opt/vcpkg |
|
|
|
|
|
|
|
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
|
|
|
|
|
|
|
|
|
|
|
. "$HOME/.local/bin/env" |
|
|
|
. "$HOME/.local/bin/env" |
|
|
|
|