From 8e5e388488336c84507b6ac0ccafa13276ed956a Mon Sep 17 00:00:00 2001 From: Phantop Date: Mon, 9 Nov 2020 22:05:24 -0500 Subject: [PATCH] Qute: simpler downloads list is better, more at 11 --- .config/qutebrowser/config.py | 5 +- .config/qutebrowser/userscripts/downloads | 114 ---------------------- 2 files changed, 2 insertions(+), 117 deletions(-) delete mode 100755 .config/qutebrowser/userscripts/downloads diff --git a/.config/qutebrowser/config.py b/.config/qutebrowser/config.py index 81ffcd3..a7641cd 100644 --- a/.config/qutebrowser/config.py +++ b/.config/qutebrowser/config.py @@ -37,9 +37,6 @@ config.set('content.persistent_storage', True, 'https://mega.nz') config.bind('', 'close') config.bind('', 'tab-close') -config.bind('sd', 'spawn -u downloads') -config.bind('', 'spawn -u readability') - c.aliases['mpv'] = "spawn -m -d -v mpv --ytdl-raw-options=write-sub=,write-auto-sub=,embed-subs=,sub-lang=en}" config.bind('', 'mpv {url}') config.bind('', 'mpv --ytdl-format=bestvideo[vcodec^=avc1]+bestaudio {url}') @@ -53,9 +50,11 @@ c.aliases['dotepub'] = "jseval -u -q javascript:(function()%7Btry%7Bvar%20d=docu config.bind('se', "dotepub") c.aliases['remove-sticky'] = "jseval -u -q javascript:(function()%7B%20let%20i%2C%20elements%20%3D%20document.querySelectorAll('body%20*')%3B%20for%20(i%20%3D%200%3B%20i%20%3C%20elements.length%3B%20i%2B%2B)%20%7B%20if(getComputedStyle(elements%5Bi%5D).position%20%3D%3D%3D%20'fixed'%20%7C%7C%20getComputedStyle(elements%5Bi%5D).position%20%3D%3D%3D%20'sticky')%7B%20elements%5Bi%5D.parentNode.removeChild(elements%5Bi%5D)%3B%20%7D%20%7D%20%7D)()" config.bind('sr', "remove-sticky") +config.bind('', 'spawn -u readability') config.bind('st', 'config-cycle -t content.proxy socks://localhost:9050/ system') config.bind('sc', 'config-cycle -t content.user_stylesheets adapta.css ""') +config.bind('sd', "spawn fish -c 'xdg-open ~/Downloads/(ls ~/Downloads | rofi -location 6 -dmenu)'") # APPEARANCE # diff --git a/.config/qutebrowser/userscripts/downloads b/.config/qutebrowser/userscripts/downloads deleted file mode 100755 index 960c930..0000000 --- a/.config/qutebrowser/userscripts/downloads +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env bash -# Both standalone script and qutebrowser userscript that opens a rofi menu with -# all files from the download directory and opens the selected file. It works -# both as a userscript and a standalone script that is called from outside of -# qutebrowser. -# -# Suggested keybinding (for "show downloads"): -# spawn --userscript ~/.config/qutebrowser/open_download -# sd -# -# Requirements: -# - rofi (in a recent version) -# - xdg-open and xdg-mime -# - You should configure qutebrowser to download files to a single directory -# - It comes in handy if you enable downloads.remove_finished. If you want to -# see the recent downloads, just press "sd". -# -# Thorsten Wißmann, 2015 (thorsten` on freenode) -# Any feedback is welcome! - -set -e - -# 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} -ROFI_ARGS=${ROFI_ARGS:-} - -msg() { - local cmd="$1" - shift - local msg="$*" - if [ -z "$QUTE_FIFO" ] ; then - echo "$cmd: $msg" >&2 - else - echo "message-$cmd '${msg//\'/\\\'}'" >> "$QUTE_FIFO" - fi -} -die() { - msg error "$*" - if [ -n "$QUTE_FIFO" ] ; then - # when run as a userscript, the above error message already informs the - # user about the failure, and no additional "userscript exited with status - # 1" is needed. - exit 0; - else - exit 1; - fi -} - -if ! [ -d "$DOWNLOAD_DIR" ] ; then - die "Download directory »$DOWNLOAD_DIR« not found!" -fi -if ! command -v "${ROFI_CMD}" > /dev/null ; then - die "Rofi command »${ROFI_CMD}« not found in PATH!" -fi - -rofi_default_args=( - -monitor -2 # place above window - -location 6 # aligned at the bottom - -i - -no-custom - -format i # make rofi return the index - -l 10 - -p 'Open download' -dmenu - ) - -crop-first-column() { - local maxlength=${1:-40} - local expression='s|^\([^\t]\{0,'"$maxlength"'\}\)[^\t]*\t|\1\t|' - sed "$expression" -} - -ls-files() { - # add the slash at the end of the download dir enforces to follow the - # symlink, if the DOWNLOAD_DIR itself is a symlink - # shellcheck disable=SC2010 - ls -Q --quoting-style escape -h -o -1 -A -t "${DOWNLOAD_DIR}/" \ - | grep '^[-]' \ - | cut -d' ' -f3- \ - | sed 's,^\(.*[^\]\) \(.*\)$,\2\t\1,' \ - | sed 's,\\\(.\),\1,g' | sort -} - -mapfile -t entries < <(ls-files) - -# we need to manually check that there are items, because rofi doesn't show up -# if there are no items and -no-custom is passed to rofi. -if [ "${#entries[@]}" -eq 0 ] ; then - die "Download directory »${DOWNLOAD_DIR}« empty" -fi - -line=$(printf '%s\n' "${entries[@]}" \ - | crop-first-column 55 \ - | column -s $'\t' -t \ - | $ROFI_CMD "${rofi_default_args[@]}" "$ROFI_ARGS") || true -if [ -z "$line" ]; then - exit 0 -fi - -file="${entries[$line]}" -file="${file%%$'\t'*}" -path="$DOWNLOAD_DIR/$file" -filetype=$(xdg-mime query filetype "$path") -application=$(xdg-mime query default "$filetype") - -if [ -z "$application" ] ; then - die "Do not know how to open »$file« of type $filetype" -fi - -msg info "Opening »$file« (of type $filetype) with ${application%.desktop}" - -xdg-open "$path" &