Add ssh config listing script
This commit is contained in:
parent
a371bc0392
commit
06d1b84966
1 changed files with 32 additions and 0 deletions
32
bin/ssh-list-config.py
Executable file
32
bin/ssh-list-config.py
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import re
|
||||
|
||||
def bold(s):
|
||||
return "\033[1m" + s + "\033[0m"
|
||||
|
||||
RE_HOST = re.compile('Host (.*)')
|
||||
RE_HOSTNAME = re.compile('Hostname (.*)')
|
||||
|
||||
with open(f"{os.environ['HOME']}/.ssh/config", 'r') as f:
|
||||
lines = [l.strip() for l in f.readlines()]
|
||||
|
||||
lines = list(filter(lambda x: not x.startswith('#'), lines))
|
||||
|
||||
l = list()
|
||||
|
||||
for line in lines:
|
||||
m = RE_HOST.match(line)
|
||||
n = RE_HOSTNAME.match(line)
|
||||
|
||||
if m is not None:
|
||||
l.append([bold(m[1]) + ":", None])
|
||||
elif n is not None:
|
||||
l[-1][1] = n[1]
|
||||
|
||||
mlength = max(len(s[0]) for s in l )
|
||||
|
||||
l.sort(key=lambda x: x[0])
|
||||
|
||||
for line in l:
|
||||
print(f"{line[0]:{mlength}} {line[1]}")
|
Loading…
Reference in a new issue