#!/bin/bash # # Thunar Copy Filename Auto-Installer # Copyright (C) 2026 laki # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # This script adds the "Copy Filename" custom action to ~/.config/Thunar/uca.xml set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SOURCE_PYTHON_SCRIPT="$SCRIPT_DIR/copy_filename.py" UCA_FILE="$HOME/.config/Thunar/uca.xml" TARGET_PYTHON_SCRIPT="$HOME/.config/Thunar/copy_filename.py" echo "--- Thunar Copy Filename Installer ---" # 1. Check if the source Python script exists if [ ! -f "$SOURCE_PYTHON_SCRIPT" ]; then echo "Error: $SOURCE_PYTHON_SCRIPT not found!" exit 1 fi echo "Copying script to: $TARGET_PYTHON_SCRIPT" mkdir -p "$(dirname "$TARGET_PYTHON_SCRIPT")" cp "$SOURCE_PYTHON_SCRIPT" "$TARGET_PYTHON_SCRIPT" chmod +x "$TARGET_PYTHON_SCRIPT" # 2. Check for dependencies if ! python3 -c "import gi; gi.require_version('Gtk', '3.0')" 2>/dev/null; then echo "Warning: Python3 GTK3 bindings not found." echo "Please install: sudo apt install python3-gi gir1.2-gtk-3.0" fi # 3. Handle uca.xml if [ ! -f "$UCA_FILE" ]; then echo "Creating new Thunar configuration at $UCA_FILE" mkdir -p "$(dirname "$UCA_FILE")" cat < "$UCA_FILE" EOF fi # 4. Check if already installed if grep -q "copy-filename-extension" "$UCA_FILE"; then echo "Action is already present in $UCA_FILE." echo "Updating the path to ensure it's correct..." # Update the existing command path sed -i "s|.*copy_filename.py %N|$TARGET_PYTHON_SCRIPT %N|g" "$UCA_FILE" else echo "Adding 'Copy Filename' action to $UCA_FILE" ACTION_BLOCK=" edit-copy Copy Filename copy-filename-extension $TARGET_PYTHON_SCRIPT %N Copy the filename and extension to clipboard * " # Use Python to safely handle the multi-line insertion export ACTION_BLOCK UCA_FILE python3 -c ' import os action_block = os.environ["ACTION_BLOCK"] uca_path = os.environ["UCA_FILE"] with open(uca_path, "r") as f: content = f.read() if "" in content: new_content = content.replace("", "\n" + action_block) with open(uca_path, "w") as f: f.write(new_content) ' fi echo "Success! Please restart Thunar (thunar -q) to see the changes." echo "----------------------------------------"