Browse Source

Updated config file to update users .bash/.zshrc file with aliases

pull/11/head
jrtechs 6 years ago
parent
commit
1c971ad260
3 changed files with 103 additions and 4 deletions
  1. +100
    -3
      src/configuration.py
  2. +2
    -0
      src/module.py
  3. +1
    -1
      src/ssh_manager.py

+ 100
- 3
src/configuration.py View File

@ -43,8 +43,7 @@ def single_conf_input(param):
print("by default it will be " print("by default it will be "
+ os.path.dirname(__file__) + "/" + param + ".txt") + os.path.dirname(__file__) + "/" + param + ".txt")
i = input("Enter selection:") i = input("Enter selection:")
if i.strip() == "": if i.strip() == "":
return param + ": " + os.path.dirname(__file__) + "/" + param + ".txt" return param + ": " + os.path.dirname(__file__) + "/" + param + ".txt"
else: else:
@ -133,7 +132,105 @@ def get_config():
create_config() create_config()
return get_config() return get_config()
def generate_bash_aliases():
"""
Generates the bash aliases to add to the bash congig
:return: list of strings with bash aliases
"""
aliases = []
path = os.path.dirname(os.path.abspath(__file__)) + "/"
aliases.append("alias roosay=\"python3 " + path + "roosay.py\"")
aliases.append("alias ss=\"python3 " + path + "ssh_manager.py\"")
aliases.append("alias ssh_manager=\"python3 " + path + "ssh_manager.py\"")
aliases.append("alias mm=\"python3 " + path + "mount_ssh_drive.py\"")
aliases.append("alias ssh-mount=\"python3 " + path + "mount_ssh_drive.py\"")
aliases.append("alias quote=\"python3 " + path + "quote.py\"")
return aliases
def generate_extra_sauce():
"""
Creates a list of bash configurations things that I use
:return: string list with all my extra bash sauce
"""
sauce = []
sauce.append("alias ls=\"ls -abp --color=auto\"")
sauce.append("function cd {")
sauce.append("\tbuiltin cd \"$@\" && ls")
sauce.append("}")
sauce.append("quote")
return sauce
def view_shell_sauce():
"""
Displays the output of generate_bash_aliases() and generate_extra_sauce()
"""
print("\n#Bash Aliases:")
for line in generate_bash_aliases():
print(line)
print("\n")
print("#Extra Sauce")
for line in generate_extra_sauce():
print(line)
def write_to_bash_config(sauce):
"""
prompts user for name of shell config file and write contents of
sauce to it
"""
path = input("Enter name of shell (.bashrc or .zshrc):")
path = "~/" + path
for line in sauce:
module.append_file(path, line)
print("Added the following to " + path)
for line in sauce:
print("\t" + line)
def main():
"""
Prompts user to either update the config file, or make aliases
in the bash configuration
"""
options = []
options.append("1) Update Configuration File")
options.append("2) Make Aliases")
options.append("3) Add Extra Sauce")
options.append("4) View proposed shell conf")
options.append("5) Exit")
i = '0'
while i != '5':
module.print_menu("Configuration Manager", options)
i = input("Enter Option:")
if i == '1':
create_config()
elif i == '2':
write_to_bash_config(generate_bash_aliases())
elif i == '3':
write_to_bash_config(generate_extra_sauce())
elif i == '4':
view_shell_sauce()
"""
Makes sure that other programs don't execute the main
"""
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass

+ 2
- 0
src/module.py View File

@ -4,6 +4,7 @@ Jeffery Russell
""" """
import subprocess import subprocess
import os.path
def input_file(file_name): def input_file(file_name):
@ -25,6 +26,7 @@ def append_file(file_name, append):
:param append: message to append on file :param append: message to append on file
:return: None :return: None
""" """
file_name = os.path.expanduser(file_name)
f = open(file_name, "a+") f = open(file_name, "a+")
f.write(append + "\n") f.write(append + "\n")
f.close() f.close()

+ 1
- 1
src/ssh_manager.py View File

@ -208,4 +208,4 @@ if __name__ == '__main__':
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
exit_program();
exit_program()

Loading…
Cancel
Save