Last active
January 30, 2017 06:11
-
-
Save yamachu/faec9bbe5bbe21ab814f1ad59e8cbb84 to your computer and use it in GitHub Desktop.
monoのバージョンを簡単に変えたかった.macでbrewとかじゃなくてインストーラーで入れてる場合はこれで対応できるはず
This file contains 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 python3 | |
import itertools | |
import sys | |
import subprocess | |
process = subprocess.run('ls /Library/Frameworks/Mono.framework/Versions/', | |
shell=True, | |
stdout=subprocess.PIPE) | |
versions = [v for v in process.stdout.decode('utf-8').strip().split() if v != 'Current'] | |
column_max = 9 if len(versions) > 9 else len(versions) | |
versions_list = [[f for f in feats] for feats in itertools.zip_longest(*[iter(versions)]*column_max)] | |
page_index = 0 | |
def print_select_field(colums, column_max = 9, has_next = False, is_initialize = False): | |
if not is_initialize: | |
for _ in range(column_max + 2): | |
print('\033[2A', file=sys.stderr) | |
print('\033[2K', file=sys.stderr) | |
print('\033[2A', file=sys.stderr) | |
pass | |
for i, col in enumerate(colums, 1): | |
if col is not None: | |
print(f'{i}. {col}') | |
else: | |
print('') | |
if has_next: print('0. next') | |
print('Select with number key') | |
process = subprocess.run('ls -l /Library/Frameworks/Mono.framework/Versions/Current', shell=True, stdout=subprocess.PIPE) | |
print(f'Current is {process.stdout.decode("utf-8").strip().split()[-1]}') | |
print_select_field(versions_list[page_index], column_max, len(versions_list) != 1, True) | |
while True: | |
n = int(input()) | |
if n == 0: | |
page_index = (page_index + 1) % len(versions_list) | |
print_select_field(versions_list[page_index], column_max, len(versions_list) != 1) | |
elif 0 < n and n < column_max + 1: | |
selected_version = versions_list[page_index][n - 1] | |
proc = subprocess.run(f'sudo ln -snf /Library/Frameworks/Mono.framework/Versions/{selected_version} /Library/Frameworks/Mono.framework/Versions/Current', shell=True) | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment