Skip to content

Commit

Permalink
Added option to quote paths (#35)
Browse files Browse the repository at this point in the history
* Added option to quote paths

* Escape value(s) in  _copy_value
  • Loading branch information
Patrick authored Jul 13, 2022
1 parent 5ed82fc commit 3e141aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"primary": true
},
"language": "auto",
"separator": ", "
"separator": ", ",
"escape_value_items": false,
"escape_value": false
}
12 changes: 11 additions & 1 deletion nautilus_copy_path.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
import shlex
from translation import Translation
from gi.repository import Nautilus, GObject, Gtk, Gdk
from gi import require_version
Expand All @@ -25,7 +26,9 @@ def __init__(self):
"primary": True
},
"language": "auto",
"separator": ", "
"separator": ", ",
"escape_value_items": False,
"escape_value": False
}

with open(os.path.join(os.path.dirname(__file__), "config.json")) as json_file:
Expand Down Expand Up @@ -84,7 +87,14 @@ def _copy_names(self, menu, files):

def _copy_value(self, value):
if len(value) > 0:
if self.config["escape_value_items"]:
value = list(map(lambda x: shlex.quote(x), value))

new_value = self.config["separator"].join(value)

if self.config["escape_value"]:
new_value = shlex.quote(new_value)

if self.config["selections"]["clipboard"]:
self.clipboard.set_text(new_value, -1)
if self.config["selections"]["primary"]:
Expand Down

0 comments on commit 3e141aa

Please sign in to comment.