summarylogtreecommitdiffstats
path: root/archlinux-python.sh
blob: 2062fa650237afc9b186a35974380f387f659970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
currentpath="$(pwd)"
available_py="$(find /usr/bin -type l -iname "python[0-9]" | cut -f4 -d '/')"
current_version="$(readlink /usr/bin/python)"

function show_help () {
	echo "archlinux-python <COMMAND>"
	echo ""
	echo "COMMAND:"
	echo "        status          List installed Python-Versions"
	echo "        show-links      Show current links"
	echo "        set <python*>   Set python-Version as default"
}

function show_current_status () {
	for i in $available_py; do
		if [ "$i" = "$current_version" ]
			then
				echo "  $i (default)"
		else
			echo "  $i"
		fi
	done
}

if [ -z "$1" ]
	then
		show_help
elif [ "$1" = "status" ] 
	then
		echo "Available Python-Versions:"
		show_current_status				

elif [ "$1" = "set" ] 
	then
		if [ -z "$2" ]
			then
				echo "please specify a pytnon-version you want to set. options are:"
				show_current_status
		else
			for i in $available_py; do
				if [ "$i" = "$2" ]
					then
						match=$i
				fi
			done
			if [ ! -z "$match" ]
				then
					echo "set $2 as default"
					cd /usr/bin/
					sudo rm python
					sudo ln -s ${match} python
					sudo rm python-config
					sudo ln -s ${match}-config python-config
					cd $currentpath
			else
					echo "$2 is not a valid Python-Version"
			fi
		fi
	elif [ "$1" = "show-links" ]
		then
			ls -l /usr/bin/python | cut -f10,11,12 -d ' '
			ls -l /usr/bin/python-config | cut -f10,11,12 -d ' '
fi