aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2016-12-06 21:01:50 +0100
committerDuncaen <mail@duncano.de>2016-12-06 21:01:50 +0100
commit05c9bcd955626a88063715dcdc0654a421dec7b4 (patch)
tree5ee51877053401a3aca23dc3010e43e96e0a3f66
parentb6d470da3742beff17be3f5102239f4a2b4fcd2c (diff)
downloaddotfiles-05c9bcd955626a88063715dcdc0654a421dec7b4.tar.gz
bin: add some new scripts
-rwxr-xr-xbin/fzpgrep9
-rwxr-xr-xbin/less15
-rwxr-xr-xbin/nginx-here46
-rw-r--r--bin/psgrep4
-rwxr-xr-xbin/sprunge12
-rwxr-xr-xbin/ssh-copy-term4
-rwxr-xr-xbin/unpatch40
-rw-r--r--bin/urlencode46
8 files changed, 176 insertions, 0 deletions
diff --git a/bin/fzpgrep b/bin/fzpgrep
new file mode 100755
index 0000000..96dd184
--- /dev/null
+++ 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
new file mode 100755
index 0000000..cad1e64
--- /dev/null
+++ 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
new file mode 100755
index 0000000..cff1001
--- /dev/null
+++ 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
new file mode 100644
index 0000000..1ed0517
--- /dev/null
+++ 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
new file mode 100755
index 0000000..0a05f4c
--- /dev/null
+++ 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
new file mode 100755
index 0000000..db7c1c5
--- /dev/null
+++ 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
new file mode 100755
index 0000000..7ae0ec5
--- /dev/null
+++ 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
new file mode 100644
index 0000000..2df4d65
--- /dev/null
+++ 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