Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mailsync: Check for ZDOTDIR when looking for environmental variables inside .zprofile and .zshrc #637

Merged
merged 1 commit into from
Jan 23, 2021

Conversation

BachoSeven
Copy link
Contributor

Using $HOME/.z{profile,shrc} as a fallback, of course.

~/.profile is not necessarily present when using zsh for login, and setting $ZDOTDIR in ~/.zshenv allows moving .zprofile and .zshrc there.

inside .zprofile and .zshrc.

~/.profile is not necessarily present when using zsh for login and
setting $ZDOTDIR in ~/.zshenv
@LukeSmithxyz LukeSmithxyz merged commit 3bd61cb into LukeSmithxyz:master Jan 23, 2021
@BachoSeven
Copy link
Contributor Author

I've realised this is not working, because ZDOTDIR is not known to mailsync. This issue also applies to #630, in those cases where ~/.profile is not present. For instance, I set both ZDOTDIR and XDG_CONFIG_HOME in ~/.zshenv.

Since this is specific to zsh, we could check if SHELL is zsh, and then run a similar eval "$(grep ...)" command beforehand to export the XDG_CONFIG_HOME and ZDOTDIR variables from ~/.zshenv, since this seems to be the proper way to change the location of zsh files. If you think this is a good solution, I can make another PR.

@BachoSeven
Copy link
Contributor Author

Okay, SHELL is obviously /bin/sh, but we could use

awk -F: -v user="$USER" '$1 == user {print $NF}' /etc/passwd

which works (source)

@BachoSeven
Copy link
Contributor Author

BachoSeven commented Jan 24, 2021

This works (just before the eval "$(grep ...)" line):

# Workaround for zsh users who only have .zshenv in their $HOME.
usersh="$(awk -F: -v user="$USER" '$1 == user {print $NF}' /etc/passwd)"
[ "$usersh" = /usr/bin/zsh ] && eval "$(grep -h -- \
	"^\s*\(export \)\?\(ZDOTDIR\|XDG_CONFIG_HOME\|XDG_DATA_HOME\)=" \
	"$HOME/.zshenv" 2>/dev/null)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants