Codeberg

summaryrefslogtreecommitdiff
path: root/install.sh
diff options
context:
space:
mode:
authorlaki <mail@lakiweb.net>2026-01-31 17:44:21 +0000
committerlaki <mail@lakiweb.net>2026-01-31 17:44:21 +0000
commit053761b58c70dc8037887341f03f9c575cbc2660 (patch)
treef778ef7e3e35354a9587be8e88cd37ae87278a67 /install.sh
downloadthunar-copy-button-053761b58c70dc8037887341f03f9c575cbc2660.tar.gz
thunar-copy-button-053761b58c70dc8037887341f03f9c575cbc2660.tar.bz2
thunar-copy-button-053761b58c70dc8037887341f03f9c575cbc2660.zip
Initial commit for thunar-copy-button
Diffstat (limited to 'install.sh')
-rwxr-xr-xinstall.sh101
1 files changed, 101 insertions, 0 deletions
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 <https://www.gnu.org/licenses/>.
+#
+# 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 <<EOF > "$UCA_FILE"
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+</actions>
+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|<command>.*copy_filename.py %N</command>|<command>$TARGET_PYTHON_SCRIPT %N</command>|g" "$UCA_FILE"
+else
+ echo "Adding 'Copy Filename' action to $UCA_FILE"
+
+ ACTION_BLOCK="<action>
+ <icon>edit-copy</icon>
+ <name>Copy Filename</name>
+ <submenu></submenu>
+ <unique-id>copy-filename-extension</unique-id>
+ <command>$TARGET_PYTHON_SCRIPT %N</command>
+ <description>Copy the filename and extension to clipboard</description>
+ <range></range>
+ <patterns>*</patterns>
+ <startup-notify/>
+ <audio-files/>
+ <image-files/>
+ <other-files/>
+ <text-files/>
+ <video-files/>
+ <directories/>
+</action>"
+
+ # 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 "<actions>" in content:
+ new_content = content.replace("<actions>", "<actions>\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 "----------------------------------------"