从任何地方谷歌搜索查询

有时当我在我的终端上工作时,我遇到了一些错误。 要解决这些问题,我必须手动将错误消息粘贴到Google并搜索解决方案。

是否可以选择消息并右键单击以获取“Google it”选项,而不必手动粘贴和搜索?

我不是要求从终端执行Google搜索或从终端浏览网页。 我想要的是更通用的东西。 我希望能够选择一段文字并通过右键单击(或使用键盘快捷键)获得“Google选定文本”。 我希望搜索在浏览器中进行。

幸运的是, tualatrix在gnome-terminal上做了一个小小的黑客攻击,并在右键单击消息时添加了对Google搜索的支持。

您需要添加第三方PPA才能使用它。 在终端中运行以下命令:

sudo add-apt-repository ppa:tualatrix/personal sudo apt-get update sudo apt-get install gnome-terminal 

更新后,关闭所有终端窗口并再次重新打开。 它将按预期工作。

gnome-terminal与Google支持黑客攻击

Keybind sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"' -c’firefox sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"'系统设置 – > 键盘 – > 自定义

或者使用以下脚本,您可以在Google搜索之前编辑鼠标选择。

 #!/bin/bash # get mouse selection QUERY=$(xclip -o) # edit selection QUERY=$(zenity --entry --entry-text="$QUERY" --text='Google') [ "$?" != 0 ] && exit 0 # search google in firefox (you can use google-chrome, chromium, opera ..) firefox "https://www.google.com/search?q=${QUERY}" exit 0 

要使用此脚本,请将其复制/粘贴到新文本文件(gedit ..)中,并将其命名为您喜欢的名称,例如google_clip.sh 。 设置执行权限, chmod +x /filepath/google_clip.sh或右键单击Nautilus,然后单击属性 – > 权限 – >选中执行 。 然后键绑定它。

我有类似的要求,我发现每次按下一组键盘按钮(例如Ctrl + Shift + G )时, Autokey对于能够通过激活python脚本(下面)搜索任何选定的文本非常有帮助。

 import webbrowser base="http://www.google.com/search?q=" phrase=clipboard.get_selection() #Remove trailing or leading white space and find if there are multiple #words. phrase=phrase.strip() singleWord=False if phrase.find(' ')<0: singleWord=True #Generate search URL. if singleWord: search_url=base+phrase if (not singleWord): phrase='+'.join(phrase.split()) search_url=base+phrase webbrowser.open_new_tab(search_url) 

有关如何使用Autokey的教程可以在这里找到: 教程