Last active
February 19, 2023 12:59
-
-
Save spookyahell/001d75e5e4eaf63dbdcb93d2c4155051 to your computer and use it in GitHub Desktop.
Place in your PATH (and add .py to PATHEXT if not already done so) for a better Windows Console title experience
This file contains hidden or 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
# v0.1 by spookyahell | |
import sys, re | |
from os import remove, sep | |
from os.path import abspath, isdir | |
from subprocess import call, check_output | |
if not isdir(sys.argv[1]): | |
print('ERROR: The path you want to switch to does NOT exist.') | |
sys.exit(1) | |
switch_to = abspath(sys.argv[1]) | |
how_many_sep = switch_to.count(sep) | |
if how_many_sep == 1: | |
drive_letter = switch_to.split(sep)[0] | |
#~ print('Drive letter:', drive_letter) | |
x = check_output(['wmic','logicaldisk','get', 'deviceid,', 'volumename,', 'description']) | |
datas = [] | |
dataos = [] | |
table_text = x.decode() | |
lines = table_text.split('\r\r\n') | |
for line in lines: | |
possible_data = [data.strip() for data in line.strip().split(' ') if data.strip() != ''] | |
if possible_data != []: | |
datas.append(possible_data) | |
data_headers = datas[0] | |
del datas[0] | |
for data in datas: | |
datao = {} | |
for idx, name in enumerate(data_headers): | |
datao[name] = data[idx] | |
dataos.append(datao) | |
for item in dataos: | |
if item['DeviceID'] == drive_letter: | |
drive_label = item['VolumeName'] | |
#~ with open('result.txt', 'w') as f: | |
#~ f.write() | |
call(['cmd', '/k', f'title {switch_to} [{drive_label}]'], cwd = sys.argv[1]) | |
else: | |
call(['cmd', '/k', f'title {switch_to.split(sep)[-1]} (in {sep.join(switch_to.split(sep)[:-1])})'], cwd = sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment