Skip to content

Instantly share code, notes, and snippets.

@deeuu
Created February 7, 2021 11:37
Show Gist options
  • Save deeuu/0cf56150ba305d135ca4b9d25e70ce25 to your computer and use it in GitHub Desktop.
Save deeuu/0cf56150ba305d135ca4b9d25e70ce25 to your computer and use it in GitHub Desktop.
Bash script to install the xonsh shell
#!/usr/bin/env bash
set -e
VIRTUAL_ENV_PATH=${VIRTUAL_ENV_PATH:-"$HOME/.local/share/virtualenvs"}
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
done
}
function check_py_version {
VERSION=$(python3 --version)
echo "$VERSION" | grep 'Python 3.[5-9]' > /dev/null
if [[ $? == 1 ]]; then
echo "Found $VERSION, but xonsh requires Python 3.5+"
exit 1
fi
}
function install_xonsh {
XONSH_ENV_DIR="$VIRTUAL_ENV_PATH/xonsh"
if [[ -d "$XONSH_ENV_DIR" ]]; then
echo "Virtual env directory $XONSH_ENV_DIR already exists"
exit 1
fi
python3 -m venv "$XONSH_ENV_DIR"
source "$XONSH_ENV_DIR/bin/activate"
pip install xonsh
}
function update_path_profile {
NEWPATH="\$HOME/${VIRTUAL_ENV_PATH#$HOME/}/xonsh/bin:\$PATH"
EXPORT_PATH="export PATH=\"$NEWPATH\""
MSG="Add '$EXPORT_PATH' to ~/.profile?"
yes_or_no "$MSG" || exit 0
echo $EXPORT_PATH >> ~/.profile
}
function main {
check_py_version
install_xonsh
update_path_profile
}
main
@deeuu
Copy link
Author

deeuu commented Feb 7, 2021

Download and run the script: curl -L https://gist.github.com/deeuu/0cf56150ba305d135ca4b9d25e70ce25/raw | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment