Created
February 7, 2021 11:37
-
-
Save deeuu/0cf56150ba305d135ca4b9d25e70ce25 to your computer and use it in GitHub Desktop.
Bash script to install the xonsh shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download and run the script:
curl -L https://gist.github.com/deeuu/0cf56150ba305d135ca4b9d25e70ce25/raw | bash