Coder Social home page Coder Social logo

open-urls's Introduction

Description

open-urls is a simple tool to open one or more web pages in browser tabs. It reads the URL's (or URI's) to open from a configuration file, but can also read the from standard input (stdin).

It provides a very thin wrapper over the underlying crate.

Why?

Opening a URL on the command line

Opening a URL on the command line is fraught with problems. Although simple sites can be handled easily enough:

$ firefox --new-tab "https://example.com"

Complications can arise if you try to open URLs like this:

$ firefox --new-tab "https://example.com/search?foo=bar&something=a+b+c&done=true&term=hello%20world"

Why? Because the URLs can contain shell meta-characters such as ?, &.

It can get even more confusing if you want to expand a variable in a URL as you would need to expand that, but not other parts of the URL:

$ firefox --new-tab "https://example.com/search?foo=$SEARCH_TERM&something=a+b+c&done=$done&term=hello%20world"

Hence, opening a URL from a shell can easily cause unintended side-effects and corrupt the URL, meaning you cannot open it ;)

Opening a URL in a crontab

It should be simple right? Not always. Will the following work as expected?

DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
DISPLAY=:0.0

# minute hour  monthday month weekday             command
# 0-59   0-23  1-31     1-12  0-7 (0 or 7=Sunday) ...
0 8 * * * firefox --new-tab 'https://example.com/search?foo=bar&something=a+b+c&done=true&term=hello%20world'

Answer: no! Not only do you need to worry about shell meta characters, you also need to worry about the percent character (%) since cron(8) will convert percentage symbols to newlines and send everything that follows to the standard input of the command!

Install

  • Install rust

  • Ensure the Cargo bin directory is in your $PATH:

    $ export PATH=$PATH:$HOME/.cargo/bin
  • Checkout the code

    $ git clone https://github.com/jamesodhunt/open-urls
    $ cd open-urls
  • Build and install:

    $ make

    Or,

    $ cargo install --path .

Usage

Minimal example

$ open-urls -c urls.conf

Command-line options

There are a few available options.

Run the following for details:

$ open-urls --help

Config file

The config file format:

  • Assumes one URL / line.
  • Uses # for comment lines that are ignored.
  • Permits blank lines.
  • Supports two fields, separated by a semi-colon (;) character:
    • The first field is the URL to open.
    • The second field is an optional browser (binary) name (which must be in your $PATH).

Config example

# This line is a comment.

# The URL on the line below will, by default, be opened with your system's default browser
https://github.com

# However, the URL on the line below will, by default, be opened with the specified browser.
https://gitlab.com;firefox

Limitations

You cannot open a URL and have the browser background it. What this means is that if you are viewing a tab and then you open a URL using this tool with the same browser, the browser will -- annoyingly -- switch to the newly opened tab.

This is a limitation of the underlying crate.

open-urls's People

Contributors

jamesodhunt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.