Last active
August 29, 2015 14:02
-
-
Save tdgunes/a74599ae11b7332067f9 to your computer and use it in GitHub Desktop.
My Terminal Utils
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
# Using this method: | |
# http://www.linuxproblem.org/art_9.html | |
import os | |
import save_as_alias | |
user = raw_input("User(root etc.): ") | |
host = raw_input("Host(x.x.x.x): ") | |
path = os.getcwd() | |
os.system("cd ~ ; ssh {0}@{1} mkdir -p .ssh".format(user, host)) | |
os.system("cd ~ ; cat .ssh/id_rsa.pub | ssh {0}@{1} \'cat >> .ssh/authorized_keys\'".format(user, host)) | |
os.system("cd "+path) | |
add_alias_answer = raw_input("Should I make an alias?(y/n)") | |
if add_alias_answer in ["y", "yes"]: | |
keyword = raw_input("Alias keyword(tdgserver): ") | |
save_as_alias.add_alias(keyword, "ssh {0}@{1}".format(user,host)) |
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
import os | |
ZSH_PATH = "/Users/tdgunes/.zshrc" | |
ZSH_FILE = open(ZSH_PATH,"r") | |
lines = list(ZSH_FILE.readlines()) | |
ZSH_FILE.close() | |
count = 0 | |
found_lines = [] | |
for line in lines: | |
if line.startswith("alias"): | |
found_lines.append((count,line)) | |
count += 1 | |
for number,line in found_lines: | |
print str(number)+": "+line.strip() | |
delete_number = int(raw_input("which line: ")) | |
lines.pop(delete_number) | |
with open(ZSH_PATH, "w") as zsh_file: | |
for line in lines: | |
zsh_file.write(line) | |
print "Done" |
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
import os | |
ZSH_PATH = "/Users/tdgunes/.zshrc" | |
def add_alias(keyword, alias): | |
with open(ZSH_PATH, "a") as zsh_file: | |
zsh_file.write("alias "+keyword +"=\""+alias+"\"\n") | |
os.system("tail " + ZSH_PATH) | |
print "------------" | |
print "write this if you want to apply the config now: | |
print ". "+ZSH_PATH | |
if __name__ == '__main__': | |
keyword = raw_input("keyword(get): ") | |
alias = raw_input("alias(curl ..): ") | |
add_alias(keyword, alias) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment