dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 40fa0ea927600ceaafa59d0a5b3fe1be49b616b0
parent e983ed98ec895705c9cccd8ce32fc51ca5cca043
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 24 Jan 2020 10:40:02 +0100

Rename general-purpose plumb and search script, allow texting from stdin

Diffstat:
D.local/bin/linkhandler | 117-------------------------------------------------------------------------------
A.local/bin/plumb | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.local/bin/text.sh | 8++++++--
R.local/bin/ducksearch -> .local/bin/websearch | 0
4 files changed, 127 insertions(+), 119 deletions(-)

diff --git a/.local/bin/linkhandler b/.local/bin/linkhandler @@ -1,117 +0,0 @@ -#!/bin/sh -mkdir -p ~/tmp -cd ~/tmp || exit 42 - -die() { - printf '%s\n' "$1" >&2 - exit 1 -} - -handle_url() { - if [ -f "$1" ]; then - setsid "$TERMINAL" -e "$EDITOR $1" - exit 0; - fi - - url="$1" - - # strip redirects - case "$url" in - *scholar.google.*) - url="$(echo "$url" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; - esac - - - action="undefined" - case "$url" in - *.png|*.PNG|*.jpg|*.JPG|*.jpeg|*.JPEG|*.tif|*.TIF|*.bmp|*.BMP|*.pdf|*.PDF|*.mp4|*.mkv|*.webm) - notify-send "${0##*/}" "download + xdg-open" - action="xdg-open" ;; - *youtube.com*|*youtu.be*) - notify-send "${0##*/}" "youtube-dl" - action="youtube-dl" ;; - *smbc-comics.com*|*xkcd.com*|*jspowerhour.com*) - notify-send "${0##*/}" "comic" - action="comic" ;; - 10.[0-9]*\/*) - url="https://doi.org/$url" - notify-send "${0##*/}" "open as doi" - action="open" ;; - gopher://*) - nohup $TERMINAL sacc "$url" >/dev/null 2>&1 & - ;; - *) - action="$(printf "open\nopen (w3m)\nopen (tbb)\nxclip\nducksearch\nmap\nbookmark\ndownload\nhtml to pdf\nsci-hub\nscholarref\nmpv\nxdg-open\nyoutube-dl\nyoutube-dl-music\ndefine" | \ - dmenu -i -p "$(echo "$url" | sed 's/.*:\/\///' | cut -c-80)")";; - esac - - case "$action" in - "open") - nohup xdg-open "$url" >/dev/null 2>&1 & ;; - "open (w3m)") - nohup $TERMINAL w3m "$url" >/dev/null 2>&1 & ;; - "open (tbb)") - nohup tor-browser "$url" >/dev/null 2>&1 & ;; - "xclip") - printf "%s" "$url" | xclip - printf "%s" "$url" | xclip -selection clipboard ;; - "bookmark") - description="$(echo "$(date), $hostname" | \ - dmenu -p "description:")" - nohup $TERMINAL bookmark "$url" "$description" >/dev/null 2>&1 & ;; - "comic") - nohup comic "$url" >/dev/null 2>&1 & ;; - "download") - if type -v curl >/dev/null 2>&1; then - echo "curl -sLO '$url' >/dev/null" | at now - elif type -v wget >/dev/null 2>&1; then - echo "wget '$url' >/dev/null" | at now - else - die 'Error: no download program found' - fi;; - "html to pdf") - out="$HOME/tmp/html_to_pdf_$(date +'%F-%T')".pdf && \ - wkhtmltopdf "$url" "$out" && \ - notify-send "$(basename $out) complete" ;; - "ducksearch") - ducksearch "$url";; - "map") - ducksearch "!map $url";; - "sci-hub") - echo "shdl --tor-socks --notify --open --reference '$url' >/dev/null" \ - | at now;; - "scholarref") - echo "getdoi '$url' | getref --notify >> '$BIB'" | at now;; - "mpv") - nohup mpv -quiet "$url" >/dev/null 2>&1 & ;; - "xdg-open") - mkdir -p open && cd open - f="$(curl -s --write-out "%{filename_effective}\n" -OL "$url")" - nohup xdg-open "$f" >/dev/null 2>&1 & ;; - "youtube-dl") - echo "youtube-dl '$url' >/dev/null" | at now;; - "youtube-dl-music") - nohup $TERMINAL -e youtube-dl-music "$url" >/dev/null 2>&1 & ;; - "define") - define -g "$url\n";; - *) - notify-send "${0##/*}" "Error: Action not understood" - exit 1 ;; - esac -} - -if [ $# -lt 1 ]; then - handle_url "$(cat)" -else - if [ "$1" = "-c" ]; then - if [ $# -eq 2 ] && [ "$2" = "clipboard" ]; then - handle_url "$(xclip -o -selection clipboard)" - else - handle_url "$(xclip -o)" - fi - else - for url in "$@"; do - handle_url "$url" - done - fi -fi diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -0,0 +1,121 @@ +#!/bin/sh +mkdir -p ~/tmp +cd ~/tmp || exit 42 + +die() { + printf '%s\n' "$1" >&2 + exit 1 +} + +handle_uri() { + if [ -f "$1" ]; then + setsid "$TERMINAL" -e "$EDITOR $1" + exit 0; + fi + + uri="$1" + + # strip redirects + case "$uri" in + *scholar.google.*) + uri="$(echo "$uri" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; + esac + + + action="undefined" + case "$uri" in + *.png|*.PNG|*.jpg|*.JPG|*.jpeg|*.JPEG|*.tif|*.TIF|*.bmp|*.BMP|*.pdf|*.PDF|*.mp4|*.mkv|*.webm) + notify-send "${0##*/}" "download + xdg-open" + action="xdg-open" ;; + *youtube.com*|*youtu.be*) + notify-send "${0##*/}" "youtube-dl" + action="youtube-dl" ;; + *smbc-comics.com*|*xkcd.com*|*jspowerhour.com*) + notify-send "${0##*/}" "comic" + action="comic" ;; + 10.[0-9]*\/*) + uri="https://doi.org/$uri" + notify-send "${0##*/}" "open as doi" + action="open" ;; + gopher://*) + nohup $TERMINAL sacc "$uri" >/dev/null 2>&1 & + ;; + *) + action="$(printf "open\nopen (w3m)\nopen (tbb)\nxclip\nwebsearch\nmap\nwikipedia\nbookmark\ndownload\nhtml to pdf\nsci-hub\nscholarref\nmpv\nxdg-open\nyoutube-dl\nyoutube-dl-music\ndefine\nsendtext" | \ + dmenu -i -p "$(echo "$uri" | sed 's/.*:\/\///' | cut -c-80)")";; + esac + + case "$action" in + "open") + nohup xdg-open "$uri" >/dev/null 2>&1 & ;; + "open (w3m)") + nohup $TERMINAL w3m "$uri" >/dev/null 2>&1 & ;; + "open (tbb)") + nohup tor-browser "$uri" >/dev/null 2>&1 & ;; + "xclip") + printf "%s" "$uri" | xclip + printf "%s" "$uri" | xclip -selection clipboard ;; + "bookmark") + description="$(echo "$(date), $hostname" | \ + dmenu -p "description:")" + nohup $TERMINAL bookmark "$uri" "$description" >/dev/null 2>&1 & ;; + "comic") + nohup comic "$uri" >/dev/null 2>&1 & ;; + "download") + if type -v curl >/dev/null 2>&1; then + echo "curl -sLO '$uri' >/dev/null" | at now + elif type -v wget >/dev/null 2>&1; then + echo "wget '$uri' >/dev/null" | at now + else + die 'Error: no download program found' + fi;; + "html to pdf") + out="$HOME/tmp/html_to_pdf_$(date +'%F-%T')".pdf && \ + wkhtmltopdf "$uri" "$out" && \ + notify-send "$(basename $out) complete" ;; + "websearch") + websearch "$uri";; + "map") + websearch "!map $uri";; + "wikipedia") + websearch "!wiki $uri";; + "sci-hub") + echo "shdl --tor-socks --notify --open --reference '$uri' >/dev/null" \ + | at now;; + "scholarref") + echo "getdoi '$uri' | getref --notify >> '$BIB'" | at now;; + "mpv") + nohup mpv -quiet "$uri" >/dev/null 2>&1 & ;; + "xdg-open") + mkdir -p open && cd open + f="$(curl -s --write-out "%{filename_effective}\n" -OL "$uri")" + nohup xdg-open "$f" >/dev/null 2>&1 & ;; + "youtube-dl") + echo "youtube-dl '$uri' >/dev/null" | at now;; + "youtube-dl-music") + nohup $TERMINAL -e youtube-dl-music "$uri" >/dev/null 2>&1 & ;; + "define") + define -g "$uri\n";; + "sendtext") + printf "%s\n" "$uri" | text.sh;; + *) + notify-send "${0##/*}" "Error: Action not understood" + exit 1 ;; + esac +} + +if [ $# -lt 1 ]; then + handle_uri "$(cat)" +else + if [ "$1" = "-c" ]; then + if [ $# -eq 2 ] && [ "$2" = "clipboard" ]; then + handle_uri "$(xclip -o -selection clipboard)" + else + handle_uri "$(xclip -o)" + fi + else + for uri in "$@"; do + handle_uri "$uri" + done + fi +fi diff --git a/.local/bin/text.sh b/.local/bin/text.sh @@ -3,5 +3,9 @@ set -e to="$(find "$HOME/.password-store/Telephone" -type f | \ sed 's/.*\///;s/\.gpg$//' | \ dmenu -i -p "to:")" -msg="$(echo | dmenu -p "message:")" -echo "$msg" | sendtext "$to" +if [ $# -eq 0 ]; then + msg="$(cat)" +else + msg="$(echo | dmenu -p "message:")" +fi +printf '%s\n' "$msg" | sendtext "$to" diff --git a/.local/bin/ducksearch b/.local/bin/websearch