0

I like to be able to do export BROWSER="lynx -cfg=~/.lynx.cfg". I tried this directly, and I also tried setting an alias alias lynx="lynx -cfg=~/.lynx.cfg", but these didn't work. (Meaning that tools that use this variable to launch a browser still ignored my config file or didn't launch the browser at all.)

  • Does it work if you rename your configuration file into ~/.lynxrc and don't use an option? – Kusalananda Nov 23 '18 at 6:48
  • @Kusalananda No, it doesn't work. It seems to be using another default config file. – HappyFace Nov 23 '18 at 9:00
  • How/where did you set the alias?; How did you try to use it? – ctrl-alt-delor Nov 23 '18 at 10:04
1

$BROWSER is understood by several utilities as being your web browser of choice.

Depending on the utility, it will be expected to contain:

  1. the path or name of the executable
  2. a list of words the first of which is the path or name and the other ones a list of initial arguments. If you're lucky, it will also understand some form of quoting similar to what shells do.
  3. (very unlikely and it would be a very unwise thing to do) the start of a shell command line.

If you were in the first case, I'd expect the utility you tried it in to complain about an unexisting "lynx -cfg=~/.lynx.cfg" command.

In the third case, note that shells don't expand the ~ in -cfg=~/.lynx.cfg. zsh only does it when the magicequalsubst option is enabled. bash only expands a ~ after a = if what's on the left of = looks like a valid variable name and it's not in POSIX mode.

However lynx (at least version 2.8.9dev.16 on my system) does appear to understand ~ as meaning one's home directory by itself, so I'd expect yours to work for utilities in the second and third category.

$ BROWSER='echo -cfg=~' sensible-browser foo
-cfg=~ foo

So either your browser is of a fourth category that ignores anything but the first word or only takes a hint as to what your browser is; or your version of lynx doesn't understand ~ as meaning home.

Run your utility as strace -fe execve the-utility to see what it tries to execute.

In the case of your versions of lynx not treating ~ as home, you can define $BROWSER as:

export BROWSER="lynx -cfg=$HOME/.lynx.cfg"

(assuming $HOME doesn't contain blanks or quotes (or other characters special to a shell))

In any case, you should be able to define $BROWSER as a script that passes the correct parameters to lynx, like:

#! /bin/sh -
exec lynx -cfg="$HOME/.lynx.cfg" "$@"

and use that as your $BROWSER.

Incidentally, if your $HOME started with ~ characters, that would fool lynx, which is why it's not such a good idea for lynx to handle those ~ by itself.

1

I don't think you can however you could try:

Must use absolute path.

export BROWSER='/home/username/lynx.sh'

Create new file lynx.sh in home dir.

#!/bin/bash
linx -cfg=/home/username/.lynx.cfg

Make it exicutable.

Then:

Launching Browser should launch lynx.
or
./lynx.sh

And/Or:

Type:

whereis lynx

Use in next step.

Edit bash_aliases:

Must use absolute path to: lynx.cfg
Must use absolute path to: lynx, if not in /usr/bin/

alias=lynx='/path/to/lynx -cfg=/home/username/.lynx.cfg'

Must use ' ' if path contains special charactors.

  • I thought of the first solution and was going to post it but you beat me to it :)) I don’t understand the second solution though? How is this different from a normal alias, which I tried and it didn’t work? – HappyFace Nov 23 '18 at 7:06
  • Forgot must use absolute path.. – Michael Prokopec Nov 23 '18 at 7:16
  • The second solution doesn't work on zsh. – HappyFace Nov 23 '18 at 8:48
  • The first solution makes the tool that is using BROWSER hang, though only after adding "$@" to the end of your script. Without this change, the tool just exits after a few seconds. I tried echoing hi in the script, and it was not echoed back to me when I ran the tool. (I am running ddgr --unsafe -n 6 --noprompt '!w apple' if it helps.) – HappyFace Nov 23 '18 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.