def remove_account(): config_obj = read_config_file() if len(config_obj) == 0: logger.info("No config found.") else: available_servers = [] for i in range(0, len(config_obj)): if 'Host' in config_obj[i]: available_servers.append({ 'key': i, 'name': config_obj[i]['Host'], 'value': i, }) host_ques = [{ 'type': 'list', 'name': 'ssh-hosts', 'message': 'Select host to remove:', 'choices': available_servers + retrieve_questions('default_exits') }] selected_host = prompt(host_ques, style=style) default_menu_or_exit(selected_host['ssh-hosts']) confirm_removal = prompt(retrieve_questions('confirm_remove'), style=style) if confirm_removal['remove_confirmation']: config_obj.pop(selected_host['ssh-hosts']) write_config_to_file(config_obj) logger.info("Finished removing config.") else: init()
def remove_account(): config_obj = read_config_file() if len(config_obj) == 0: logger.info("No config found.") else: host_ques = [{ 'type': 'list', 'name': 'git-hosts', 'message': 'Select host to remove:', 'choices': list(config_obj.keys()) + retrieve_questions('default_exits') }] selected_host = prompt(host_ques, style=style) default_menu_or_exit(selected_host['git-hosts']) confirm_removal = prompt(retrieve_questions('confirm_remove'), style=style) if confirm_removal['remove_confirmation']: del config_obj[selected_host['git-hosts']] write_config_to_file(config_obj) logger.info("Account removal successful.") else: init()
def init(): selected = prompt(retrieve_questions('zsh', 'init'), style=style) if selected['zsh'] == "install": script_path = get_script_path(dir_path, "install-zsh.sh") subprocess.run(['bash', script_path]) elif selected['zsh'] == "ls-themes": script_path = get_script_path(dir_path, "ls-themes.sh") subprocess.run(['bash', script_path]) elif selected['zsh'] == "set-theme": script_path = get_script_path(dir_path, "set-theme.sh") inp = prompt(retrieve_questions('zsh', 'set_theme_ques'), style=style) subprocess.run(['bash', script_path, inp['set_theme_name']]) else: default_menu_or_exit(selected['zsh']) init()
def init(): selected = prompt(retrieve_questions('ssh', 'init'), style=style) if selected['ssh-config'] == "add": inp_username = prompt(retrieve_questions('ssh', 'add_server_username'), style=style) inp_host = prompt(retrieve_questions('ssh', 'add_server_host'), style=style) inp_alias = prompt(retrieve_questions('ssh', 'add_server_alias'), style=style) inp_id_rsa = prompt(retrieve_questions('ssh', 'path_to_id_rsa'), style=style) add_account(inp_host['add_server_host'], inp_username['add_server_username'], inp_alias['add_server_alias'], inp_id_rsa['id_rsa_path']) elif selected['ssh-config'] == "remove": remove_account() elif selected['ssh-config'] == "connect-to": connect_to_server() else: default_menu_or_exit(selected['ssh-config']) init()
def init(): selected = prompt(retrieve_questions('git', 'init'), style=style) if selected['git-config'] == "add": inp_username = prompt(retrieve_questions('git', 'add_account_username'), style=style) inp_email = prompt(retrieve_questions('git', 'add_account_email'), style=style) inp_hostname = prompt(retrieve_questions('git', 'add_account_hostname'), style=style) add_account(inp_email['add_acc_email'], inp_username['add_acc_username'], inp_hostname['add_acc_hostname']) elif selected['git-config'] == "remove": remove_account() elif selected['git-config'] == "switch": switch_account() else: default_menu_or_exit(selected['git-config']) init()
def switch_account(): config_obj = read_config_file() if len(config_obj) == 0: logger.info("No config found.") else: host_ques = [{ 'type': 'list', 'name': 'git-hosts', 'message': 'Select host to switch to:', 'choices': list(config_obj.keys()) + retrieve_questions('default_exits') }] selected_host = prompt(host_ques, style=style) default_menu_or_exit(selected_host['git-hosts']) script_path = get_script_path(dir_path, "switch-acc.sh") username = config_obj[selected_host['git-hosts']]['name'] email = config_obj[selected_host['git-hosts']]['email'] subprocess.run(['bash', script_path, username, email])