dotfiles

configuration files
git clone https://pi.duncano.de/git/dotfiles.git
Log | Files | Refs | README

commit 05c9bcd955626a88063715dcdc0654a421dec7b4
parent b6d470da3742beff17be3f5102239f4a2b4fcd2c
Author: Duncaen <mail@duncano.de>
Date:   Tue,  6 Dec 2016 21:01:50 +0100

bin: add some new scripts

Diffstat:
bin/fzpgrep | 9+++++++++
bin/less | 15+++++++++++++++
bin/nginx-here | 46++++++++++++++++++++++++++++++++++++++++++++++
bin/psgrep | 4++++
bin/sprunge | 12++++++++++++
bin/ssh-copy-term | 4++++
bin/unpatch | 40++++++++++++++++++++++++++++++++++++++++
bin/urlencode | 46++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/bin/fzpgrep b/bin/fzpgrep @@ -0,0 +1,9 @@ +#!/bin/sh +# fzpsgrep [pattern] - psgrep with fzy selection + +psgrep "$@" | \ + while read -r l; do + printf '%s\n' "$l" >2 + fzy | awk '{print $2}' + break + done diff --git a/bin/less b/bin/less @@ -0,0 +1,15 @@ +#!/bin/sh + +: ${LESS="-FXRi"} + +LESS_TERMCAP_md=$'\e[1;31m' # start bold +LESS_TERMCAP_so=$'\e[1;40;37m' # start standout +LESS_TERMCAP_se=$'\e[0m' # end standout +LESS_TERMCAP_us=$'\e[0;34m' # start underlining +LESS_TERMCAP_ue=$'\e[0m' # end underlining +LESS_TERMCAP_me=$'\e[0m' # end all modes + +export LESS LESS_TERMCAP_md LESS_TERMCAP_so LESS_TERMCAP_se LESS_TERMCAP_us \ + LESS_TERMCAP_ue LESS_TERMCAP_me + +for l in /usr/bin/less /bin/less; do [ -x "$l" ] && exec "$l"; done diff --git a/bin/nginx-here b/bin/nginx-here @@ -0,0 +1,46 @@ +#!/bin/sh +# nginx-here [DIR] [PORT] - serve current directory (or DIR) on PORT (or 8080) + +DIR=$(realpath ${1:-.}) +PORT=${2:-8080} + +mkdir -p /tmp/.nginx-here.$$ +cat >/tmp/.nginx-here.$$/cfg <<EOF +worker_processes 1; +error_log "/dev/stdout"; +daemon off; +pid "/tmp/.nginx-here.$$/pid"; +events { + worker_connections 1024; +} + +http { + access_log "/dev/stdout"; + client_body_temp_path "/tmp/.nginx-here.$$"; + scgi_cache off; + scgi_temp_path "/tmp/.nginx-here.$$"; + uwsgi_cache off; + uwsgi_temp_path "/tmp/.nginx-here.$$"; + fastcgi_cache off; + #fastcgi_cache_path "/tmp/.nginx-here.$$" 1; + fastcgi_temp_path "/tmp/.nginx-here.$$"; + proxy_temp_path "/tmp/.nginx-here.$$"; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen $PORT; + sendfile on; + gzip on; + + location / { + root "$DIR"; + autoindex on; + index index.html index.htm; + } + } +} +EOF +nginx -p /tmp/.nginx-here.$$ -c cfg +rm -r /tmp/.nginx-here.$$ diff --git a/bin/psgrep b/bin/psgrep @@ -0,0 +1,4 @@ +#!/bin/sh +# psgrep [pattern] + +exec ps up $(pgrep -f $@) 2>&-; diff --git a/bin/sprunge b/bin/sprunge @@ -0,0 +1,12 @@ +#!/bin/sh +# sprunge FILES... - paste to sprunge.us + +if [ $# -lt 2 ]; then + cat "$@" +else + for f; do + echo "## $f" + cat "$f" + echo + done +fi | curl -sF 'sprunge=<-' http://sprunge.us | tr -d ' ' diff --git a/bin/ssh-copy-term b/bin/ssh-copy-term @@ -0,0 +1,4 @@ +#!/bin/sh +# ssh-copy-term - copy terminfo via ssh +# 10dec2014 +chris+ +infocmp $TERM | ssh "$@" 't="$(mktemp)" && cat >"$t" && tic -s "$t"' diff --git a/bin/unpatch b/bin/unpatch @@ -0,0 +1,40 @@ +#!/bin/sh +# unpatch [-pN] FILES... - re-generate patch from files and their .orig version + +STRIP=0 +case "$1" in + -p*) STRIP=${1#-p}; shift;; +esac + +pstrip() { + i=0 p=$1 + while [ "$i" -lt "$STRIP" ]; do + i=$((i+1)) p=${p#*/} + done + printf %s "$p" +} + +match() { + case "$1" in + $2) true;; + *) false;; + esac +} + +if [ "$#" -eq 0 ]; then + set -- . + STRIP=$((STRIP+1)) +fi +for f; do + if [ -f "$f" ] && [ -f "$f.orig" ]; then + diff -u --label "$(pstrip "$f.orig")" "$f.orig" \ + --label "$(pstrip "$f")" "$f" + elif match "$f" "*.orig" && [ -f "$f" ] && [ -f "${f%.orig}" ]; then + diff -u --label "$(pstrip "$f")" "$f" \ + --label "$(pstrip "${f%.orig}")" "${f%.orig}" + elif [ -d "$f" ]; then + find "$f" -type f -name '*.orig' -exec "$0" "-p$STRIP" {} ';' + else + printf "Can't unpatch '%s'.\n" "$f" 1>&2 + fi +done diff --git a/bin/urlencode b/bin/urlencode @@ -0,0 +1,46 @@ +#!/bin/mksh + +typeset decoded=$1 encoded= rest= c= +typeset rest2= bug='rest2=${rest}' + +if [[ -z ${BASH_VERSION} ]]; then + # bug /usr/bin/sh HP-UX 11.00 + typeset _decoded='xyz%26xyz' + rest="${_decoded#?}" + c="${_decoded%%${rest}}" + if (( ${#c} != 1 )); then + typeset qm='????????????????????????????????????????????????????????????????????????' + typeset bug='(( ${#rest} > 0 )) && typeset -L${#rest} rest2="${qm}" || rest2=${rest}' + fi +fi + +rest="${decoded#?}" +eval ${bug} +c="${decoded%%${rest2}}" +decoded="${rest}" + +while [[ -n ${c} ]]; do + case ${c} in + [-a-zA-z0-9.]) + ;; + ' ') + c='+' + ;; + *) + c=$(printf "%%%02X" "'$c") + ;; + esac + + encoded="${encoded}${c}" + + rest="${decoded#?}" + eval ${bug} + c="${decoded%%${rest2}}" + decoded="${rest}" +done + +if [[ -n ${BASH_VERSION:-} ]]; then + \echo -E "${encoded}" +else + print -r -- "${encoded}" +fi