Skip to content

Instantly share code, notes, and snippets.

@tdgunes
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdgunes/a74599ae11b7332067f9 to your computer and use it in GitHub Desktop.
Save tdgunes/a74599ae11b7332067f9 to your computer and use it in GitHub Desktop.
My Terminal Utils
# 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))
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"
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