From 1067ca480638aa98c1b7f16f4db9821c7aeb95ca Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 9 Feb 2022 00:21:57 +0300 Subject: [PATCH] webbrowser: Allow to open a new window/tab without an URL --- bin/webbrowser | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/webbrowser b/bin/webbrowser index 0590aa0..674ad69 100755 --- a/bin/webbrowser +++ b/bin/webbrowser @@ -11,17 +11,26 @@ import webbrowser if sys.argv[1] in ("-t", "--tab"): new = 2 - url = sys.argv[2] + try: + url = sys.argv[2] + except IndexError: + url = '' elif sys.argv[1] in ("-n", "--new"): new = 1 - url = sys.argv[2] + try: + url = sys.argv[2] + except IndexError: + url = '' else: new = 0 - url = sys.argv[1] + try: + url = sys.argv[1] + except IndexError: + url = '' -if '://' not in url: # Make an URL from a local file name +if url and '://' not in url: # Make an URL from a local file name url = 'file://' + os.path.abspath(url) webbrowser.open(url, new) -- 2.39.5