From de53cc79c2df45ddc1e405d413e5fd5d7e6b8fcd Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 1 Feb 2024 17:55:34 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20git-status-all:=20allow=20giving=20?= =?UTF-8?q?the=20search=20path=20on=20the=20cmd=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git-status-all | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/git-status-all b/git-status-all index e8a1c21..ca8ac7a 100755 --- a/git-status-all +++ b/git-status-all @@ -11,6 +11,8 @@ import os import re import subprocess +import click + # TODO config file (and defaults here) IGNORES = [ @@ -36,19 +38,31 @@ def working_directory(directory: Path): os.chdir(saved_cwd) -for git_directory in git_directories('.'): - # technically,we could have a different GIT_DIR than ".git", but this script - # assumes ".git". - if git_directory.parts[-1] != ".git": - continue - work_tree_directory = git_directory.parent - - with working_directory(work_tree_directory): - try: - out = subprocess.check_output(['git', 'status', '-s'], stderr=subprocess.STDOUT) - if len(out) > 0: - print('== {}\n{}'.format(work_tree_directory, out.decode('utf-8'))) - except subprocess.CalledProcessError as e: - print((Fore.RED + 'git status is unhappy with {}' + Fore.RESET) - .format(work_tree_directory)) - print(e.output) +@click.command +@click.argument('topdirs', nargs=-1) +def search_dirty(topdirs): + """Search for dirty git working directories in TOPDIRS""" + if len(topdirs) == 0: + topdirs = ["."] + + for topdir in topdirs: + for git_directory in git_directories(topdir): + # technically,we could have a different GIT_DIR than ".git", but this script + # assumes ".git". + if git_directory.parts[-1] != ".git": + continue + work_tree_directory = git_directory.parent + + with working_directory(work_tree_directory): + try: + out = subprocess.check_output(['git', 'status', '-s'], stderr=subprocess.STDOUT) + if len(out) > 0: + print('== {}\n{}'.format(work_tree_directory, out.decode('utf-8'))) + except subprocess.CalledProcessError as e: + print((Fore.RED + 'git status is unhappy with {}' + Fore.RESET) + .format(work_tree_directory)) + print(e.output) + + +if __name__ == '__main__': + search_dirty()