-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add Copy file path to Nautilus right-click context menu #5793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
da0bb37
3b8ab81
4a3355e
1b07638
e5bcec5
e2b6b5e
b72a831
50d3579
fc1cb1a
e4757ab
f18dfdd
76d09b2
ecbd912
f81b3c8
0e126b7
997011e
33c92f5
46eb556
feda8b7
2554fe8
e6b105d
cd511f7
d71ddf0
4ee44c3
b919a55
cdb8628
d51a3f6
9ece331
8f7d64b
2c4b448
236a34b
2537edb
77c9bca
2f5be43
577cd1e
12494bc
141edc2
1abc92a
8346eea
7dc086b
add6a3c
bc9777c
4127c74
2fab15c
53d073d
1770494
b77f900
9eb0f0e
cd7c38c
fa5d054
0c97265
efd34a2
58c350c
0b35365
3d9a875
cf16a6a
8537f41
1eaddf9
a4ab555
ff23d01
59b16e7
1351cc6
211acd6
60966d4
ea7979a
06fd369
4a7ade9
dc249db
d40e314
5cf3496
f1a4e9f
fddaa5e
774acbf
0edff31
d7e3c0d
cb3fcf4
e7f4538
011243f
f4a0249
a6280ee
03750b3
48a771b
e3d3ee4
516882a
86a38c4
7138044
648d833
9aa3858
0a5cd43
a3aedb0
d59ad09
e22b70f
d827b90
c80d060
dc8ad1d
d4ffa9e
cd4fadd
b6ad01a
66492e5
38326c7
d8a9186
c9d1cdc
3a240c7
71e303d
121a1e0
98e9bc6
74f319b
f2f65fd
c8c395b
cff80ff
d0000ea
2a1c198
b2ffc1f
a865ecc
6f281d8
27b598a
8f43960
dde7605
44a0123
7f6abcd
b2d95ee
30bb098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import shutil | ||
|
|
||
| from gi import require_version | ||
|
|
||
| require_version("Nautilus", "4.1") | ||
|
|
||
| from gi.repository import GObject, Gio, GLib, Nautilus | ||
|
|
||
|
|
||
| class CopyFilePathAction(GObject.GObject, Nautilus.MenuProvider): | ||
| def _selected_paths(self, files): | ||
| paths = [] | ||
| seen = set() | ||
|
|
||
| for file in files: | ||
| location = file.get_location() | ||
| if not location: | ||
| continue | ||
|
|
||
| path = location.get_path() | ||
| if path and path not in seen: | ||
| seen.add(path) | ||
| paths.append(path) | ||
|
|
||
| return paths | ||
|
|
||
| def _make_item(self, paths): | ||
| label = "Copy file path" if len(paths) == 1 else "Copy file paths" | ||
| item = Nautilus.MenuItem( | ||
| name="OmarchyCopyFilePath::copy_file_path", | ||
| label=label, | ||
| icon="edit-copy", | ||
| ) | ||
| item.connect("activate", self._on_activate, paths) | ||
| return item | ||
|
|
||
| def _on_activate(self, _menu, paths): | ||
| text = "\n".join(paths) | ||
|
|
||
| proc = Gio.Subprocess.new( | ||
| ["wl-copy", "--type", "text/plain"], | ||
| Gio.SubprocessFlags.STDIN_PIPE | ||
| | Gio.SubprocessFlags.STDOUT_SILENCE | ||
| | Gio.SubprocessFlags.STDERR_SILENCE, | ||
| ) | ||
| if proc: | ||
| proc.communicate(GLib.Bytes.new(text.encode("utf-8")), cancellable=None) | ||
|
|
||
| def get_file_items(self, *args): | ||
| files = args[0] if len(args) == 1 else args[1] | ||
| paths = self._selected_paths(files) | ||
|
|
||
| if not paths or not shutil.which("wl-copy"): | ||
| return [] | ||
|
|
||
| return [self._make_item(paths)] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ EXTENSIONS_DIR="$HOME/.local/share/nautilus-python/extensions" | |
| mkdir -p "$EXTENSIONS_DIR" | ||
| cp "$OMARCHY_PATH/default/nautilus-python/extensions/localsend.py" "$EXTENSIONS_DIR/" | ||
| cp "$OMARCHY_PATH/default/nautilus-python/extensions/transcode.py" "$EXTENSIONS_DIR/" | ||
| cp "$OMARCHY_PATH/default/nautilus-python/extensions/copy-filepath.py" "$EXTENSIONS_DIR/" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This commit only adds Useful? React with 👍 / 👎. |
||
Uh oh!
There was an error while loading. Please reload this page.