vdotfiles

Cem's Dotfiles for Void Linux
git clone git://git.ckyln.com/vdotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 75a3fcad07c3114e577266d0f445f92b69c928f4
parent 927278152027a7103c967c19b8fc5d4f95d9fc55
Author: Cem Keylan <cem@ckyln.com>
Date:   Fri, 22 Nov 2019 23:37:09 +0300

switch back to surf

Diffstat:
A.local/bin/edit_screen.sh | 5+++++
A.local/bin/surf-open.sh | 32++++++++++++++++++++++++++++++++
A.local/bin/surf_linkselect.sh | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.profile | 2+-
4 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/.local/bin/edit_screen.sh b/.local/bin/edit_screen.sh @@ -0,0 +1,5 @@ +#!/bin/sh +tmpfile=$(mktemp /tmp/st-edit.XXXXXX) +trap 'rm "$tmpfile"' 0 1 15 +cat > "$tmpfile" +st -e "$EDITOR" "$tmpfile" diff --git a/.local/bin/surf-open.sh b/.local/bin/surf-open.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# +# See the LICENSE file for copyright and license details. +# + +xidfile="/tmp/$USER-tabbed-surf.xid" +uri="" + +if [ "$#" -gt 0 ]; +then + uri="$1" +fi + +runtabbed() { + tabbed -dn tabbed-surf -r 2 surf -e '' "$uri" >"$xidfile" \ + 2>/dev/null & +} + +if [ ! -r "$xidfile" ]; +then + runtabbed +else + xid=$(cat "$xidfile") + xprop -id "$xid" >/dev/null 2>&1 + if [ $? -gt 0 ]; + then + runtabbed + else + surf -e "$xid" "$uri" >/dev/null 2>&1 & + fi +fi + diff --git a/.local/bin/surf_linkselect.sh b/.local/bin/surf_linkselect.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env sh +# surf_linkselect.sh: +# Usage: curl somesite.com | surf_linkselect [SURFWINDOWID] [PROMPT] +# Deps: xmllint, dmenu +# Info: +# Designed to be used w/ surf externalpipe patch. Enables keyboard-only +# link selection via dmenu. Given HTML stdin, extracts links one per line +# Selected link is normalized based on current URI and printed to STDOUT. +# Pipe the result to a new surf or xprop _SURF_URI accordingly. +SURF_WINDOW="${1:-$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')}" +DMENU_PROMPT="${2:-Link}" + +dump_links_with_titles() { + awk '{ + input = $0; + + $0 = input; + gsub("<[^>]*>", ""); + gsub(/[ ]+/, " "); + gsub("&amp;", "\\&"); + gsub("&lt;", "<"); + gsub("&gt;", ">"); + $1 = $1; + title = ($0 == "" ? "None" : $0); + + $0 = input; + match($0, /\<[ ]*[aA][^>]* [hH][rR][eE][fF]=["]([^"]+)["]/, linkextract); + $0 = linkextract[1]; + gsub(/^[ \t]+/,""); + gsub(/[ \t]+$/,""); + gsub("[ ]", "%20"); + link = $0; + + if (link != "") { + print title ": " link; + } + }' +} + +link_normalize() { + URI=$1 + awk -v uri=$URI '{ + gsub("&amp;", "\\&"); + + if ($0 ~ /^https?:\/\// || $0 ~ /^\/\/.+$/) { + print $0; + } else if ($0 ~/^#/) { + gsub(/[#?][^#?]+/, "", uri); + print uri $0; + } else if ($0 ~/^\//) { + split(uri, uri_parts, "/"); + print uri_parts[3] $0; + } else { + gsub(/[#][^#]+/, "", uri); + uri_parts_size = split(uri, uri_parts, "/"); + delete uri_parts[uri_parts_size]; + for (v in uri_parts) { + uri_pagestripped = uri_pagestripped uri_parts[v] "/" + } + print uri_pagestripped $0; + } + }' +} + +link_select() { + tr '\n\r' ' ' | + xmllint --html --xpath "//a" - | + dump_links_with_titles | + awk '!x[$0]++' | + # sort | uniq + dmenu -p "$DMENU_PROMPT" -l 10 -i -w $SURF_WINDOW | + awk -F' ' '{print $NF}' | + link_normalize $(xprop -id $SURF_WINDOW _SURF_URI | cut -d '"' -f 2) +} + +link_select diff --git a/.profile b/.profile @@ -1,7 +1,7 @@ # Default Applications and Configuration Directory export EDITOR="/usr/bin/nvim" export TERMINAL="st" -export BROWSER="qutebrowser" +export BROWSER="surf-open.sh" export MAILER="neomutt" export SUDO_ASKPASS=$HOME/.local/bin/dpass export PAGER="vimpager"