From 7c350a29d568ba6600120d7ac250e6640f4c865b Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Mon, 27 Jun 2016 22:16:25 +0200 Subject: [PATCH 1/4] Add $QUTE_CONFIG_DIR for userscripts (#937) --- qutebrowser/commands/userscripts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 2447ddb0d..530afb9f9 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -376,6 +376,7 @@ def run(cmd, *args, win_id, env, verbose=False): user_agent = config.get('network', 'user-agent') if user_agent is not None: env['QUTE_USER_AGENT'] = user_agent + env['QUTE_CONFIG_DIR'] = standarddir.config() cmd_path = os.path.expanduser(cmd) # if cmd is not given as an absolute path, look it up From 980cf5ada1010a26e70c170b2c5e7456f4b979d4 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Wed, 29 Jun 2016 13:39:18 +0200 Subject: [PATCH 2/4] Documentation, check if config dir exists --- doc/userscripts.asciidoc | 1 + qutebrowser/commands/userscripts.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/userscripts.asciidoc b/doc/userscripts.asciidoc index 04441f94b..7d1f3288b 100644 --- a/doc/userscripts.asciidoc +++ b/doc/userscripts.asciidoc @@ -33,6 +33,7 @@ The following environment variables will be set when a userscript is launched: - `QUTE_FIFO`: The FIFO or file to write commands to. - `QUTE_HTML`: Path of a file containing the HTML source of the current page. - `QUTE_TEXT`: Path of a file containing the plaintext of the current page. +- `QUTE_CONFIG_DIR`: Path of the directory containing qutebrowser's configuration. In `command` mode: diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 530afb9f9..b5ce00e76 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -376,7 +376,9 @@ def run(cmd, *args, win_id, env, verbose=False): user_agent = config.get('network', 'user-agent') if user_agent is not None: env['QUTE_USER_AGENT'] = user_agent - env['QUTE_CONFIG_DIR'] = standarddir.config() + config_dir = standarddir.config() + if config_dir is not None: + env['QUTE_CONFIG_DIR'] = config_dir cmd_path = os.path.expanduser(cmd) # if cmd is not given as an absolute path, look it up From cc67dba9f12d1a40c84a51a1faa4dae34b09639c Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Fri, 1 Jul 2016 15:53:21 +0200 Subject: [PATCH 3/4] Add and use $QUTE_DATA_DIR, $QUTE_DOWNLOAD_DIR Also fix a few small issues in the userscripts like unquoted variables and trailing whitespace. --- misc/userscripts/dmenu_qutebrowser | 5 ++--- misc/userscripts/open_download | 5 ++--- misc/userscripts/qutebrowser_viewsource | 2 +- misc/userscripts/qutedmenu | 7 +++---- qutebrowser/commands/userscripts.py | 7 +++++++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/misc/userscripts/dmenu_qutebrowser b/misc/userscripts/dmenu_qutebrowser index fbb70ca51..8e209ebec 100755 --- a/misc/userscripts/dmenu_qutebrowser +++ b/misc/userscripts/dmenu_qutebrowser @@ -39,10 +39,9 @@ [ -z "$QUTE_URL" ] && QUTE_URL='http://google.com' -url=$(echo "$QUTE_URL" | cat - ~/.config/qutebrowser/quickmarks ~/.local/share/qutebrowser/history | dmenu -l 15 -p qutebrowser) -url=$(echo $url | sed -E 's/[^ ]+ +//g' | egrep "https?:" || echo $url) +url=$(echo "$QUTE_URL" | cat - "$QUTE_CONFIG_DIR/quickmarks" "$QUTE_DATA_DIR/history" | dmenu -l 15 -p qutebrowser) +url=$(echo "$url" | sed -E 's/[^ ]+ +//g' | egrep "https?:" || echo "$url") [ -z "${url// }" ] && exit echo "open $url" >> "$QUTE_FIFO" || qutebrowser "$url" - diff --git a/misc/userscripts/open_download b/misc/userscripts/open_download index fa3e98675..a9b92d8bd 100755 --- a/misc/userscripts/open_download +++ b/misc/userscripts/open_download @@ -19,6 +19,7 @@ # Any feedback is welcome! # open a file from the download directory using rofi +DOWNLOAD_DIR=${DOWNLOAD_DIR:-$QUTE_DOWNLOAD_DIR} DOWNLOAD_DIR=${DOWNLOAD_DIR:-$HOME/Downloads} # the name of the rofi command ROFI_CMD=${ROFI_CMD:-rofi} @@ -49,7 +50,7 @@ die() { if ! [ -d "$DOWNLOAD_DIR" ] ; then die "Download directory »$DOWNLOAD_DIR« not found!" fi -if ! $(which "${ROFI_CMD}" > /dev/null ) ; then +if ! which "${ROFI_CMD}" > /dev/null ; then die "Rofi command »${ROFI_CMD}« not found in PATH!" fi @@ -109,5 +110,3 @@ fi msg info "Opening »$file« (of type $filetype) with ${application%.desktop}" xdg-open "$path" & - - diff --git a/misc/userscripts/qutebrowser_viewsource b/misc/userscripts/qutebrowser_viewsource index 0985297d7..e8481eb15 100755 --- a/misc/userscripts/qutebrowser_viewsource +++ b/misc/userscripts/qutebrowser_viewsource @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . -# +# # This script fetches the unprocessed HTML source for a page and opens it in vim. # :bind gf spawn --userscript qutebrowser_viewsource # diff --git a/misc/userscripts/qutedmenu b/misc/userscripts/qutedmenu index 2b47d0fce..3f8b13514 100755 --- a/misc/userscripts/qutedmenu +++ b/misc/userscripts/qutedmenu @@ -7,7 +7,6 @@ # If you would like to set a custom colorscheme/font use these dirs. # https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/bemenucolors readonly confdir=${XDG_CONFIG_HOME:-$HOME/.config} -readonly datadir=${XDG_DATA_HOME:-$HOME/.local/share} readonly optsfile=$confdir/dmenu/bemenucolors @@ -15,17 +14,17 @@ create_menu() { # Check quickmarks while read -r url; do printf -- '%s\n' "$url" - done < "$confdir"/qutebrowser/quickmarks + done < "$QUTE_CONFIG_DIR"/quickmarks # Next bookmarks while read -r url _; do printf -- '%s\n' "$url" - done < "$confdir"/qutebrowser/bookmarks/urls + done < "$QUTE_CONFIG_DIR"/bookmarks/urls # Finally history while read -r _ url; do printf -- '%s\n' "$url" - done < "$datadir"/qutebrowser/history + done < "$QUTE_DATA_DIR"/history } get_selection() { diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index b5ce00e76..a8e62cf39 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -29,6 +29,7 @@ from qutebrowser.utils import message, log, objreg, standarddir from qutebrowser.commands import runners, cmdexc from qutebrowser.config import config from qutebrowser.misc import guiprocess +from qutebrowser.browser.webkit import downloads class _QtFIFOReader(QObject): @@ -379,6 +380,12 @@ def run(cmd, *args, win_id, env, verbose=False): config_dir = standarddir.config() if config_dir is not None: env['QUTE_CONFIG_DIR'] = config_dir + data_dir = standarddir.data() + if data_dir is not None: + env['QUTE_DATA_DIR'] = data_dir + download_dir = downloads.download_dir() + if download_dir is not None: + env['QUTE_DOWNLOAD_DIR'] = download_dir cmd_path = os.path.expanduser(cmd) # if cmd is not given as an absolute path, look it up From 67ada0341485bf034ec84299aa4630339eb60da4 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Sat, 2 Jul 2016 13:20:11 +0200 Subject: [PATCH 4/4] Add QUTE_DATA_DIR, QUTE_DOWNLOAD_DIR documentation --- doc/userscripts.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/userscripts.asciidoc b/doc/userscripts.asciidoc index 7d1f3288b..e131bae9a 100644 --- a/doc/userscripts.asciidoc +++ b/doc/userscripts.asciidoc @@ -34,6 +34,8 @@ The following environment variables will be set when a userscript is launched: - `QUTE_HTML`: Path of a file containing the HTML source of the current page. - `QUTE_TEXT`: Path of a file containing the plaintext of the current page. - `QUTE_CONFIG_DIR`: Path of the directory containing qutebrowser's configuration. +- `QUTE_DATA_DIR`: Path of the directory containing qutebrowser's data. +- `QUTE_DOWNLOAD_DIR`: Path of the downloads directory. In `command` mode: