Hello community, here is the log from the commit of package ddgr for openSUSE:Factory checked in at 2018-05-29 10:48:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ddgr (Old) and /work/SRC/openSUSE:Factory/.ddgr.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ddgr" Tue May 29 10:48:23 2018 rev:2 rq:612512 version:1.4 Changes: -------- --- /work/SRC/openSUSE:Factory/ddgr/ddgr.changes 2018-01-31 19:54:20.278651514 +0100 +++ /work/SRC/openSUSE:Factory/.ddgr.new/ddgr.changes 2018-05-29 10:48:25.188743920 +0200 @@ -1,0 +2,8 @@ +Wed May 2 06:10:01 UTC 2018 - sebix+novell....@sebix.at + +- update to version 1.4: + - Copy URL at omniprompt + - Check default stdout encoding at start + - New environment variable DISABLE_PROMPT_COLOR + +------------------------------------------------------------------- Old: ---- v1.2.tar.gz New: ---- v1.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ddgr.spec ++++++ --- /var/tmp/diff_new_pack.MBzi1R/_old 2018-05-29 10:48:26.144708650 +0200 +++ /var/tmp/diff_new_pack.MBzi1R/_new 2018-05-29 10:48:26.144708650 +0200 @@ -17,10 +17,10 @@ Name: ddgr -Version: 1.2 +Version: 1.4 Release: 0 Summary: DuckDuckGo from the terminal -License: GPL-3.0 +License: GPL-3.0-only Group: Productivity/Networking/Web/Utilities URL: https://github.com/jarun/ddgr Source: https://github.com/jarun/ddgr/archive/v%{version}.tar.gz ++++++ v1.2.tar.gz -> v1.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ddgr-1.2/CHANGELOG new/ddgr-1.4/CHANGELOG --- old/ddgr-1.2/CHANGELOG 2017-12-08 13:53:10.000000000 +0100 +++ new/ddgr-1.4/CHANGELOG 2018-04-05 01:26:45.000000000 +0200 @@ -1,4 +1,14 @@ -ddgr 1.2 +ddgr v1.4 +2018-04-05 + +What's in? +- Copy URL at omniprompt +- Check default stdout encoding at start +- New environment variable DISABLE_PROMPT_COLOR + +------------------------------------------------------------------------------- + +ddgr v1.2 2017-12-08 What's in? @@ -8,7 +18,7 @@ ------------------------------------------------------------------------------- -ddgr 1.1 +ddgr v1.1 2017-11-29 What's in? @@ -21,7 +31,7 @@ ------------------------------------------------------------------------------- -ddgr 1.0 +ddgr v1.0 2017-11-05 What's in? diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ddgr-1.2/README.md new/ddgr-1.4/README.md --- old/ddgr-1.2/README.md 2017-12-08 13:53:10.000000000 +0100 +++ new/ddgr-1.4/README.md 2018-04-05 01:26:45.000000000 +0200 @@ -3,22 +3,33 @@ <p align="center"> <a href="https://github.com/jarun/ddgr/releases/latest"><img src="https://img.shields.io/github/release/jarun/ddgr.svg?maxAge=600" alt="Latest release" /></a> <a href="https://aur.archlinux.org/packages/ddgr"><img src="https://img.shields.io/aur/version/ddgr.svg?maxAge=600" alt="AUR" /></a> +<a href="http://formulae.brew.sh/formula/ddgr"><img src="https://img.shields.io/homebrew/v/ddgr.svg?maxAge=600" alt="Homebrew" /></a> <a href="https://packages.debian.org/search?keywords=ddgr&searchon=names&exact=1"><img src="https://img.shields.io/badge/debian-10+-blue.svg?maxAge=2592000" alt="Debian Buster+" /></a> +<a href="https://apps.fedoraproject.org/packages/ddgr"><img src="https://img.shields.io/badge/fedora-26+-blue.svg?maxAge=2592000" alt="Fedora 26+" /></a> +<a href="https://software.opensuse.org/package/ddgr"><img src="https://img.shields.io/badge/opensuse%20leap-15.0+-blue.svg?maxAge=2592000" alt="openSUSE Leap 15.0+" /></a> <a href="https://packages.ubuntu.com/search?keywords=ddgr&searchon=names&exact=1"><img src="https://img.shields.io/badge/ubuntu-18.04+-blue.svg?maxAge=2592000" alt="Ubuntu Bionic+" /></a> -<a href="https://launchpad.net/~twodopeshaggy/+archive/ubuntu/jarun/"><img src="https://img.shields.io/badge/ubuntu-PPA-blue.svg?maxAge=2592000" alt="Ubuntu PPA" /></a> +</p> + +<p align="center"> <a href="https://github.com/jarun/ddgr/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-GPLv3-yellow.svg?maxAge=2592000" alt="License" /></a> <a href="https://travis-ci.org/jarun/ddgr"><img src="https://travis-ci.org/jarun/ddgr.svg?branch=master" alt="Build Status" /></a> </p> +<p align="center"> +<a href="https://asciinema.org/a/151849"><img src="https://asciinema.org/a/151849.png" alt="Asciicast" width="734"/></a> +</p> + `ddgr` is a cmdline utility to search DuckDuckGo from the terminal. While [`googler`](https://github.com/jarun/googler) is highly popular among cmdline users, in many forums the need of a similar utility for privacy-aware DuckDuckGo came up. [DuckDuckGo Bangs](https://duckduckgo.com/bang) are super-cool too! So here's `ddgr` for you! Unlike the web interface, you can specify the number of search results you would like to see per page. It's more convenient than skimming through 30-odd search results per page. The default interface is carefully designed to use minimum space without sacrificing readability. `ddgr` isn't affiliated to DuckDuckGo in any way. +*Love smart and efficient terminal utilities? Explore my repositories. Buy me a cup of coffee if they help you.* + <p align="center"> <a href="https://saythanks.io/to/jarun"><img src="https://img.shields.io/badge/say-thanks!-ff69b4.svg" /></a> -<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q"><img src="https://img.shields.io/badge/Donate-$5-green.svg" alt="Donate via PayPal!" /></a> +<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q"><img src="https://img.shields.io/badge/PayPal-donate-green.svg" alt="Donate via PayPal!" /></a> </p> ### Table of contents @@ -37,6 +48,7 @@ - [Text-based browser integration](#text-based-browser-integration) - [Colors](#colors) - [Examples](#examples) +- [Troubleshooting](#troubleshooting) - [Collaborators](#collaborators) - [In the Press](#in-the-press) @@ -63,21 +75,29 @@ `ddgr` requires Python 3.4 or later. Only the latest patch release of each minor version is supported. +To copy url to clipboard at the omniprompt, `ddgr` uses `xsel` on Linux, `pbcopy` (default installed) on OS X and `clip` (default installed) on Windows. + Note: v1.1 and below require the Python3 `requests` library to make HTTPS requests. This dependency is removed in the later releases. #### From a package manager -- [AUR](https://aur.archlinux.org/packages/ddgr/) -- [Debian](https://packages.debian.org/search?keywords=ddgr&searchon=names&exact=1) +- [AUR](https://aur.archlinux.org/packages/ddgr/) (`pacman -S ddgr`) +- [Debian](https://packages.debian.org/search?keywords=ddgr&searchon=names&exact=1) (`apt-get install ddgr`) +- [Fedora](https://apps.fedoraproject.org/packages/ddgr) (`dnf install ddgr`) - [FreeBSD](https://www.freshports.org/www/ddgr/) (`pkg install ddgr`) -- [Snap Store](https://snapcraft.io/ddgr/) (`sudo snap install ddgr`) -- [Ubuntu](https://packages.ubuntu.com/search?keywords=ddgr&searchon=names&exact=1) -- [Ubuntu PPA](https://launchpad.net/~twodopeshaggy/+archive/ubuntu/jarun/) -- [Void Linux](https://github.com/voidlinux/void-packages/tree/master/srcpkgs/ddgr) (`sudo xbps-install -S ddgr`) +- [Homebrew](http://formulae.brew.sh/formula/ddgr) (`brew install ddgr`) +- [NixOS](https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/misc/ddgr) (`nix-env -i ddgr`) +- [openSUSE](https://software.opensuse.org/package/ddgr) (`zypper in ddgr`) +- [Slackware](http://slackbuilds.org/repository/14.2/network/ddgr/) (`slackpkg install ddgr`) +- [Snap Store](https://snapcraft.io/ddgr/) (`snap install ddgr`) +- [Source Mage](http://codex.sourcemage.org/test/utils/ddgr/) (`cast ddgr`) +- [Ubuntu](https://packages.ubuntu.com/search?keywords=ddgr&searchon=names&exact=1) (`apt-get install ddgr`) +- [Ubuntu PPA](https://launchpad.net/~twodopeshaggy/+archive/ubuntu/jarun/) (`apt-get install ddgr`) +- [Void Linux](https://github.com/voidlinux/void-packages/tree/master/srcpkgs/ddgr) (`xbps-install -S ddgr`) #### Release packages -Packages for Arch Linux, CentOS, Debian, Fedora and Ubuntu are available with the [latest stable release](https://github.com/jarun/ddgr/releases/latest). +Packages for Arch Linux, CentOS, Debian, Fedora, OpenSUSE Leap and Ubuntu are available with the [latest stable release](https://github.com/jarun/ddgr/releases/latest). #### From source @@ -150,6 +170,7 @@ d keywords new DDG search for 'keywords' with original options should be used to search omniprompt keys and indices x toggle url expansion + c index copy url to clipboard q, ^D, double Enter exit ddgr ? show omniprompt help * other inputs are considered as new search keywords @@ -188,11 +209,13 @@ 3. **DuckDuckGo Bang** search `hello world` in Wikipedia: $ ddgr !w hello world + $ ddgr \!w hello world // bash-specific, need to escape ! on bash Bangs work at the omniprompt too. To look up bangs, visit https://duck‐duckgo.com/bang?#bangs-list. 4. **Bang alias** to fire from the cmdline, open results in a GUI browser and exit: alias bang='ddgr --gb --np' $ bang !w hello world + $ bang \!w hello world // bash-specific, need to escape ! on bash 5. **Website specific** search: $ ddgr -w amazon.com digital camera @@ -224,6 +247,12 @@ d g keywords d 1 +### Troubleshooting + +1. Some users have reported problems with a colored omniprompt (refer to issue [#40](https://github.com/jarun/ddgr/issues/40)) with iTerm2 on OS X. To force a plain omniprompt: + + export DISABLE_PROMPT_COLOR=1 + ### Collaborators - [Arun Prakash Jana](https://github.com/jarun) @@ -231,10 +260,12 @@ - [SZ Lin](https://github.com/szlin) - [Alex Gontar](https://github.com/mosegontar) -Copyright © 2016-2017 [Arun Prakash Jana](mailto:engineera...@gmail.com) +Copyright © 2016-2018 [Arun Prakash Jana](mailto:engineera...@gmail.com) ### In the Press +- [Fossbytes](https://fossbytes.com/search-duckduckgo-from-terminal-ddgr/) - [Information Security Squad](http://itsecforu.ru/2017/11/21/%D0%BA%D0%B0%D0%BA-%D0%B8%D1%81%D0%BA%D0%B0%D1%82%D1%8C-%D0%B2-duckduckgo-%D0%B8%D0%B7-%D0%BA%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D0%BD%D0%BE%D0%B9-%D1%81%D1%82%D1%80%D0%BE%D0%BA%D0%B8-linux/) - [LinOxide](https://linoxide.com/tools/search-duckduckgo-command-line/) - [OMG! Ubuntu!](http://www.omgubuntu.co.uk/2017/11/duck-duck-go-terminal-app) +- [Tecmint](https://www.tecmint.com/search-duckduckgo-from-linux-terminal/) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ddgr-1.2/ddgr new/ddgr-1.4/ddgr --- old/ddgr-1.2/ddgr 2017-12-08 13:53:10.000000000 +0100 +++ new/ddgr-1.4/ddgr 2018-04-05 01:26:45.000000000 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2016-2017 Arun Prakash Jana <engineera...@gmail.com> +# Copyright (C) 2016-2018 Arun Prakash Jana <engineera...@gmail.com> # # 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 @@ -16,15 +16,18 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import argparse +import codecs import collections import functools import gzip import html.entities import html.parser +import locale import logging import os +import shutil import signal -import subprocess +from subprocess import Popen, PIPE, DEVNULL import sys import textwrap import urllib.error @@ -52,7 +55,7 @@ # Constants -_VERSION_ = '1.2' +_VERSION_ = '1.4' COLORMAP = {k: '\x1b[%sm' % v for k, v in { 'a': '30', 'b': '31', 'c': '32', 'd': '33', @@ -95,7 +98,7 @@ # Custom URL handler gets max priority if hasattr(open_url, 'url_handler'): - p = subprocess.Popen([open_url.url_handler, url], stdin=subprocess.PIPE) + p = Popen([open_url.url_handler, url], stdin=PIPE) p.communicate() return @@ -166,6 +169,62 @@ return code, payload +def unwrap(text): + """Unwrap text.""" + lines = text.split('\n') + result = '' + for i in range(len(lines) - 1): + result += lines[i] + if not lines[i]: + # Paragraph break + result += '\n\n' + elif lines[i + 1]: + # Next line is not paragraph break, add space + result += ' ' + # Handle last line + result += lines[-1] if lines[-1] else '\n' + return result + + +def check_stdout_encoding(): + """Make sure stdout encoding is utf-8. + + If not, print error message and instructions, then exit with + status 1. + + This function is a no-op on win32 because encoding on win32 is + messy, and let's just hope for the best. /s + """ + if sys.platform == 'win32': + return + + # Use codecs.lookup to resolve text encoding alias + encoding = codecs.lookup(sys.stdout.encoding).name + if encoding != 'utf-8': + locale_lang, locale_encoding = locale.getlocale() + if locale_lang is None: + locale_lang = '<unknown>' + if locale_encoding is None: + locale_encoding = '<unknown>' + ioencoding = os.getenv('PYTHONIOENCODING', 'not set') + sys.stderr.write(unwrap(textwrap.dedent("""\ + stdout encoding '{encoding}' detected. ddgr requires utf-8 to + work properly. The wrong encoding may be due to a non-UTF-8 + locale or an improper PYTHONIOENCODING. (For the record, your + locale language is {locale_lang} and locale encoding is + {locale_encoding}; your PYTHONIOENCODING is {ioencoding}.) + + Please set a UTF-8 locale (e.g., en_US.UTF-8) or set + PYTHONIOENCODING to utf-8. + """.format( + encoding=encoding, + locale_lang=locale_lang, + locale_encoding=locale_encoding, + ioencoding=ioencoding, + )))) + sys.exit(1) + + def printerr(msg): """Print message, verbatim, to stderr. @@ -173,6 +232,7 @@ """ print(msg, file=sys.stderr) + # Classes class DdgUrl(object): @@ -1105,9 +1165,6 @@ """ - # Class variables - colors = None - def __init__(self, opts): super().__init__() self.index = 0 @@ -1120,6 +1177,11 @@ self.results = [] self._urltable = {} + colors = self.colors + message = 'ddgr (? for help)' + self.prompt = ((colors.prompt + message + colors.reset + ' ') + if (colors and os.getenv('DISABLE_PROMPT_COLOR') is None) else (message + ': ')) + @property def options(self): """Current options.""" @@ -1245,7 +1307,7 @@ """Show omniprompt and read user command line. Command line is always stripped, and each consecutive group of - whitespace is replaced with a single space charater. If the + whitespace is replaced with a single space character. If the command line is empty after stripping, when ignore it and keep reading. Exit with status 0 if we get EOF or an empty line (pre-strip, that is, a raw <enter>) twice in a row. @@ -1253,13 +1315,10 @@ The new command line (non-empty) is stored in ``self.cmd``. """ - colors = self.colors - message = 'ddgr (? for help)' - prompt = (colors.prompt + message + colors.reset + ' ') if colors else (message + ': ') enter_count = 0 while True: try: - cmd = input(prompt) + cmd = input(self.prompt) except EOFError: sys.exit(0) @@ -1455,6 +1514,29 @@ elif cmd == 'x': Result.urlexpand = not Result.urlexpand printerr('url expansion toggled.') + elif cmd.startswith('c ') and cmd[2:].isdigit(): + try: + # try copying the url to clipboard using native utilities + if sys.platform.startswith(('linux', 'freebsd', 'openbsd')): + if shutil.which('xsel') is None: + raise FileNotFoundError + copier_params = ['xsel', '-b', '-i'] + elif sys.platform == 'darwin': + copier_params = ['pbcopy'] + elif sys.platform == 'win32': + copier_params = ['clip'] + else: + copier_params = [] + + if not copier_params: + printerr('operating system not identified') + else: + Popen(copier_params, stdin=PIPE, stdout=DEVNULL, + stderr=DEVNULL).communicate(self._urltable[cmd[2:]].encode('utf-8')) + except FileNotFoundError: + printerr('xsel missing') + except Exception: + raise NoKeywordsException else: self.do_ddg(cmd) except NoKeywordsException: @@ -1477,6 +1559,7 @@ d keywords new DDG search for 'keywords' with original options should be used to search omniprompt keys and indices x toggle url expansion + c index copy url to clipboard q, ^D, double Enter exit ddgr ? show omniprompt help * other inputs are considered as new search keywords @@ -1488,7 +1571,7 @@ file = sys.stderr if file is None else file file.write(textwrap.dedent(""" Version %s - Copyright © 2016-2017 Arun Prakash Jana <engineera...@gmail.com> + Copyright © 2016-2018 Arun Prakash Jana <engineera...@gmail.com> License: GPLv3 Webpage: https://github.com/jarun/ddgr """ % _VERSION_)) @@ -1653,6 +1736,8 @@ if opts.complete is not None: completer_run(opts.complete) + check_stdout_encoding() + # Add cmdline args to readline history if opts.keywords: try: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ddgr-1.2/ddgr.1 new/ddgr-1.4/ddgr.1 --- old/ddgr-1.2/ddgr.1 2017-12-08 13:53:10.000000000 +0100 +++ new/ddgr-1.4/ddgr.1 2018-04-05 01:26:45.000000000 +0200 @@ -1,4 +1,4 @@ -.TH "DDGR" "1" "08 Dec 2017" "Version 1.2" "User Commands" +.TH "DDGR" "1" "05 Apr 2018" "Version 1.4" "User Commands" .SH NAME ddgr \- DuckDuckGo from the terminal .SH SYNOPSIS @@ -101,6 +101,9 @@ .BI "x" Toggle url expansion. .TP +.BI "c index" +Copy url to clipboard. +.TP .BI "q, ^D, double Enter" Exit ddgr. .TP @@ -194,6 +197,9 @@ .BI DDGR_COLORS Refer to the \fBCOLORS\fR section. .TP +.BI DISABLE_PROMPT_COLOR +Force a plain omniprompt if you are facing issues with colors at the prompt. +.TP .BI "HTTPS_PROXY, https_proxy" Refer to the \fB--proxy\fR option. .SH EXAMPLES @@ -220,6 +226,7 @@ .EX .IP .B ddgr !w hello world +.B ddgr \\\\!w hello world // bash-specific, need to escape ! on bash .EE .PP .IP "" 4 @@ -233,6 +240,7 @@ .B alias bang='ddgr --gb --np' .IP .B bang !w hello world +.B bang \\\\!w hello world // bash-specific, need to escape ! on bash .EE .PP .IP 5. 4 @@ -324,7 +332,7 @@ .SH REPORTING BUGS .I https://github.com/jarun/ddgr/issues .SH LICENSE -Copyright \(co 2016-2017 Arun Prakash Jana <engineera...@gmail.com> +Copyright \(co 2016-2018 Arun Prakash Jana <engineera...@gmail.com> .PP License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. .br diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ddgr-1.2/packagecore.yaml new/ddgr-1.4/packagecore.yaml --- old/ddgr-1.2/packagecore.yaml 2017-12-08 13:53:10.000000000 +0100 +++ new/ddgr-1.4/packagecore.yaml 2018-04-05 01:26:45.000000000 +0200 @@ -30,6 +30,16 @@ - make deps: - python3 + fedora27: + builddeps: + - make + deps: + - python3 + opensuse42.2: + builddeps: + - make + deps: + - python3 opensuse42.3: builddeps: - make