From 1b17c35f4bff8193f86c106bdcd119079311de43 Mon Sep 17 00:00:00 2001 From: druckdev Date: Mon, 12 Apr 2021 17:13:37 +0200 Subject: [PATCH] zsh: Add zlogout to kill ssh-agent On system where my dotfiles are only partially installed (e.g. only the shell) for the environment variables defined in the zprofile to take affect, every terminal instance needs to execute zsh a login-shell. This lead to numerous instances of the ssh-agent that were not killed when exiting the shell. As I still need the correct env-vars like SSH_AGENT_PID in every shell I cannot just pgrep and execute the agent respectively. This adds a zlogout that kills the agent spawned in the current shell. It also stops `exec`ing `startx` as then the zlogout is not read. --- .config/zsh/.zlogout | 1 + .config/zsh/.zprofile | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .config/zsh/.zlogout diff --git a/.config/zsh/.zlogout b/.config/zsh/.zlogout new file mode 100644 index 0000000..002ff41 --- /dev/null +++ b/.config/zsh/.zlogout @@ -0,0 +1 @@ +[[ -z $SSH_AGENT_PID ]] || kill "$SSH_AGENT_PID" diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile index d093191..64449c6 100644 --- a/.config/zsh/.zprofile +++ b/.config/zsh/.zprofile @@ -94,4 +94,8 @@ if (( $+commands[dircolors] )); then fi # Automatically start X on login after boot. -[[ -n $DISPLAY || $XDG_VTNR -ne 1 ]] || exec startx +# Do not use exec so that the zlogout is still read. +if command -v startx &>/dev/null && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then + startx + exit $? +fi