Repository: qutebrowser/qutebrowser

Issue:
Add a way to substitute ({url}) and yank decoded URL
Not sure if this is intended. I'm piping the output to xclip, but I want the bash script to receive normal spaces.



Discussion:
That's intended currently - qutebrowser uses [`QUrl::FullyEncoded`](http://doc.qt.io/qt-5/qurl.html#ComponentFormattingOption-enum) to make sure no information gets lost. Maybe there should be a `{url:pretty}` or something too?

Something along those lines would be a nice addition. Though not very
important.
It'd be nice to not have to parse % codes elsewhere.

On Sun, Mar 27, 2016 at 4:28 PM, Florian Bruhin notifications@github.com
wrote:

> That's intended currently - qutebrowser uses QUrl::FullyEncoded
> http://doc.qt.io/qt-5/qurl.html#ComponentFormattingOption-enum to make
> sure no information gets lost. Maybe there should be a {url:pretty} or
> something too?
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly or view it on GitHub
> https://github.com/The-Compiler/qutebrowser/issues/1372#issuecomment-202148111

Speaking of percent encoding, it would be nice to be able to `:yank` the decoded URL. Most browsers, email clients or anything you might want to paste it into will automatically encode unicode input anyway, so you wouldn't lose any information and gain human readability :wink:


Resolving patch:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -654,13 +654,14 @@ def scroll_page(self, x: {'type': float}, y: {'type': float}, *,
         frame.scroll(dx, dy)
 
     @cmdutils.register(instance='command-dispatcher', scope='window')
-    def yank(self, title=False, sel=False, domain=False):
+    def yank(self, title=False, sel=False, domain=False, pretty=False):
         """Yank the current URL/title to the clipboard or primary selection.
 
         Args:
             sel: Use the primary selection instead of the clipboard.
             title: Yank the title instead of the URL.
             domain: Yank only the scheme, domain, and port number.
+            pretty: Yank the URL in pretty decoded form.
         """
         if title:
             s = self._tabbed_browser.page_title(self._current_index())
@@ -672,8 +673,10 @@ def yank(self, title=False, sel=False, domain=False):
                                    ':' + str(port) if port > -1 else '')
             what = 'domain'
         else:
-            s = self._current_url().toString(
-                QUrl.FullyEncoded | QUrl.RemovePassword)
+            flags = QUrl.RemovePassword
+            if not pretty:
+                flags |= QUrl.FullyEncoded
+            s = self._current_url().toString(flags)
             what = 'URL'
 
         if sel and QApplication.clipboard().supportsSelection():
diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py
--- a/qutebrowser/config/configdata.py
+++ b/qutebrowser/config/configdata.py
@@ -1443,6 +1443,8 @@ def data(readonly=False):
         ('yank -ts', ['yT']),
         ('yank -d', ['yd']),
         ('yank -ds', ['yD']),
+        ('yank -p', ['yp']),
+        ('yank -ps', ['yP']),
         ('paste', ['pp']),
         ('paste -s', ['pP']),
         ('paste -t', ['Pp']),


Test patch:
diff --git a/tests/integration/data/title with spaces.html b/tests/integration/data/title with spaces.html
new file mode 100644
--- /dev/null
+++ b/tests/integration/data/title with spaces.html	
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Test title</title>
+    </head>
+    <body>
+        foo
+    </body>
+</html>
diff --git a/tests/integration/features/yankpaste.feature b/tests/integration/features/yankpaste.feature
--- a/tests/integration/features/yankpaste.feature
+++ b/tests/integration/features/yankpaste.feature
@@ -33,6 +33,18 @@ Feature: Yanking and pasting.
         Then the message "Yanked domain to clipboard: http://localhost:(port)" should be shown
         And the clipboard should contain "http://localhost:(port)"
 
+    Scenario: Yanking fully encoded URL
+        When I open data/title with spaces.html
+        And I run :yank
+        Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title%20with%20spaces.html" should be shown
+        And the clipboard should contain "http://localhost:(port)/data/title%20with%20spaces.html"
+
+    Scenario: Yanking pretty decoded URL
+        When I open data/title with spaces.html
+        And I run :yank --pretty
+        Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title with spaces.html" should be shown
+        And the clipboard should contain "http://localhost:(port)/data/title with spaces.html"
+
     #### :paste
 
     Scenario: Pasting an URL