firecat53 / urlscan

Mutt and terminal url selector (similar to urlview)
GNU General Public License v2.0
213 stars 37 forks source link

$BROWSER var empy when using --run script #94

Closed rpolve closed 3 years ago

rpolve commented 4 years ago

Expected behaviour:

Open $BROWSER to the desired URL

Actual behaviour:

Var $BROWSER is empty, you can see it by doing for example urlscan -r 'echo $BROWSER {} > plpl' test.txt; cat plpl

I've seen that other environment variable aren't empty (I tried a few, for example $TERMINAL and $EDITOR)

How to reproduce:

#!/bin/sh
$BROWSER $1
www.google.com
pluto
https://youtube.com

urlscan --run 'linkhandler {}' test.txt

Extra info:

I tried piping it too, but with no result:

urlscan --run 'xargs linkhandler' --pipe test.txt

Version:

$ cat /proc/version
Linux version 5.5.5-arch1-1 (linux@archlinux) (gcc version 9.2.1 20200130 (Arch Linux 9.2.1+20200130-2)) #1 SMP PREEMPT Thu, 20 Feb 2020 18:23:09 +0000
$ pacman -Qi urlscan
Name            : urlscan
Version         : 0.9.4-2
Description     : Mutt and terminal url selector
Architecture    : any
URL             : https://github.com/firecat53/urlscan
Licenses        : GPL2
Groups          : None
Provides        : None
Depends On      : python-urwid
Optional Deps   : xclip: Clipboard support for X11 environments [installed]
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 154.25 KiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Mon 04 Nov 2019 08:47:38 AM CET
Install Date    : Fri 15 Nov 2019 12:08:04 PM CET
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature
firecat53 commented 4 years ago

Give this commit a try. It removes a workaround I had in place to fix an old python webbrowser module bug that has since been fixed. I haven't checked yet if this will cause issues for python versions < 3.7, though.

rpolve commented 4 years ago

Thank you for your time. Unfortunately it didn't work.

This is what I did:

mkdir _test && cd _test
git clone --single-branch --branch "browser_var_empty" https://github.com/firecat53/urlscan/
cd urlscan
./setup.py install --root=".."
cd ..
echo www.test.com > test
usr/bin/urlscan -r 'echo $BROWSER {} > output' test

$ python --version Python 3.8.2

soifou commented 4 years ago

Same problem here, python 3.7 only

@rpolve I only deleted the line del os.environ['BROWSER'] in urlchoose.py and that fixed the issue for me.

What the point to remove this environment var by the way ?

firecat53 commented 4 years ago

@soifo - can you please try my browser_var_empty branch and @ryneeverett's PR? Neither have the del os.environ['BROWSER'] line. @rpolve - can you also try @ryneeverett's PR? And maybe my branch again? I really have no idea why it wouldn't be working for you.

The bug report says that this bug has been closed since 2018, which is why I deleted the whole section in browser_var_empty.

ryneeverett commented 4 years ago

The bug report says that this bug has been closed since 2018, which is why I deleted the whole section in browser_var_empty.

I'd also be fine with deleting the whole workaround. I suspect it wasn't backported to pythons before 3.7 so an update to the README might be in order if you choose this route.

Rereading the report, the bug was only introduced in development at the time so it wouldn't have been present in earlier versions.

rpolve commented 4 years ago

@rpolve - can you also try @ryneeverett's PR? And maybe my branch again? I really have no idea why it wouldn't be working for you.

Testing both @ryneeverett 's revision and the browser_var_empty branch now gives me this:

$ usr/bin/urlscan test.txt
Traceback (most recent call last):
  File "usr/bin/urlscan", line 205, in <module>
    main()
  File "usr/bin/urlscan", line 189, in main
    tui = urlchoose.URLChooser(urlscan.msgurls(msg),
TypeError: __init__() got an unexpected keyword argument 'single'

I suspect I'm doing something wrong here, but I don't understand what.

firecat53 commented 4 years ago

Yeah, something doesn't smell right. Maybe start completely over. Make sure urlscan is deleted both from /usr/lib/python3.8/site-packages, /usr/bin, /usr/local/bin/, ~/.local/bin/ and from ~/.local/lib/python3.8/site-packages. Completely remove the _test directory and then repeat the steps you posted above.

rpolve commented 4 years ago

Sorry for the late reply but I wanted to make sure to get back on the same machine, the other where I tried this must have missed some dependency that I couldn't identify...

I've tried the procedure previously decribed both with the browser_var_empty branch and with @ryneeverett 's revision, but the result is still the same as described in the original post, unfortunately.

firecat53 commented 4 years ago

I'm going to push the browser_var_empty patch to master because I still believe that it should fix your issue, as there is no longer any code that affects the value of $BROWSER. Install urlscan to your system (instead of just to a local directory) and try again. Ensure $BROWSER is set either in .bashrc or in the current terminal session you are using.

As an aside, can I ask what exactly were you trying to accomplish when you found this issue?

I'll leave this issue open for now.

rpolve commented 4 years ago

I'm going to push the browser_var_empty patch to master because I still believe that it should fix your issue

Yes, you were right. Doing a fresh system install from git solved the problem.

I apologize for having been less than effective at debugging this.

can I ask what exactly were you trying to accomplish when you found this issue?

I think I forgot, but probably not anything specific. If I'm not mistaken I encountered this problem when I was trying to hack at this other issue.

firecat53 commented 4 years ago

No worries, glad it worked for you finally.

After reading your neomutt issue, I'd suggest that you maybe add to your issue what you were originally trying to accomplish. Sometimes just having the steps to reproduce without some context makes debugging more challenging