From 053761b58c70dc8037887341f03f9c575cbc2660 Mon Sep 17 00:00:00 2001 From: laki Date: Sat, 31 Jan 2026 17:44:21 +0000 Subject: Initial commit for thunar-copy-button --- install.sh | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 install.sh (limited to 'install.sh') diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..96fab95 --- /dev/null +++ b/install.sh @@ -0,0 +1,101 @@ +#!/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 "----------------------------------------" -- cgit v1.2.3-70-g09d2