Auto-update: Fri Jan 17 11:58:23 PST 2025
This commit is contained in:
parent
61706931da
commit
7737517ad5
2 changed files with 78 additions and 0 deletions
70
linecounter
Executable file
70
linecounter
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def is_binary(file_path):
|
||||
"""
|
||||
Determines if a file is binary by checking its content.
|
||||
Returns True for binary files, False for text files.
|
||||
"""
|
||||
try:
|
||||
with open(file_path, 'rb') as f:
|
||||
# Read the first 1024 bytes to check if it's binary
|
||||
chunk = f.read(1024)
|
||||
if b'\0' in chunk:
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Error reading file {file_path}: {e}")
|
||||
return True # Treat unreadable files as binary for safety.
|
||||
|
||||
def count_lines_in_file(file_path):
|
||||
"""
|
||||
Counts the number of lines in a given text file.
|
||||
"""
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
return sum(1 for _ in f)
|
||||
except Exception as e:
|
||||
print(f"Error counting lines in file {file_path}: {e}")
|
||||
return 0
|
||||
|
||||
def count_lines_in_directory(directory, extensions=None):
|
||||
"""
|
||||
Recursively counts lines in all text files (optionally filtered by extensions) within the directory.
|
||||
"""
|
||||
total_lines = 0
|
||||
total_files = 0
|
||||
for root, _, files in os.walk(directory):
|
||||
for file_name in files:
|
||||
file_path = os.path.join(root, file_name)
|
||||
|
||||
# Skip binary files
|
||||
if is_binary(file_path):
|
||||
continue
|
||||
|
||||
# Check for extensions if provided
|
||||
if extensions and not file_name.lower().endswith(tuple(extensions)):
|
||||
continue
|
||||
|
||||
# Count lines in the valid file
|
||||
lines = count_lines_in_file(file_path)
|
||||
total_lines += lines
|
||||
total_files += 1
|
||||
|
||||
return total_files, total_lines
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Get extensions from command-line arguments
|
||||
extensions = [ext.lower() for ext in sys.argv[1:]] if len(sys.argv) > 1 else None
|
||||
|
||||
# Get the current working directory
|
||||
current_dir = os.getcwd()
|
||||
print(f"Scanning directory: {current_dir}")
|
||||
if extensions:
|
||||
print(f"Filtering by extensions: {', '.join(extensions)}")
|
||||
total_files, total_lines = count_lines_in_directory(current_dir, extensions)
|
||||
print(f"Total matching files: {total_files}")
|
||||
print(f"Total lines across matching files: {total_lines}")
|
||||
|
8
ollapull
Executable file
8
ollapull
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
# Pull the latest version of every locally installed model:
|
||||
|
||||
ollama ls | tail -n +2 | awk '{print $1}' | while read MODEL; do
|
||||
echo "Pulling latest for $MODEL..."
|
||||
ollama pull "$MODEL"
|
||||
done
|
||||
|
Loading…
Add table
Reference in a new issue