diff --git a/Makefile b/Makefile index 148aeab..82758fa 100644 --- a/Makefile +++ b/Makefile @@ -57,9 +57,9 @@ else endif deb: -ifneq ($(shell id -u), 0) - @echo "You must be root to perform this action." - exit 1 +ifeq ($(FAKEROOTKEY),) + @echo fakerooting + @fakeroot make deb else rm -rf build mkdir -p build/$(GLOBALLOC)/nautilus-python @@ -85,6 +85,7 @@ else find build/ -type d -exec chmod 0755 {} \; find build/ -type f -exec chmod 0644 {} \; chmod +x build/$(GLOBALLOC)/actions-for-nautilus-configurator/start-configurator.sh -endif dpkg-deb -Z gzip --build build dist/actions-for-nautilus_$(VERSION)_all.deb lintian dist/actions-for-nautilus_$(VERSION)_all.deb +endif + diff --git a/README.md b/README.md index 0ad4888..617d9f2 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ if you want to see the sample configuration working properly: * `gedit` - the standard Gnome editor - you probably already have this * `gnome-terminal` - the standard Gnome terminal emulator (for now) - you probably have this too. -* `xclip` - a command line tool for managing the X clipboards +* `xclip` - a command line tool for managing the X clipboards * `zenity` - a Gnome UI toolkit for shell scripts Again, these can be installed using your platform package manager as shown above. @@ -140,6 +140,11 @@ It is also possible that the semantics of the more complex command structures re upon shell features that, if you are not using BASH as your system shell, will not work for you. +(Note that there are a number of programs that allow you to manage the X clipboards +from the command line - `xsel`, `xclipboard`, `xcutsel`... - all are usable with this +extension - particularly `xsel`. However for the sample configuration we had to pick one, +so `xclip` was chosen). + ### The Gnome Terminal "No Close" profile When executing the `gnome-terminal` command, the sample configuration references a `gnome-terminal` profile named "No Close". @@ -546,6 +551,8 @@ the same semantics: | `%s` | the URI scheme from the URI of the first selected item (e.g. `file`) | ANY | | `%u` | the URI of the first selected item (e.g. `file:///home/me/my-first-dir/my-second-dir/my-file.txt`) | SINGULAR | | `%U` | space-separated list of the `%u` values of all selected items | PLURAL | +| `%v` | the text content of the system selection | ANY | +| `%V` | the text content of the system clipboard | ANY | | `%w` | the basename of the first selected item without it's extension (e.g. `my-file`) | SINGULAR | | `%W` | space-separated list of the `%w` values of all selected items | PLURAL | | `%x` | the extension of the first selected item without it's extension (e.g. `txt`) | SINGULAR | diff --git a/configurator/command-line-help.html b/configurator/command-line-help.html index ffeb004..4f0404d 100644 --- a/configurator/command-line-help.html +++ b/configurator/command-line-help.html @@ -163,6 +163,16 @@
%u
values of all selected items%v
%V
%w
my-file
)
diff --git a/configurator/sample-config.json b/configurator/sample-config.json
index 4e7458b..5bf6512 100644
--- a/configurator/sample-config.json
+++ b/configurator/sample-config.json
@@ -13,7 +13,7 @@
{
"type": "command",
"label": "Test all place holders",
- "command_line": "%O printf '%%s\\n' '#b' %b '#B' %B '#c' %c '#d' %d '#D' %D '#f' %f '#F' %F '#h' %h '#m' %m '#M' %M '#n' %n '#o' %o '#O' %O '#p' %p '#s' %s '#u' %u '#U' %U '#w' %w '#W' %W '#x' %x '#X' %X | zenity --title \"Test all place holders\" --text-info",
+ "command_line": "%O printf '%%s\\n' '#v' %v '#V' %V '#b' %b '#B' %B '#c' %c '#d' %d '#D' %D '#f' %f '#F' %F '#h' %h '#m' %m '#M' %M '#n' %n '#o' %o '#O' %O '#p' %p '#s' %s '#u' %u '#U' %U '#w' %w '#W' %W '#x' %x '#X' %X | zenity --title \"Test all place holders\" --text-info",
"use_shell": true
},
{
diff --git a/dist/actions-for-nautilus_1.6.0_all.deb b/dist/actions-for-nautilus_1.6.0_all.deb
index 4c7f6ea..edaf010 100644
Binary files a/dist/actions-for-nautilus_1.6.0_all.deb and b/dist/actions-for-nautilus_1.6.0_all.deb differ
diff --git a/extensions/actions-for-nautilus/afn_clipboard.py b/extensions/actions-for-nautilus/afn_clipboard.py
new file mode 100644
index 0000000..65aed8a
--- /dev/null
+++ b/extensions/actions-for-nautilus/afn_clipboard.py
@@ -0,0 +1,52 @@
+#
+# I have two implementations because the original used xclip and I wanted
+# to preserve that in the sources as the "reference" for semantics while
+# we shake out the feature in general.
+#
+# However, there really isn't a need for a user switch between the GTK
+# implementation and the xclip implementation - if GTK is proved to be
+# entirely consistent it will be the actual implementation, avoiding a
+# dependency on xclip (even though that remains a recommended additional
+# tool.
+#
+# Additionally The GTK implementation has the advantage of internally
+# sorting out whether the content of the target clipboard is text-serializable
+# without relying on the caller (us) having to trap and process errors.
+#
+IMPL = "gtk" # "gtk" or "xclip"
+
+if IMPL == "gtk":
+ import gi
+
+ gi.require_version("Gtk", "3.0")
+ from gi.repository import Gtk, Gdk
+
+ global _gtk_clipboard
+ _gtk_clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
+ global _gtk_selection
+ _gtk_selection = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
+else:
+ import os
+
+def _get_from_gtk_clipboard(clipboard):
+ return clipboard.wait_for_text()
+
+def _get_from_xclip(clipboard):
+ try:
+ paste_str = os.popen(f"xclip -out -selection {clipboard}").read()
+ return "" if not isinstance(paste_str, str) else paste_str
+ except Exception as error:
+ print("Clipboard load error", error)
+ return ""
+
+def get_from_clipboard():
+ if IMPL == "gtk":
+ return _get_from_gtk_clipboard(_gtk_clipboard)
+ else:
+ return _get_from_xclip("clipboard")
+
+def get_from_selection():
+ if IMPL == "gtk":
+ return _get_from_gtk_clipboard(_gtk_selection)
+ else:
+ return _get_from_xclip("primary")
diff --git a/extensions/actions-for-nautilus/afn_place_holders.py b/extensions/actions-for-nautilus/afn_place_holders.py
index 65a583b..6d3b9b9 100644
--- a/extensions/actions-for-nautilus/afn_place_holders.py
+++ b/extensions/actions-for-nautilus/afn_place_holders.py
@@ -1,7 +1,7 @@
###
### Place holder replacement functions
###
-import re, afn_config
+import re, afn_config, afn_clipboard, os
###
### Exported functions and values
@@ -66,6 +66,14 @@ def _expand_percent_p(index, files, escape):
def _expand_percent_s(index, files, escape):
return files[0]["uri"].scheme
+def _expand_percent_v(index, files, escape):
+ v = afn_clipboard.get_from_selection()
+ return "" if v is None else v.replace(" ","\\ ") if escape else v
+
+def _expand_percent_V(index, files, escape):
+ V = afn_clipboard.get_from_clipboard()
+ return "" if V is None else V.replace(" ","\\ ") if escape else V
+
#
# SINGULAR (per index)
#
@@ -142,6 +150,8 @@ def _file_name_extension(basename):
"s": { "f": _expand_percent_s, "behavior": -1},
"u": { "f": _expand_percent_u, "behavior": SINGULAR},
"U": { "f": _expand_percent_U, "behavior": PLURAL},
+ "v": { "f": _expand_percent_v, "behavior": -1},
+ "V": { "f": _expand_percent_V, "behavior": -1},
"w": { "f": _expand_percent_w, "behavior": SINGULAR},
"W": { "f": _expand_percent_W, "behavior": PLURAL},
"x": { "f": _expand_percent_x, "behavior": SINGULAR},