90 lines
2.6 KiB
Python
90 lines
2.6 KiB
Python
import sys
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
from config import load_config
|
|
from gui import MainWindow
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
|
|
def get_icon_with_fzf(breeze_path):
|
|
try:
|
|
preview_script = r'''
|
|
FILE="$1"
|
|
DIM="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}"
|
|
if command -v kitten >/dev/null; then
|
|
kitten icat --clear --transfer-mode=memory --stdin=no --scale-up --place="${DIM}@${FZF_PREVIEW_LEFT:-0}x${FZF_PREVIEW_TOP:-0}" "$FILE" > /dev/tty
|
|
elif command -v wezterm >/dev/null; then
|
|
wezterm imgcat "$FILE"
|
|
elif command -v chafa >/dev/null; then
|
|
chafa -s "$DIM" "$FILE"
|
|
else
|
|
cat "$FILE"
|
|
fi
|
|
'''
|
|
env = os.environ.copy()
|
|
env['FZF_PREVIEW_SCRIPT'] = preview_script
|
|
|
|
find_proc = subprocess.Popen(
|
|
["find", ".", "-type", "f", "-name", "*.svg"],
|
|
cwd=breeze_path,
|
|
stdout=subprocess.PIPE,
|
|
)
|
|
fzf_proc = subprocess.Popen(
|
|
["fzf", "--preview", "bash -c \"$FZF_PREVIEW_SCRIPT\" _ {}"],
|
|
stdin=find_proc.stdout,
|
|
stdout=subprocess.PIPE,
|
|
text=True,
|
|
cwd=breeze_path,
|
|
env=env
|
|
)
|
|
find_proc.stdout.close()
|
|
out, _ = fzf_proc.communicate()
|
|
if fzf_proc.returncode == 0 and out.strip():
|
|
return (Path(breeze_path) / out.strip()).resolve()
|
|
return None
|
|
except Exception as e:
|
|
print(f"Error running fzf: {e}")
|
|
return None
|
|
|
|
|
|
def main():
|
|
breeze_path = load_config()
|
|
|
|
icon_path = None
|
|
if len(sys.argv) > 1:
|
|
arg_path = Path(sys.argv[1])
|
|
if arg_path.is_absolute():
|
|
icon_path = arg_path
|
|
else:
|
|
# First try relative to current directory
|
|
if arg_path.exists():
|
|
icon_path = arg_path.resolve()
|
|
else:
|
|
# Then try relative to breeze_path
|
|
icon_path = (Path(breeze_path) / arg_path).resolve()
|
|
|
|
if not icon_path.exists():
|
|
print(f"Error: Icon not found at {icon_path}")
|
|
sys.exit(1)
|
|
else:
|
|
print("Select an icon using fzf...")
|
|
icon_path = get_icon_with_fzf(breeze_path)
|
|
if not icon_path:
|
|
print("No icon selected.")
|
|
sys.exit(0)
|
|
|
|
app = QApplication(sys.argv)
|
|
window = MainWindow(icon_path)
|
|
window.show()
|
|
exit_code = app.exec()
|
|
|
|
if window.parser.history:
|
|
print(f"\nIcon colors updated: {icon_path.resolve()}")
|
|
|
|
sys.exit(exit_code)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|