add the git project ending part
This commit is contained in:
parent
dd32deac6e
commit
108f24255d
33
ls.py
33
ls.py
|
|
@ -6,6 +6,7 @@ import grp
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import subprocess
|
||||||
|
|
||||||
# ANSI escape codes for colors
|
# ANSI escape codes for colors
|
||||||
COLORS = {
|
COLORS = {
|
||||||
|
|
@ -97,6 +98,27 @@ def sizeof_fmt(num):
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
return f"{num:.1f}Y"
|
return f"{num:.1f}Y"
|
||||||
|
|
||||||
|
def git_gud(path):
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(['git', 'status', '--porcelain'], cwd=path).strip().decode("utf-8")
|
||||||
|
if output.strip():
|
||||||
|
lines=output.split('\n')
|
||||||
|
mods = len([x for x in lines if x[0] == 'M'])
|
||||||
|
unt = len([x for x in lines if x[0] == '?'])
|
||||||
|
ding = ''
|
||||||
|
ding += colorize('!'+str(mods), "YELLOW") if mods > 0 else ''
|
||||||
|
ding += ' ' if mods > 0 and unt > 0 else ''
|
||||||
|
ding += colorize('?'+str(unt), "CYAN") if unt > 0 else ''
|
||||||
|
return ding
|
||||||
|
|
||||||
|
# output = subprocess.check_output(['git', 'rev-list', '--count', '--left-only', '@{u}...HEAD'], cwd=file_path, stderr=subprocess.DEVNULL)
|
||||||
|
# if int(output.strip()) > 0:
|
||||||
|
# print("bbbb")
|
||||||
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||||
|
pass
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_files(directory='.', args={}):
|
def list_files(directory='.', args={}):
|
||||||
files = os.listdir(directory)
|
files = os.listdir(directory)
|
||||||
|
|
@ -138,14 +160,19 @@ def list_files(directory='.', args={}):
|
||||||
mtime = time.strftime("%b %d %H:%M", time.localtime(stats.st_mtime))
|
mtime = time.strftime("%b %d %H:%M", time.localtime(stats.st_mtime))
|
||||||
|
|
||||||
colored_file = color_file(file_path, mode)
|
colored_file = color_file(file_path, mode)
|
||||||
|
|
||||||
|
|
||||||
|
git=''
|
||||||
|
if args.extend and Filetype(mode & Filetype.S_IFMT.value) == Filetype.S_IFDIR and os.path.exists(os.path.join(file_path, '.git')):
|
||||||
|
git=git_gud(file_path)
|
||||||
|
|
||||||
if os.path.islink(file_path):
|
if os.path.islink(file_path):
|
||||||
color = "RED"
|
color = "RED"
|
||||||
if os.path.exists(os.readlink(file_path)):
|
if os.path.exists(os.readlink(file_path)):
|
||||||
color = "GREEN"
|
color = "GREEN"
|
||||||
print(f"{permissions} {nlink:2d} {user:<8s} {group:<8s} {size:>6} {mtime} {colored_file} -> {colorize(os.readlink(file_path), color)}")
|
print(f"{permissions} {nlink:2d} {user:<8s} {group:<8s} {size:>6} {mtime} {colored_file} -> {colorize(os.readlink(file_path), color)} {git}")
|
||||||
else:
|
else:
|
||||||
print(f"{permissions} {nlink:2d} {user:<8s} {group:<8s} {size:>6} {mtime} {colored_file}")
|
print(f"{permissions} {nlink:2d} {user:<8s} {group:<8s} {size:>6} {mtime} {colored_file} {git}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
@ -172,6 +199,8 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('-r', '--reverse', action='store_true', help="Reverse sort order")
|
parser.add_argument('-r', '--reverse', action='store_true', help="Reverse sort order")
|
||||||
|
|
||||||
parser.add_argument('-h', '--human', action='store_true', help="Human Readable size")
|
parser.add_argument('-h', '--human', action='store_true', help="Human Readable size")
|
||||||
|
|
||||||
|
parser.add_argument('-e', '--extend', action='store_true', help="Human Readable size")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue