Giter Club home page Giter Club logo

Comments (4)

xwmx avatar xwmx commented on July 17, 2024 1

@weierophinney Thanks for the information! Your comment prompted me to add a $NB_BROWSER variable that can be set instead of $BROWSER, in case that's helpful.

from nb.

xwmx avatar xwmx commented on July 17, 2024

Thanks for the suggestion!

I looked into it a bit and it appears that the best first step is to respect the user's $BROWSER environment variable, which can be set in .bashrc, .zshrc, or similar:

export BROWSER=lynx

This variable is not standard, but it is included in the Debian and Arch documentation. nb should work when this is set to a browser command with or without options. nb does not support more complex $BROWSER values, like a "colon-delimited list of commands" mentioned in the Debian documentation.

So as of version 5.6.1, nb now checks the environment for a $BROWSER environment variable and uses the specified browser instead of always defaulting to w3m. Currently it only fully supports w3m and lynx. If $BROWSER is not set, it falls back to w3m and then lynx.

Note that this also makes it possible to easily specify a different browser for an individual command:

> BROWSER=lynx nb 12 peek
# opens the URL from bookmark 12 in lynx

> BROWSER=w3m nb 12 peek
# opens the URL from bookmark 12 in w3m

w3m is still used to escape HTML entities from titles and descriptions when saving a bookmark. When w3m is not available, the title and description are saved without escaping HTML entities. I feel that this is OK given that w3m is a recommended dependency, the only platform I'm aware of that w3m doesn't work on is WSL 1, and adding lynx support for that particular operation doesn't seem critical since it's internal and not exposed to the user. I added TODO comments indicating that these operations should become browser-agnostic when time permits.

A setting has not yet been added within nb for the browser. I'd like to see how it goes just respecting the $BROWSER environment variable. I'm trying to avoid adding too many lines to nb and want to see what other settings might need to be added.

I'm going to close this as complete. If you have any feedback, please let me know.

I hope this helps!

from nb.

weierophinney avatar weierophinney commented on July 17, 2024

Leaving a note here in case anybody else comes across a similar issue I encountered.

I use ubuntu, and $BROWSER is set to /usr/bin/x-www-browser, which eventually resolves to the browser alternative you have set, which is generally your GUI browser. I wanted to instead use w3m by default so that I stay in the CLI. As such, I wrote the following function in my shell configuration:

nb () {
    BROWSER=w3m nb "$@"
}

This works great. However...

Occasionally when in w3m, I want to open a link or the current page in my GUI browser (for example, if I have a link to an external site). w3m has command bindings for this (Esc M and M, respectively), and you can configure which browser to open (defaults to /usr/bin/sensible-browser, which, again, eventually resolves to the GUI browser).

The problem? sensible-browser uses the $BROWSER value, which means everything opens in w3m.

I found two ways to fix this:

  • When in w3m, press "o" to open the options screen. Find the External browser setting, and set it to the specific binary of the browser you use.
  • Since the above means that if you switch your default browser, w3m will still be opening your previous, the better way is to just clear the $BROWSER value when opening nb:
    nb () {
        BROWSER= nb "$@"
    }

This latter works perfectly, and is future-proof with any changes in your default browser.

from nb.

weierophinney avatar weierophinney commented on July 17, 2024

Works brilliantly! I've set NB_BROWSER in my shell configuration, and now can remove the nb() function definition entirely!

Thanks, @xwmx !

from nb.

Related Issues (20)

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.