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 19b536f0f425fccf1fef5301c87017a35e80eb85
parent 19480bcf06bef3ba81cba5d9f5e3862b261deb73
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 25 Jul 2019 19:34:24 +0200

Improve scripts and remove unused

Diffstat:
M.local/bin/define | 84++++++++++++++++++++++++++++++++++++++++----------------------------------------
M.local/bin/displayselect | 86++++++++++++++++++++++++++++++++++++++++----------------------------------------
M.local/bin/docker-delete-all | 6+++---
M.local/bin/docker-shell | 52++++++++++++++++++++++++----------------------------
M.local/bin/ducksearch | 35+++++++++++++++++------------------
M.local/bin/dwmstatus | 4++--
M.local/bin/ejectall | 16++++++++--------
M.local/bin/ffmpeg-to-mp4.sh | 20++++++++------------
M.local/bin/forecast | 56++++++++++++++++++++++++++------------------------------
M.local/bin/forecast-sky | 10+++++-----
D.local/bin/fsize.sh | 6------
M.local/bin/fuzzylaunch | 20++++++++++----------
M.local/bin/getdoi | 200++++++++++++++++++++++++++++++++++++++++----------------------------------------
M.local/bin/getref | 252++++++++++++++++++++++++++++++++++++++++----------------------------------------
M.local/bin/gitlab-ci | 34+++++++++++++++-------------------
M.local/bin/gitlab-project | 124+++++++++++++++++++++++++++++++++++++++----------------------------------------
D.local/bin/i3resize | 27---------------------------
D.local/bin/i3status-mpc.sh | 27---------------------------
M.local/bin/passmenu | 18+++++++++---------
19 files changed, 499 insertions(+), 578 deletions(-)

diff --git a/.local/bin/define b/.local/bin/define @@ -2,71 +2,71 @@ set -e show_help() { - echo "usage: ${0##*/} [OPTIONS] TERM[S]" - echo "shows definitions for each TERM from dict.org" - echo - echo "Options:" - echo " -g, --gui use dmenu for input and notify-send for output" - echo " -np, --no-pager do not use a pager for long output" - echo " -h, --help show this message" + echo "usage: ${0##*/} [OPTIONS] TERM[S]" + echo "shows definitions for each TERM from dict.org" + echo + echo "Options:" + echo " -g, --gui use dmenu for input and notify-send for output" + echo " -np, --no-pager do not use a pager for long output" + echo " -h, --help show this message" } define() { - curl --silent dict://dict.org/d:"$1" + curl --silent dict://dict.org/d:"$1" } remove_comm_msgs() { - grep -vE '[0-9][0-9] ' | \ - sed 's/^\.//' + grep -vE '[0-9][0-9] ' | \ + sed 's/^\.//' } die() { - printf '%s\n' "$1" >&2 - exit 1 + printf '%s\n' "$1" >&2 + exit 1 } gui=0 pager=1 while :; do - case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - -g|--gui) - gui=1 - ;; - -np|--no-pager) - pager=0 - ;; - --) # end all options - shift - break - ;; - -?*) - die 'ERROR: Unknown option specified' - ;; - *) # no more options - break - esac - shift + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -g|--gui) + gui=1 + ;; + -np|--no-pager) + pager=0 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'ERROR: Unknown option specified' + ;; + *) # no more options + break + esac + shift done if [ "$gui" = 1 ]; then - word=$(xclip -o | dmenu_themed -i -p "Dictionary lookup:") || exit 1 - notify-send "define: $word" "$(define "$word" | remove_comm_msgs)" - exit 0 + word=$(xclip -o | dmenu_themed -i -p "Dictionary lookup:") || exit 1 + notify-send "define: $word" "$(define "$word" | remove_comm_msgs)" + exit 0 else - [ $# -lt 1 ] && (show_help && exit 1) + [ $# -lt 1 ] && (show_help && exit 1) fi definition="" for word in "$@"; do - definition="${definition}\n$(define "$word" | remove_comm_msgs)" + definition="${definition}\n$(define "$word" | remove_comm_msgs)" done if [ "$(printf "%s" "$definition" | wc -l)" -gt "$(tput lines)" ] && \ - [ "$pager" = 1 ]; then - printf "%s" "$definition" | tail -n +2 | less + [ "$pager" = 1 ]; then + printf "%s" "$definition" | tail -n +2 | less else - printf "%s" "$definition" | tail -n +2 + printf "%s" "$definition" | tail -n +2 fi diff --git a/.local/bin/displayselect b/.local/bin/displayselect @@ -7,59 +7,59 @@ twoscreen() { # If multi-monitor is selected and there are two screens. - mirror=$(printf "no\\nyes" | dmenu_themed -i -p "Mirror displays?") - # Mirror displays using native resolution of external display and a scaled - # version for the internal display - if [ "$mirror" = "yes" ]; then - external=$(echo "$screens" | dmenu_themed -i -p "Optimize resolution for:") - internal=$(echo "$screens" | grep -v "$external") + mirror=$(printf "no\\nyes" | dmenu_themed -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | dmenu_themed -i -p "Optimize resolution for:") + internal=$(echo "$screens" | grep -v "$external") - res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ - tail -n 1 | awk '{print $1}') - res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ - tail -n 1 | awk '{print $1}') + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ + tail -n 1 | awk '{print $1}') - res_ext_x=$(echo "$res_external" | sed 's/x.*//') - res_ext_y=$(echo "$res_external" | sed 's/.*x//') - res_int_x=$(echo "$res_internal" | sed 's/x.*//') - res_int_y=$(echo "$res_internal" | sed 's/.*x//') + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') - scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) - scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) - xrandr --output "$external" --auto --scale 1.0x1.0 \ - --output "$internal" --auto --same-as "$external" \ - --scale "$scale_x"x"$scale_y" + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" else - primary=$(echo "$screens" | dmenu_themed -i -p "Select primary display:") - secondary=$(echo "$screens" | grep -v "$primary") - direction=$(printf "left\\nright" | \ - dmenu_themed -i -p "What side of $primary should $secondary be on?") - xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" \ - --"$direction"-of "$primary" --auto --scale 1.0x1.0 + primary=$(echo "$screens" | dmenu_themed -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | \ + dmenu_themed -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" \ + --"$direction"-of "$primary" --auto --scale 1.0x1.0 fi } morescreen() { # If multi-monitor is selected and there are more than two screens. primary=$(echo "$screens" | dmenu_themed -i -p "Select primary display:") secondary=$(echo "$screens" | grep -v "$primary" | \ - dmenu_themed -i -p "Select secondary display:") + dmenu_themed -i -p "Select secondary display:") direction=$(printf "left\\nright" | \ - dmenu_themed -i -p "What side of $primary should $secondary be on?") + dmenu_themed -i -p "What side of $primary should $secondary be on?") tertiary=$(echo "$screens" | grep -v "$primary" | \ - grep -v "$secondary" | dmenu_themed -i -p "Select third display:") + grep -v "$secondary" | dmenu_themed -i -p "Select third display:") xrandr --output "$primary" --auto \ - --output "$secondary" --"$direction"-of "$primary" --auto \ - --output "$tertiary" \ - --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" \ - --auto + --output "$secondary" --"$direction"-of "$primary" --auto \ + --output "$tertiary" \ + --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" \ + --auto } multimon() { # Multi-monitor handler case "$(echo "$screens" | wc -l)" in 1) xrandr "$(echo "$allposs" | awk '{print "--output", $1, "--off"}' \ - | tr '\n' ' ')" ;; + | tr '\n' ' ')" ;; 2) twoscreen ;; *) morescreen ;; esac ; @@ -73,17 +73,17 @@ screens=$(echo "$allposs" | grep " connected" | awk '{print $1}') # Get user choice including multi-monitor and manual selection: if [ "$(echo "$screens" | wc -l)" -gt 1 ]; then - chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" \ - | dmenu_themed -i -p "Select display arangement:") && - case "$chosen" in - "manual selection") arandr ; exit ;; - "multi-monitor") multimon ;; - *) xrandr --output "$chosen" --auto --scale 1.0x1.0 \ - $(echo "$screens" | grep -v "$chosen" | \ - awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; - esac + chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" \ + | dmenu_themed -i -p "Select display arangement:") && + case "$chosen" in + "manual selection") arandr ; exit ;; + "multi-monitor") multimon ;; + *) xrandr --output "$chosen" --auto --scale 1.0x1.0 \ + $(echo "$screens" | grep -v "$chosen" | \ + awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;; + esac else - xrandr --auto --scale 1.0x1.0 + xrandr --auto --scale 1.0x1.0 fi # Fix feh background if screen size/arangement has changed. diff --git a/.local/bin/docker-delete-all b/.local/bin/docker-delete-all @@ -1,9 +1,9 @@ -#!/bin/bash +#!/bin/sh [ "$(uname)" = "Linux" ] && dockercmd="sudo docker" || dockercmd=docker # Delete all containers -$dockercmd rm $($dockercmd ps -a -q) +$dockercmd rm "$($dockercmd ps -a -q)" # Delete all images -$dockercmd rmi $($dockercmd images -q) +$dockercmd rmi "$($dockercmd images -q)" diff --git a/.local/bin/docker-shell b/.local/bin/docker-shell @@ -1,42 +1,38 @@ -#!/usr/bin/env bash +#!/bin/sh set -e -function help { - echo "Usage: ${0##*/} IMAGE [SHELL]" - echo "where IMAGE is a valid Docker image, or one of the predefined" - echo "shortcuts (e.g., alpine, ubuntu, ubuntu-lts), and the optional" - echo "argument SHELL sets the shell to run in the image." +help() { + echo "Usage: ${0##*/} IMAGE [SHELL]" + echo "where IMAGE is a valid Docker image, or one of the predefined" + echo "shortcuts (e.g., alpine, ubuntu, ubuntu-lts), and the optional" + echo "argument SHELL sets the shell to run in the image." } [ $# -lt 1 ] && (help && exit 1) case "$1" in - ubuntu-lts) - img="ubuntu:16.04" - [ ! -z "$2" ] && shell="$2" || shell="bash" - ;; - alpine) - img="alpine" - [ ! -z "$2" ] && shell="$2" || shell="sh" - ;; - -h) - help - exit 0 - ;; - --help) - help - exit 0 - ;; - *) - img="$1" - [ -z "$2" ] && shell="$2" || shell="bash" - ;; + ubuntu-lts) + img="ubuntu:18.04" + [ -n "$2" ] && shell="$2" || shell="bash" + ;; + alpine) + img="alpine" + [ -n "$2" ] && shell="$2" || shell="sh" + ;; + -h|--help) + help + exit 0 + ;; + *) + img="$1" + [ -z "$2" ] && shell="$2" || shell="bash" + ;; esac if [ "$(uname)" = "Linux" ]; then - dockercmd="sudo docker" + dockercmd="sudo docker" else - dockercmd="docker" + dockercmd="docker" fi eval "$dockercmd" run -i -t "$img" "$shell" diff --git a/.local/bin/ducksearch b/.local/bin/ducksearch @@ -7,28 +7,27 @@ browser=${BROWSER:-firefox} url="$(grep 'href="htt' "$HOME"/.w3m/bookmark.html | \ - sed 's/<\/.*>//g' | \ - sed 's/.*<a href="//;s/">/ /;s/<\/a>//' ; - cat ~/doc/bookmark.txt)" + sed 's/<\/.*>//g' | \ + sed 's/.*<a href="//;s/">/ /;s/<\/a>//' ; + cat ~/doc/bookmark.txt)" choice=$(echo "$url" | dmenu_themed -i -p "Search DuckDuckGo:") || exit 1 echo "$choice" if [ "$choice" = "🦆" ]; then - $browser "https://duckduckgo.com" + $browser "https://duckduckgo.com" else - # Detect if url - if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9\-]+\.[a-zA-Z]+(/)?.*$ ]]; then - $browser "$(echo "$choice" | awk '{print $1}')" - else - case "$choice" in - scholar*) - $browser "https://scholar.google.com/scholar?q=${choice/scholar /}" - ;; - *) - $browser "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1" - ;; - esac - - fi + # Detect if url + if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9\-]+\.[a-zA-Z]+(/)?.*$ ]]; then + $browser "$(echo "$choice" | awk '{print $1}')" + else + case "$choice" in + scholar*) + $browser "https://scholar.google.com/scholar?q=${choice/scholar /}" + ;; + *) + $browser "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1" + ;; + esac + fi fi diff --git a/.local/bin/dwmstatus b/.local/bin/dwmstatus @@ -1,5 +1,5 @@ #!/bin/sh while true; do - xsetroot -name "$(sysstatus)" - sleep 30 + xsetroot -name "$(sysstatus)" + sleep 30 done diff --git a/.local/bin/ejectall b/.local/bin/ejectall @@ -1,10 +1,10 @@ -#!/bin/bash +#!/bin/sh for f in "/Volumes/"*; do - if [ "$f" != "/Volumes/Macintosh HD" ]; then - if [ "$f" != "/Volumes/MobileBackups" ]; then - diskutil eject "$f" 2>&1 | \ - sed "s/Volume failed to eject/$(tput setaf 1)Volume failed to eject$(tput sgr0)/" | - sed "s/Unable to find disk for .*com\.apple\.TimeMachine.*//" - fi - fi + if [ "$f" != "/Volumes/Macintosh HD" ]; then + if [ "$f" != "/Volumes/MobileBackups" ]; then + diskutil eject "$f" 2>&1 | \ + sed "s/Volume failed to eject/$(tput setaf 1)Volume failed to eject$(tput sgr0)/" | + sed "s/Unable to find disk for .*com\.apple\.TimeMachine.*//" + fi + fi done diff --git a/.local/bin/ffmpeg-to-mp4.sh b/.local/bin/ffmpeg-to-mp4.sh @@ -1,19 +1,15 @@ -#!/bin/bash +#!/bin/sh output="${1%.*}.mp4" -#ffmpeg -i $1 \ - #-crf 20 -vcodec libx264 -x264opts keyint=25 \ - #$output - # From media9 LaTeX package documentation. # Generates sufficient keyframes to allow for precise seeking within video. # The scale argument ensures that dimensions are divisible by 2, a requirement # for MP4 videos using H.264. ffmpeg -i "$1" \ - -vf scale="trunc(iw/2)*2:trunc(ih/2)*2" \ - -c:v libx264 -profile:v high -pix_fmt yuv420p \ - -g 30 -r 30 -y \ - "$output" + -vf scale="trunc(iw/2)*2:trunc(ih/2)*2" \ + -c:v libx264 -profile:v high -pix_fmt yuv420p \ + -g 30 -r 30 -y \ + "$output" #ffmpeg -i movie.avi -sameq -vcodec libx264 -x264opts keyint=25 \ #-acodec libfaac -b:a 128k -vcodec mpeg4 -b:v 1200k -flags +aic+mv4 \ @@ -32,7 +28,7 @@ ffmpeg -i "$1" -y -vframes 1 -f image2 "${output%.*}.png" echo "$output" -if [ "$2" == "cleanup" ]; then - rm "${1%.*}.png" - rm "${1}" +if [ "$2" = "cleanup" ]; then + rm "${1%.*}.png" + rm "${1}" fi diff --git a/.local/bin/forecast b/.local/bin/forecast @@ -1,52 +1,48 @@ #!/bin/sh -# vim: ft=sh: set -e -# DMI -#zipcode=7700 # Thisted default_zipcode=9520 # Skoerping show_help() { - echo "usage: ${0##*/} [radar | 3-9 | wind] [ZIPCODE]" - echo "gets DMI forecast, with ZIPCODE=$default_zipcode by default" + echo "usage: ${0##*/} [radar | 3-9 | wind] [ZIPCODE]" + echo "gets DMI forecast, with ZIPCODE=$default_zipcode by default" } if command -v open >/dev/null 2>&1; then - open=open + open=open elif command -v xdg-open >/dev/null 2>&1; then - open=xdg-open + open=xdg-open else - open="echo" + open="echo" fi get_url() { - echo "http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=${1}&mode=long&eps=true" + echo "http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=${1}&mode=long&eps=true" } if [ $# -gt 0 ]; then - if [ "$1" = "radar" ]; then - $open "http://www.dmi.dk/vejr/maalinger/radar-nedboer/" - exit 0 - elif [ "$1" = "3-9" ]; then - if [ $# -gt 1 ]; then - zip="$2" - else - zip="$default_zipcode" - fi - url="http://servlet.dmi.dk/byvejr/servlet/byvejr?by=${zip}&tabel=dag3_9&eps=true" - elif [ "$1" = "wind" ]; then - url="http://servlet.dmi.dk/bv/servlet/bvImage?stat=6065&param=wind" - elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then - show_help - exit 0 - else - url=$(get_url "$1") - fi + if [ "$1" = "radar" ]; then + $open "http://www.dmi.dk/vejr/maalinger/radar-nedboer/" + exit 0 + elif [ "$1" = "3-9" ]; then + if [ $# -gt 1 ]; then + zip="$2" + else + zip="$default_zipcode" + fi + url="http://servlet.dmi.dk/byvejr/servlet/byvejr?by=${zip}&tabel=dag3_9&eps=true" + elif [ "$1" = "wind" ]; then + url="http://servlet.dmi.dk/bv/servlet/bvImage?stat=6065&param=wind" + elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + show_help + exit 0 + else + url=$(get_url "$1") + fi else - url=$(get_url $default_zipcode) + url=$(get_url $default_zipcode) fi tmpfile=$(mktemp).png -curl --silent --location "$url" \ - --output "$tmpfile" +curl --silent --location "$url" --output "$tmpfile" $open "$tmpfile" diff --git a/.local/bin/forecast-sky b/.local/bin/forecast-sky @@ -2,13 +2,13 @@ tmpfile=$(mktemp).png curl --location \ - 'http://www.cleardarksky.com/c/AAAP1_NJcsk.gif?c=468010'\ - --output "$tmpfile" + 'http://www.cleardarksky.com/c/AAAP1_NJcsk.gif?c=468010'\ + --output "$tmpfile" if command -v open >/dev/null 2>&1; then - open "$tmpfile" + open "$tmpfile" elif command -v xdg-open >/dev/null 2>&1; then - xdg-open "$tmpfile" + xdg-open "$tmpfile" else - echo "$tmpfile" + echo "$tmpfile" fi diff --git a/.local/bin/fsize.sh b/.local/bin/fsize.sh @@ -1,6 +0,0 @@ -#!/bin/bash -#FONT=uushi -#FONT=Terminus -#FONT=lemon -FONT="Monaco for Powerline" -printf '\33]50;%s%d\007' "xft:$FONT:pixelsize=" $1 diff --git a/.local/bin/fuzzylaunch b/.local/bin/fuzzylaunch @@ -3,18 +3,18 @@ open="xdg-open" [ "$(uname)" = "Darwin" ] && open="open" IFS= out=$(fzf --query="$1" --exit-0 \ - --expect=ctrl-o,ctrl-e,ctrl-y \ - --preview-window=hidden) + --expect=ctrl-o,ctrl-e,ctrl-y \ + --preview-window=hidden) key=$(echo "$out" | sed 1q) file=$(echo "$out" | sed 2q | tail -1) if [ -n "$file" ]; then - if [ "$key" = ctrl-e ]; then - nohup "$TERMINAL" -e "$EDITOR" "$file" >/dev/null 2>&1 & - elif [ "$key" = ctrl-o ]; then - cd "$(dirname "$file")" && nohup "$TERMINAL" >/dev/null 2>&1 & - else - nohup "$open" "$file" >/dev/null 2>&1 & - fi - sleep 0.25 + if [ "$key" = ctrl-e ]; then + setsid "$TERMINAL" -e "$EDITOR" "$file" >/dev/null 2>&1 + elif [ "$key" = ctrl-o ]; then + cd "$(dirname "$file")" && setsid "$TERMINAL" >/dev/null 2>&1 + else + setsid "$open" "$file" >/dev/null 2>&1 + fi + sleep 0.25 fi diff --git a/.local/bin/getdoi b/.local/bin/getdoi @@ -4,85 +4,85 @@ version=1.0 host="http://api.crossref.org/works" show_help() { - echo "usage: ${0##*/} [OPTIONS] QUERY" - echo "will attempt to get the DOI from $host" - echo "where QUERY can consist of publication title, author, DOI, ORCID id," - echo "or a PDF file. In case a file is specified, ${0##*/} will attempt to" - echo "extract the DOI from it." - echo "If no QUERY is specified, this program will expect a QUERY as stdin." - echo - echo "OPTIONS are one or more of the following:" - echo " -h, --help show this message" - echo " -v, --version show version and license information" - echo " -V, --verbose show verbose information" - echo " -t, --tor-socks use torsocks for HTTP requests" - echo " -n, --notify send result as desktop notification" - echo " -N, --number NUM return NUM results (default 1)" - echo " -c, --clip paste DOI to clipboard (requires xclip)" - echo " -o, --open open DOI as url in browser" - echo " -- do not consider any following args as options" + echo "usage: ${0##*/} [OPTIONS] QUERY" + echo "will attempt to get the DOI from $host" + echo "where QUERY can consist of publication title, author, DOI, ORCID id," + echo "or a PDF file. In case a file is specified, ${0##*/} will attempt to" + echo "extract the DOI from it." + echo "If no QUERY is specified, this program will expect a QUERY as stdin." + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -V, --verbose show verbose information" + echo " -t, --tor-socks use torsocks for HTTP requests" + echo " -n, --notify send result as desktop notification" + echo " -N, --number NUM return NUM results (default 1)" + echo " -c, --clip paste DOI to clipboard (requires xclip)" + echo " -o, --open open DOI as url in browser" + echo " -- do not consider any following args as options" } show_version() { - echo "${0##*/} version $version" - echo "Licensed under the GNU Public License, v3+" - echo "written by Anders Damsgaard, anders@adamsgaard.dk" - echo "https://gitlab.com/admesg/dotfiles" + echo "${0##*/} version $version" + echo "Licensed under the GNU Public License, v3+" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://gitlab.com/admesg/dotfiles" } die() { - printf '%s\n' "$1" >&2 - exit 1 + printf '%s\n' "$1" >&2 + exit 1 } extract_dois() { - tr ',' '\n' | grep DOI | \ - sed 's/.*DOI":"//' | sed 's/"}.*//' | sed 's|\\\/|/|g' + tr ',' '\n' | grep DOI | \ + sed 's/.*DOI":"//' | sed 's/"}.*//' | sed 's|\\\/|/|g' } browser_open() { - if command -v xdg-open >/dev/null 2>&1; then - [ "$verbose" = 1 ] && echo "launching default browser" - xdg-open "$1" - elif command -v open >/dev/null 2>&1; then - [ "$verbose" = 1 ] && echo "launching default browser" - open "$1" - else - die 'Error: could not open a browser' - fi + if command -v xdg-open >/dev/null 2>&1; then + [ "$verbose" = 1 ] && echo "launching default browser" + xdg-open "$1" + elif command -v open >/dev/null 2>&1; then + [ "$verbose" = 1 ] && echo "launching default browser" + open "$1" + else + die 'Error: could not open a browser' + fi } get_doi_from_crossref() { - query="$(echo "$@" | sed 's/ /+/g')" - url="$host?rows=$number&select=DOI&query=$query" - [ "$verbose" = 1 ] && echo "connecting to $url" - result=$($prefix curl --header "Accept: application/json" \ - --header "Content-Type: application/json" \ - --silent --show-error \ - --request GET "$url") - echo "$result" | extract_dois + query="$(echo "$@" | sed 's/ /+/g')" + url="$host?rows=$number&select=DOI&query=$query" + [ "$verbose" = 1 ] && echo "connecting to $url" + result=$($prefix curl --header "Accept: application/json" \ + --header "Content-Type: application/json" \ + --silent --show-error \ + --request GET "$url") + echo "$result" | extract_dois } get_doi_from_file() { - doi=$(pdfinfo "$1" | grep -io "doi.*") || - doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi.*" -m 1 ) || - die "Error: Could not extract DOI from file $doi" - doi=$(echo "$doi" | sed 's/[A-Za-z\.\/:]*//;s/[\.,]$//' |\ - sed 's/.*\(10\.\)/\1/' | cut -d' ' -f1 | sed 's/,//g') - echo "$doi" + doi=$(pdfinfo "$1" | grep -io "doi.*") || + doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi.*" -m 1 ) || + die "Error: Could not extract DOI from file $doi" + doi=$(echo "$doi" | sed 's/[A-Za-z\.\/:]*//;s/[\.,]$//' |\ + sed 's/.*\(10\.\)/\1/' | cut -d' ' -f1 | sed 's/,//g') + echo "$doi" } get_doi() { - if [ -e "$1" ]; then - doi=$(get_doi_from_file "$1") - else - doi=$(get_doi_from_crossref "$@") - fi - echo "$doi" - [ "$clip" = 1 ] && echo "https://doi.org/${doi}" | \ - xclip -selection clipboard - [ "$notify" = 1 ] && notify-send "$doi" - [ "$open" = 1 ] && browser_open "https://doi.org/${doi}" + if [ -e "$1" ]; then + doi=$(get_doi_from_file "$1") + else + doi=$(get_doi_from_crossref "$@") + fi + echo "$doi" + [ "$clip" = 1 ] && echo "https://doi.org/${doi}" | \ + xclip -selection clipboard + [ "$notify" = 1 ] && notify-send "$doi" + [ "$open" = 1 ] && browser_open "https://doi.org/${doi}" } verbose=0 @@ -92,50 +92,50 @@ open=0 notify=0 prefix="" while :; do - case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - -v|--version) - show_version - exit 0 - ;; - -V|--verbose) - verbose=1 - ;; - -t|--tor-socks) - prefix="torsocks" - ;; - -N|--number) - number="$2" - shift - ;; - -n|--notify) - notify=1 - ;; - -c|--clip) - clip=1 - ;; - -o|--open) - open=1 - ;; - --) # end all options - shift - break - ;; - -?*) - die 'Error: Unknown option specified' - ;; - *) # No more options - break - esac - shift + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -V|--verbose) + verbose=1 + ;; + -t|--tor-socks) + prefix="torsocks" + ;; + -N|--number) + number="$2" + shift + ;; + -n|--notify) + notify=1 + ;; + -c|--clip) + clip=1 + ;; + -o|--open) + open=1 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift done if [ $# -lt 1 ]; then - query="$(cat)" - get_doi "$query" + query="$(cat)" + get_doi "$query" else - get_doi "$@" + get_doi "$@" fi diff --git a/.local/bin/getref b/.local/bin/getref @@ -4,112 +4,112 @@ version=1.0 host="https://doi.org" show_help() { - echo "usage: ${0##*/} [OPTIONS] DOI1 [DOI2 ...]" - echo "will attempt to get a BibTeX citation from $host" - echo "If no DOIs are specified, this program will expect DOIs as stdin." - echo - echo "OPTIONS are one or more of the following:" - echo " -h, --help show this message" - echo " -v, --version show version and license information" - echo " -V, --verbose show verbose information" - echo " -t, --tor-socks use torsocks for HTTP requests" - echo " -j, --full-journal return full journal name in citation" - echo " -a, --full-author do not shorten author names" - echo " -n, --no-newline suppress trailing newline but prepend with newline" - echo " -N, --notify send desktop notification when complete" - echo " -- do not consider any following args as options" + echo "usage: ${0##*/} [OPTIONS] DOI1 [DOI2 ...]" + echo "will attempt to get a BibTeX citation from $host" + echo "If no DOIs are specified, this program will expect DOIs as stdin." + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -V, --verbose show verbose information" + echo " -t, --tor-socks use torsocks for HTTP requests" + echo " -j, --full-journal return full journal name in citation" + echo " -a, --full-author do not shorten author names" + echo " -n, --no-newline suppress trailing newline but prepend with newline" + echo " -N, --notify send desktop notification when complete" + echo " -- do not consider any following args as options" } show_version() { - echo "${0##*/} version $version" - echo "Licensed under the GNU Public License, v3+" - echo "written by Anders Damsgaard, anders@adamsgaard.dk" - echo "https://gitlab.com/admesg/dotfiles" + echo "${0##*/} version $version" + echo "Licensed under the GNU Public License, v3+" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://gitlab.com/admesg/dotfiles" } die() { - printf '%s\n' "$1" >&2 - exit 1 + printf '%s\n' "$1" >&2 + exit 1 } format_bibtex_key() { - sed '/@/ s/_\([0-9]\)/\1/' + sed '/@/ s/_\([0-9]\)/\1/' } abbreviate_journal_name() { - sed '/journal = / { - s/Journal/J./ - s/Geophysical/Geophys./ - s/Research/Res./ - s/Geophysical/Geophys./ - s/Geophysics/Geophys./ - s/Research/Res./ - s/Letters/Lett./ - s/Mechanics/Mech./ - s/Glaciology/Glaciol./ - s/Proceedings/Proc./ - s/Royal/R./ - s/Society/Soc./ - s/Annals/Ann./ - s/Resources/Resour./ - s/Surface/Surf./ - s/Processes/Proc./ - s/National/Nat./ - s/Computers/Comput./ - s/Geotechnics/Geotech./ - s/Academy/Acad./ - s/Sciences/Sci./ - s/Review/Rev./ - s/Quaternary/Quat./ - s/Physical/Phys./ - s/Planetary/Planet./ - s/Quarterly/Q./ - s/Geological/Geol./ - s/Statistical/Stat./ - s/Applied/Appl./ - s/Physics/Phys./ - s/Communications/Commun./ - s/Geoscience/Geosci./ - s/Landforms/Land./ - s/Science/Sci./ - s/Annual/Ann./ - s/International/Int./ - s/Numerical/Numer./ - s/Methods/Meth./ - s/Geomechanics/Geomech./ - s/Analytical/Anal./ - s/ for / / - s/ of / / - s/ and / / - s/ in / / - }' + sed '/journal = / { + s/Journal/J./ + s/Geophysical/Geophys./ + s/Research/Res./ + s/Geophysical/Geophys./ + s/Geophysics/Geophys./ + s/Research/Res./ + s/Letters/Lett./ + s/Mechanics/Mech./ + s/Glaciology/Glaciol./ + s/Proceedings/Proc./ + s/Royal/R./ + s/Society/Soc./ + s/Annals/Ann./ + s/Resources/Resour./ + s/Surface/Surf./ + s/Processes/Proc./ + s/National/Nat./ + s/Computers/Comput./ + s/Geotechnics/Geotech./ + s/Academy/Acad./ + s/Sciences/Sci./ + s/Review/Rev./ + s/Quaternary/Quat./ + s/Physical/Phys./ + s/Planetary/Planet./ + s/Quarterly/Q./ + s/Geological/Geol./ + s/Statistical/Stat./ + s/Applied/Appl./ + s/Physics/Phys./ + s/Communications/Commun./ + s/Geoscience/Geosci./ + s/Landforms/Land./ + s/Science/Sci./ + s/Annual/Ann./ + s/International/Int./ + s/Numerical/Numer./ + s/Methods/Meth./ + s/Geomechanics/Geomech./ + s/Analytical/Anal./ + s/ for / / + s/ of / / + s/ and / / + s/ in / / + }' } abbreviate_author_name() { - sed '/author = / { s/\([A-Z]\)[A-Za-z]* \([A-Z]\)/\1. \2/g }' + sed '/author = / { s/\([A-Z]\)[A-Za-z]* \([A-Z]\)/\1. \2/g }' } strip_doi() { - sed 's/^(http:\/\/|https:\/\/)?(dx\.)?(doi\.org\/)//' + sed 's/^(http:\/\/|https:\/\/)?(dx\.)?(doi\.org\/)//' } get_citation() { - doi=$(echo "$1" | strip_doi) - url="$host/$1" - [ "$verbose" = 1 ] && echo "connecting to $url" - result=$($prefix curl --location \ - --header "Accept: application/x-bibtex" \ - --silent --show-error "$url") - result="$(echo "$result" | format_bibtex_key)" - [ "$fulljournal" = 0 ] && result="$(echo "$result" | abbreviate_journal_name)" - [ "$fullauthor" = 0 ] && result="$(echo "$result" | abbreviate_author_name)" - result="$(echo "$result" | sed 's/\t/ /g')" - if [ "$nonewline" = 1 ]; then - printf "\n%s" "$result" - else - echo "$result" - fi - [ "$notify" = 1 ] && notify-send "${0##*/}" "added: $(echo "$result" | cut -c-80)" + doi=$(echo "$1" | strip_doi) + url="$host/$1" + [ "$verbose" = 1 ] && echo "connecting to $url" + result=$($prefix curl --location \ + --header "Accept: application/x-bibtex" \ + --silent --show-error "$url") + result="$(echo "$result" | format_bibtex_key)" + [ "$fulljournal" = 0 ] && result="$(echo "$result" | abbreviate_journal_name)" + [ "$fullauthor" = 0 ] && result="$(echo "$result" | abbreviate_author_name)" + result="$(echo "$result" | sed 's/\t/ /g')" + if [ "$nonewline" = 1 ]; then + printf "\n%s" "$result" + else + echo "$result" + fi + [ "$notify" = 1 ] && notify-send "${0##*/}" "added: $(echo "$result" | cut -c-80)" } verbose=0 @@ -119,49 +119,49 @@ nonewline=0 notify=0 prefix="" while :; do - case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - -v|--version) - show_version - exit 0 - ;; - -j|--full-journal) - fulljournal=1 - ;; - -a|--full-author) - fullauthor=1 - ;; - -n|--no-newline) - nonewline=1 - ;; - -N|--notify) - notify=1 - ;; - -V|--verbose) - verbose=1 - ;; - -t|--tor-socks) - prefix="torsocks" - ;; - --) # end all options - shift - break - ;; - -?*) - die 'Error: Unknown option specified' - ;; - *) # No more options - break - esac - shift + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -j|--full-journal) + fulljournal=1 + ;; + -a|--full-author) + fullauthor=1 + ;; + -n|--no-newline) + nonewline=1 + ;; + -N|--notify) + notify=1 + ;; + -V|--verbose) + verbose=1 + ;; + -t|--tor-socks) + prefix="torsocks" + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift done if [ $# -lt 1 ]; then - doi="$(cat)" - get_citation "$doi" + doi="$(cat)" + get_citation "$doi" else - get_citation "$@" + get_citation "$@" fi diff --git a/.local/bin/gitlab-ci b/.local/bin/gitlab-ci @@ -1,30 +1,26 @@ #!/bin/sh help() { - echo "Usage: ${0##*/} JOBNAME1 [JOBNAME2,...,[JOBNAME N]]" + echo "Usage: ${0##*/} JOBNAME1 [JOBNAME2,...,[JOBNAME N]]" } [ $# -lt 1 ] && (help && exit 1) case "$1" in - -h) - help - exit 0 - ;; - --help) - help - exit 0 - ;; - *) - if [ "$(uname)" = "Linux" ]; then - # Run as sudo if not SU already - if ! [ "$(id -u)" = 0 ]; then - sudo "$0" "$@" - exit $? - fi - fi - ;; + -h|--help) + help + exit 0 + ;; + *) + if [ "$(uname)" = "Linux" ]; then + # Run as sudo if not SU already + if ! [ "$(id -u)" = 0 ]; then + sudo "$0" "$@" + exit $? + fi + fi + ;; esac for jobname in "$@"; do - gitlab-runner exec docker "$jobname" + gitlab-runner exec docker "$jobname" done diff --git a/.local/bin/gitlab-project b/.local/bin/gitlab-project @@ -1,87 +1,85 @@ -#!/usr/bin/env bash +#!/bin/sh # https://docs.gitlab.com/ee/api/README.html glserver="https://gitlab.com" apiversion="v4" whoami="admesg" -#debug="-v" -function show_help { - echo "${0##*/} { CREATE [VISIBILITY] | DELETE } PROJECTNAME[S]" - echo "where ACTION is 'create' or 'delete', where 'create' creates a " - echo "$glserver project with name PROJECTNAME." - echo "VISIBILITY can be 'private', 'internal', or 'public'." - echo "If VISIBILITY is not set, the project will be set as 'private'." +show_help() { + echo "${0##*/} { CREATE [VISIBILITY] | DELETE } PROJECTNAME[S]" + echo "where ACTION is 'create' or 'delete', where 'create' creates a " + echo "$glserver project with name PROJECTNAME." + echo "VISIBILITY can be 'private', 'internal', or 'public'." + echo "If VISIBILITY is not set, the project will be set as 'private'." } -function send_create_project { - curl "$debug" \ - --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ - --header "Accept: application/json" \ - --header "Content-type: application/json" \ - --request POST \ - --data "{\"name\":\"$2\", \"visibility_level\":$1}" \ - "$glserver/api/$apiversion/projects" +send_create_project() { + curl \ + --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ + --header "Accept: application/json" \ + --header "Content-type: application/json" \ + --request POST \ + --data "{\"name\":\"$2\", \"visibility_level\":$1}" \ + "$glserver/api/$apiversion/projects" } -function send_delete_project { - curl "$debug" \ - --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ - --request DELETE \ - "$glserver/api/$apiversion/projects/$whoami%2F$1" +send_delete_project() { + curl \ + --header "PRIVATE-TOKEN: $(pass Online/gitlab.com-admesg-private-access-token)" \ + --request DELETE \ + "$glserver/api/$apiversion/projects/$whoami%2F$1" } -function die { - printf '%s\n' "$1" >&2 - exit 1 +die() { + printf '%s\n' "$1" >&2 + exit 1 } -[[ $# -lt 2 ]] && (show_help && exit 1) +[ $# -lt 2 ] && (show_help && exit 1) visibility=0 delete=0 while :; do - case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - delete) - delete=1 - ;; - create) # default operation - ;; - private) - visibility=0 - ;; - internal) - visibility=10 - ;; - public) - visibility=20 - ;; - --) # end all options - shift - break - ;; - -?*) - die 'Error: Unknown option specified' - ;; - *) # no more options - break - esac - shift + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + delete) + delete=1 + ;; + create) # default operation + ;; + private) + visibility=0 + ;; + internal) + visibility=10 + ;; + public) + visibility=20 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # no more options + break + esac + shift done -[[ $# -lt 1 ]] && die 'Error: No project name[s] specified' +[ $# -lt 1 ] && die 'Error: No project name[s] specified' # loop over PROJECTNAME[S] for projectname in "$@"; do - - if [[ "$delete" = 1 ]]; then - echo "deleting $projectname" - send_delete_project "$projectname" - else - send_create_project "$visibility" "$projectname" - fi + if [ "$delete" = 1 ]; then + echo "deleting $projectname" + send_delete_project "$projectname" + else + send_create_project "$visibility" "$projectname" + fi done diff --git a/.local/bin/i3resize b/.local/bin/i3resize @@ -1,27 +0,0 @@ -#!/bin/sh -# This script was made by `goferito` on Github. -# Some cleanup by Luke. - -[ -z "$1" ] && echo "No direction provided" && exit 1 -distanceStr="2 px or 2 ppt" - -moveChoice() { - i3-msg resize "$1" "$2" "$distanceStr" | grep '"success":true' || \ - i3-msg resize "$3" "$4" "$distanceStr" -} - -case $1 in - up) - moveChoice grow up shrink down - ;; - down) - moveChoice shrink up grow down - ;; - left) - moveChoice shrink right grow left - ;; - right) - moveChoice grow right shrink left - ;; -esac - diff --git a/.local/bin/i3status-mpc.sh b/.local/bin/i3status-mpc.sh @@ -1,27 +0,0 @@ -#!/bin/sh -mpdcolor="#81a2be" -host=bigquake.ucsd.edu - -i3status --config ~/.i3/status | (read line && echo $line && read line && echo $line && while : -do - read line - dat="" - if [[ -n $(mpc -h $host | grep playing) ]] - then - dat="$(mpc current -h $host -f '[%artist%]'): $(mpc current -h $host -f '[%title%]')" - fi - newmails=$(find ~/mail/*/INBOX/new -type f | wc -l) - kbdlayout=$(cat ~/.kbd-layout) - mailcolor="#859900" - if [ "$newmails" -gt 0 ]; then - mailcolor="#cb4b16" - fi - - dat="["\ -"{\"full_text\":\"${dat}\",\"color\":\"${mpdcolor}\"},"\ -"{\"full_text\":\"M: ${newmails}\",\"color\":\"${mailcolor}\"},"\ -"{\"full_text\":\"${kbdlayout}\"}," - - #dat="[{\"name\":\"mpd\",\"full_text\":\"asdf\"}," - echo "${line/[/$dat}" || exit 1 -done) diff --git a/.local/bin/passmenu b/.local/bin/passmenu @@ -1,11 +1,11 @@ -#!/usr/bin/env bash +#!/bin/bash shopt -s nullglob globstar typeit=0 -if [[ $1 == "--type" ]]; then - typeit=1 - shift +if [ "$1" = "--type" ]; then + typeit=1 + shift fi prefix=${PASSWORD_STORE_DIR-~/.password-store} @@ -15,11 +15,11 @@ password_files=( "${password_files[@]%.gpg}" ) password=$(printf '%s\n' "${password_files[@]}" | dmenu_themed -i "$@") -[[ -n $password ]] || exit +[ -n "$password" ] || exit -if [[ $typeit -eq 0 ]]; then - pass show -c "$password" 2>/dev/null +if [ $typeit -eq 0 ]; then + pass show -c "$password" 2>/dev/null else - pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | - xdotool type --clearmodifiers --file - + pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | + xdotool type --clearmodifiers --file - fi