lang/python/ PoorMansLs
The cygwin ls
blocks trying to stat a link to a network share that isn't there.
(On one laptop with a small SSD, I store my downloads on a network share, and when on the go
that isn't accessible; there is a link in my home directory ~/dl
so, if I want to ls
inside
my home directory, it hangs trying to stat ~/dl
, so I wrote this to 'scratch this itch').
#!/usr/bin/env python3
from glob import glob
from colors import color
import os
import sys
args = sys.argv[1:]
files = set()
if len(args) == 0:
args = ["*"]
for arg in args:
files.update(glob(arg))
for x in files:
if os.path.islink(x):
print(color(f"{x}@",fg="cyan"))
elif os.path.isdir(x):
print(color(f"{x}/",fg="blue"))
elif os.access(x, os.X_OK):
print(color(f"{x}*",fg="green"))
else:
print(f"{x}")