-
-
Save marcosdiez/35ecd78f6bba011f618bb2530699449b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import sys | |
import os | |
def show_paths(): | |
uid = os.getuid() | |
folder = "/proc" | |
blacklist = [ "/proc/net" , "/proc/self", "/proc/thread-self" ] | |
output = [] | |
for proc_path in os.scandir(folder): | |
if not proc_path.is_dir(): | |
continue | |
if proc_path.stat().st_uid != uid: | |
continue | |
if proc_path.path in blacklist: | |
continue | |
cwd = "{}/cwd".format(proc_path.path) | |
try: | |
cwd_value = os.readlink(cwd) | |
except PermissionError: | |
continue | |
if cwd_value not in output: | |
output.append(cwd_value) | |
return output | |
def max_length(the_list): | |
max_length = 0 | |
for elem in the_list: | |
this_length = len(elem) | |
if this_length > max_length: | |
max_length = this_length | |
return max_length | |
if len(sys.argv) < 2: | |
print("This program shows the path in which each bash is located, so you can easily go to the same path in a different termnial") | |
print("") | |
paths = show_paths() | |
length = max_length(paths) | |
mask = "cd {path:" + str(length) + "} # {counter}" | |
counter = 0 | |
for path in paths: | |
print(mask.format(counter=counter, path=path)) | |
counter += 1 | |
print("") | |
sys.exit(1) | |
else: | |
n = int(sys.argv[1]) | |
print(show_paths()[n]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment