2025-05-09 13:34:28 +02:00
export PATH = "/snap/bin: $HOME /.local/bin: $HOME /dotfiles/scripts: $PATH "
2025-05-08 09:10:37 +02:00
export XDG_CONFIG_HOME = " $HOME /.config" # Fix nvim bug
2025-08-05 09:56:03 +02:00
2025-08-12 16:14:56 +02:00
2023-10-31 12:34:17 +01:00
[[ -z $SSH_AUTH_SOCK ]] || export FORWARD_SOCK = $SSH_AUTH_SOCK
2021-10-23 17:41:05 +02:00
2017-04-12 10:07:44 +02:00
[[ -f ~/.zsh/.powerline_config ]] && source ~/.zsh/.powerline_config
2018-07-29 16:26:51 +02:00
2025-01-08 09:49:46 +01:00
if [[ -f ~/.zsh/.shared_config ]] && [[ " $SUDO_USER " != "fabian" ]] ; then
shared_config = 1
else
shared_config = 0
fi
2025-12-27 14:34:54 +01:00
# Workaround for HOME directory in sudo nvim (caused by snap)
if [[ " $USER " == "root" ]] ; then
if [[ ! -e /home/root ]] ; then
ln -s /root/ /home/root
elif [[ ! -e /home/root/.config ]] ; then
ln -s /root/.config /home/root/.config
fi
fi
2025-08-05 09:56:03 +02:00
if [[ -f ~/.zsh/.shared_config ]] ; then
touch ~/.config/nvim/.shared_config
fi
2026-07-05 17:27:56 +02:00
# On shell start, bring ~/dotfiles up to date by fast-forwarding the CURRENT
# branch to its upstream only. Never rebase or stash in the background: if the
# branch diverged or local edits block it, warn and leave it for a manual pull.
# Per-branch, so `server` on each device fast-forwards to origin/server.
2025-08-05 14:34:08 +02:00
update_dotfiles() {
2026-07-05 17:27:56 +02:00
local repo = " $HOME /dotfiles"
git -C " $repo " fetch --quiet 2>/dev/null || return
git -C " $repo " rev-parse --abbrev-ref '@{u}' >/dev/null 2>& 1 || return # no upstream
git -C " $repo " merge-base --is-ancestor '@{u}' HEAD 2>/dev/null && return # already current
git -C " $repo " merge --ff-only --quiet '@{u}' 2>/dev/null \
|| print -u2 "⚠ dotfiles: $( git -C " $repo " symbolic-ref --short HEAD) can't fast-forward to @{u} — run: git -C ~/dotfiles pull"
2025-08-05 12:38:26 +02:00
}
2026-07-05 17:27:56 +02:00
update_dotfiles & !
2025-08-05 14:34:08 +02:00
if [ " $shared_config " -eq 0 ] ; then
update_dotfiles 2>& 1 & !
2025-08-12 16:14:56 +02:00
export GIT_AUTHOR_NAME = "Fabian Ising"
export GIT_AUTHOR_EMAIL = "f.ising@fh-muenster.de"
export GIT_COMMITTER_NAME = $GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL = $GIT_AUTHOR_EMAIL
2025-08-05 12:38:26 +02:00
fi
2026-07-10 13:30:11 +02:00
# On shell start, check the security tools repo for upstream updates and print a
# one-line notice if the checkout is behind. Notify only (never auto-pull). This
# stays read-only so it works even when the repo lives in root-owned /opt/tools:
# - `safe.directory=*` sidesteps git's "dubious ownership" refusal on a repo
# owned by root, which would otherwise fail every git command.
# - `ls-remote` queries the remote without writing into .git (a normal user
# can't write a root-owned .git, so `fetch` would fail there).
# Uses the first candidate that is a git checkout; covers global and per-user layouts.
check_tools_repo() {
local repo branch remote mergeref remote_sha local_sha cmd
for repo in /opt/tools " $HOME /tools" " $HOME /tools/tools-repo" ; do
local -a g =( git -c 'safe.directory=*' -C " $repo " )
$g rev-parse --is-inside-work-tree >/dev/null 2>& 1 || continue
branch = $( $g symbolic-ref --short HEAD 2>/dev/null) || return
remote = $( $g config "branch. $branch .remote" 2>/dev/null) || return # no upstream
mergeref = $( $g config "branch. $branch .merge" 2>/dev/null) || return
remote_sha = $( $g ls-remote " $remote " " $mergeref " 2>/dev/null | awk '{print $1}' )
local_sha = $( $g rev-parse HEAD 2>/dev/null)
[[ -n " $remote_sha " && -n " $local_sha " ]] || return # remote unreachable
[[ " $remote_sha " == " $local_sha " ]] && return # already current
$g merge-base --is-ancestor " $remote_sha " HEAD 2>/dev/null && return # remote is an ancestor: ahead/equal (also true if we lack the object -> falls through to "behind")
[[ -w " $repo /.git" ]] && cmd = "git -C $repo pull" || cmd = "sudo git -C $repo pull"
print -u2 "⬆ tools: updates available in $repo — run: $cmd "
return
done
}
check_tools_repo & !
2022-09-06 13:25:54 +02:00
# Load Antidote
2022-10-06 16:36:52 +02:00
mkdir -p ${ ZDOTDIR :- ~ } /.cache/zsh
2022-09-27 13:18:21 +02:00
static_file = ${ ZDOTDIR :- ~ } /.cache/zsh/.zsh_plugins.zsh
2025-01-08 09:49:46 +01:00
if [ $shared_config -eq 0 ] ; then
2024-10-14 16:02:14 +02:00
plugins_txt = ${ ZDOTDIR :- ~ } /.zsh/.zsh_plugins.txt
2024-10-14 16:38:40 +02:00
# Vi mode
bindkey -v
VI_MODE_SET_CURSOR = true
2024-10-14 16:02:14 +02:00
else
plugins_txt = ${ ZDOTDIR :- ~ } /.zsh/.zsh_plugins_shared.txt
2025-01-08 10:39:28 +01:00
static_file = ${ ZDOTDIR :- ~ } /.cache/zsh/.zsh_shared_plugins.zsh
2024-10-14 16:02:14 +02:00
fi
2022-09-06 10:50:17 +02:00
# clone antidote if necessary
if ! [[ -e ${ ZDOTDIR :- ~ } /.antidote ]] ; then
git clone https://github.com/mattmc3/antidote.git ${ ZDOTDIR :- ~ } /.antidote
fi
2017-04-12 10:07:44 +02:00
2024-07-19 13:25:17 +02:00
#zstyle ':omz:plugins:docker' legacy-completion yes
zstyle ':completion:*:ssh:*' hosts off
2025-08-04 11:47:52 +02:00
zstyle ':completion:*:scp:*' hosts off
2024-07-19 13:25:17 +02:00
2025-08-04 11:47:52 +02:00
# Run rehash for external commands
zstyle ":completion:*:commands" rehash 1
2022-09-06 10:50:17 +02:00
# source antidote and load plugins from `${ZDOTDIR:-~}/.zsh_plugins.txt`
source ${ ZDOTDIR :- ~ } /.antidote/antidote.zsh
2022-09-06 13:25:54 +02:00
antidote load ${ plugins_txt } ${ static_file }
2023-10-31 12:34:17 +01:00
export SSH_REAL_SOCK = $SSH_AUTH_SOCK
[[ -z $FORWARD_SOCK ]] || export SSH_AUTH_SOCK = $FORWARD_SOCK
2022-09-06 13:25:54 +02:00
setopt interactivecomments
2025-07-31 15:24:28 +02:00
# History options
HISTSIZE = 100000 # Set the amount of lines you want saved
SAVEHIST = 100000 # This is required to actually save them, needs to match with HISTSIZE
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Don\'t record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don\'t record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don\'t write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
2022-09-06 13:25:54 +02:00
# Clear screen by ctrl+q
bindkey '^q' clear-screen
2017-04-12 10:07:44 +02:00
2026-07-10 14:56:07 +02:00
(( $+commands[ nvim] )) && alias vim = nvim
2019-08-22 15:27:20 +02:00
alias sudo = 'sudo '
2023-07-18 14:54:43 +02:00
alias cgrep = "grep --color=always"
2026-07-10 14:56:07 +02:00
(( $+commands[ nvim] )) && export EDITOR = 'nvim'
(( $+commands[ nvim] )) && export VISUAL = 'nvim'
2019-02-28 13:36:24 +01:00
2024-03-26 14:10:18 +01:00
# Allow access to all libvirt vms
export LIBVIRT_DEFAULT_URI = "qemu:///system"
2019-08-22 15:27:20 +02:00
alias ls = "ls --color=always"
2020-10-14 11:05:01 +02:00
2026-07-10 11:37:46 +02:00
# Use safecp/safemv from the tools-repo when available
(( $+commands[ safecp] )) && alias cp = safecp
(( $+commands[ safemv] )) && alias mv = safemv
2020-10-14 11:05:01 +02:00
delzip() {
unzip -Z -1 " $@ " | xargs -I{} rm -rf {}
}
# mitmproxy
export MITMPROXY_SSLKEYLOGFILE = "~/.mitmproxy/sslkeylogfile.txt"
2021-10-27 14:56:12 +02:00
[[ -f ~/.zsh/.mac_config ]] && source ~/.zsh/.mac_config
2021-11-09 08:36:16 +01:00
2024-10-07 14:29:02 +02:00
# Workaround for async issues https://github.com/romkatv/powerlevel10k/issues/1554
unset ZSH_AUTOSUGGEST_USE_ASYNC
2021-11-09 08:36:16 +01:00
# Powerlevel 10k
2021-10-27 15:02:27 +02:00
# Remove padding on right side
ZLE_RPROMPT_INDENT = 0
2021-11-09 08:36:16 +01:00
# To customize prompt, run `p10k configure` or edit ~/dotfiles/zsh/.p10k.zsh.
2024-03-19 15:13:38 +01:00
function load_p10k() {
2025-01-08 09:49:46 +01:00
if zmodload zsh/terminfo && (( terminfo[ colors] >= 256 )) && [ $shared_config -eq 0 ] ; then
2024-10-13 08:41:25 +02:00
[[ ! -f ~/dotfiles/zsh/.p10k.zsh ]] || source ~/dotfiles/zsh/.p10k.zsh
else
[[ ! -f ~/dotfiles/zsh/.p10k_shared.zsh ]] || source ~/dotfiles/zsh/.p10k_shared.zsh
fi
2024-03-19 15:13:38 +01:00
}
load_p10k
2024-10-14 15:50:37 +02:00
#
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT = ${${ (s.:.)widgets[self-insert] } [2,3] }
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
2024-10-14 15:54:06 +02:00
# https://github.com/zsh-users/zsh-autosuggestions/issues/351
ZSH_AUTOSUGGEST_CLEAR_WIDGETS +=( bracketed-paste)
2024-10-14 15:50:37 +02:00
2024-03-19 15:13:38 +01:00
export LANG = "en_US.UTF-8"
export LC_CTYPE = "en_US.UTF-8"
export TIME_STYLE = "long-iso"
2025-08-12 16:20:09 +02:00
[[ -f ~/.zsh/.user_config ]] && source ~/.zsh/.user_config
[[ -f ~/.zsh/.virtual_env_config.zsh ]] && source ~/.zsh/.virtual_env_config.zsh
[[ -f ~/.zsh/.local_config ]] && source ~/.zsh/.local_config
[[ -f ~/.zsh/.os_config.zsh ]] && source ~/.zsh/.os_config.zsh