blob: 96fab959d7c13fab34f95d841916e800b7653ea5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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 "----------------------------------------"
|