Last active
July 27, 2017 12:08
-
-
Save MatiMax/76fb5e3f0c5483bf3186e2cb2447ad46 to your computer and use it in GitHub Desktop.
This fish-shell script detects and switches the Swift version. It has been tested with fish-shell version 2.2.0 under Ubuntu Linux 16.04 LTS.
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/fish | |
set SWIFT_PATH /opt | |
set swift_versions (sudo find $SWIFT_PATH -maxdepth 1 -name "swift[0-9][0-9][0-9]" -type d -printf "%f\n" | sort) | |
set swift_active_version (stat $SWIFT_PATH/swift -c "%N" | sed -r "s/.+(swift[0-9][0-9][0-9]).+/\1/g") | |
echo -e "\n\e[44;1mI found these Swift versions:\e[0m" | |
set i 1 | |
for v in $swift_versions | |
echo -en " $i) $v" | |
if [ $v = $swift_active_version ] | |
echo -n " (currently active)" | |
end | |
echo | |
set i (math $i + 1) | |
end | |
read -p "echo -e '\nSwitch to Swift version: '" selected_version | |
if [ "$selected_version" = "" ] | |
echo -e "\e[32mNo changes are made. Bye.\e[0m\n" | |
exit | |
else | |
set selected_version (math $selected_version) | |
if [ $selected_version -lt 1 -o $selected_version -ge $i ] | |
echo -e "\e[31mInvalid selection. Bye.\e[0m\n" | |
exit | |
end | |
echo -en "\e[42mSwitching to version \e[1m$swift_versions[$selected_version]\e[22m... " | |
sudo rm -f $SWIFT_PATH/swift | |
sudo ln -s $SWIFT_PATH/$swift_versions[$selected_version] $SWIFT_PATH/swift | |
echo -e "Done.\e[0m\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment