URLで閉じ括弧を避けるには、firefox -remoteを使用してください。

URLで閉じ括弧を避けるには、firefox -remoteを使用してください。

私はこのコマンドを持っています(詳細はGoogleが選択したテキストのショートカット):

sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(xsel),new-tab)"'

しかし、それで終わるテキストを選択すると、閉じ)括弧で解析されます。

解決策はありますか? (なんとか脱出してるみたいですか?)

ベストアンサー1

返された文字列をURLエンコードする必要がありますxselPythonの使用:

sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$(xsel)"),new-tab)"'

パールを使う:

sh -c 'firefox -remote "openURL(http://www.google.com/search?q=$(perl -MURI::Escape -e '\''print uri_escape($ARGV[0]);'\'' "$(xsel)"),new-tab)"'

説明する

Google検索の実行をリクエストしたときにfirefox何が起こるのかを確認してくださいfoo()

$ firefox -remote 'openURL(http://www.google.com/search?q=Foo(),new-tab)'
Error: Failed to send command: 500 command not parseable

「解析可能」にするには、文字をURLエンコードする必要があります。たとえば、Foo()エンコード後は次のようになります。

$ python -c "import urllib, sys; print urllib.quote(sys.argv[1])"  "Foo()"
Foo%28%29

おすすめ記事