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

Add 'xonsh' shell to postflight #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 37 additions & 3 deletions portmgr/dmg/postflight.in
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ function write_setting () {
fi
{
echo -e "\n# ${OUR_STRING}: adding an appropriate ${1} variable for use with MacPorts."
echo "${ENV_COMMAND} ${1}${ASSIGN}${2}"
echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n"
echo "${ENV_COMMAND}${ENV_SEP}${1}${ASSIGN}${2}"
} >> "${HOME}/.${CONF_FILE}"
chown "${USER}" "${HOME}/.${CONF_FILE}" || echo "Warning: unable to adapt permissions on your ${HOME}/.${CONF_FILE} shell configuration file!"
echo "An appropriate ${1} variable has been added to your shell environment by the MacPorts installer."
Expand Down Expand Up @@ -237,6 +237,7 @@ case "${USHELL}" in
*/tcsh)
echo "Detected the tcsh shell."
ENV_COMMAND="setenv"
ENV_SEP=" "
ASSIGN=" "
if [[ -f "${HOME}/.tcshrc" ]]; then
CONF_FILE=tcshrc
Expand All @@ -249,6 +250,7 @@ case "${USHELL}" in
*/bash)
echo "Detected the bash shell."
ENV_COMMAND="export"
ENV_SEP=" "
ASSIGN="="
if [[ -f "${HOME}/.bash_profile" ]]; then
CONF_FILE=bash_profile
Expand All @@ -261,9 +263,22 @@ case "${USHELL}" in
*/zsh)
echo "Detected the zsh shell."
ENV_COMMAND="export"
ENV_SEP=" "
ASSIGN="="
CONF_FILE="zprofile"
;;
*/xonsh)
echo "Detected the 🐚xonsh shell."
ENV_COMMAND='$'
ENV_SEP=""
ASSIGN="="
IS_XONSH=true
if [[ -f "${HOME}/.config/xonsh/rc.xsh" ]]; then
CONF_FILE="config/xonsh/rc.xsh"
else
CONF_FILE=xonshrc
fi
;;
*)
echo "Unknown shell ($USHELL)! Please set your MacPorts compatible environment manually."
update_macports
Expand All @@ -280,7 +295,17 @@ esac
if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv PATH" | tail -n 1 | tr ":" "\n" | grep "^${BINPATH}$" > /dev/null; then
echo "Your shell already has the right PATH environment variable for use with MacPorts!"
else
write_setting PATH "\"${BINPATH}:${SBINPATH}:\$PATH\""
if $IS_XONSH; then
# ↓"${ENV_COMMAND}${ENV_SEP}${1}${ASSIGN}${2}"
# "$PATH.add('${PATH_TO_ADD}' ,front=True)"
backupASSIGN=${ASSIGN}
export ASSIGN=".add('"
write_setting PATH "${SBINPATH}',front=True)"
write_setting PATH "${BINPATH}' ,front=True)"
export ASSIGN=${backupASSIGN}
else
write_setting PATH "\"${BINPATH}:${SBINPATH}:\$PATH\""
fi
Comment on lines -283 to +308
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to add the special handling for xonsh to the write_setting function and pass the shell's name as an additional parameter. This would avoid the duplication of this conditional block for each variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would replace some of the duplication with a new variable condition in the write_setting function, and you'd have to call this function 3 times instead of 2, so will add more lines with comments to user configs, so it seems even worse

fi

# Adding our setting to the MANPATH variable only if it exists:
Expand All @@ -289,7 +314,16 @@ if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv MANPATH" > /dev/null; then
if /usr/bin/su "${USER}" -l -c "/usr/bin/printenv MANPATH" | tail -n 1 | tr ":" "\n" | grep "^${MANPAGES}$" >/dev/null; then
echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
else
write_setting MANPATH "\"${MANPAGES}:\$MANPATH\""
if $IS_XONSH; then
# ↓"${ENV_COMMAND}${ENV_SEP}${1}${ASSIGN}${2}"
# "$PATH.add('${PATH_TO_ADD}' ,front=True)"
backupASSIGN=${ASSIGN}
export ASSIGN=".add('"
write_setting MANPATH "${MANPAGES}',front=True)"
export ASSIGN=${backupASSIGN}
else
write_setting MANPATH "\"${MANPAGES}:\$MANPATH\""
fi
fi
fi

Expand Down