From: Michael D. Lowis Date: Tue, 9 Oct 2018 18:37:08 +0000 (-0400) Subject: added bin directory with helper scripts and commands X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=bf3a131b079538653289943b6ae5fe0d03fdd360;p=projs%2Ftide.git added bin directory with helper scripts and commands --- diff --git a/bin/E-S b/bin/E-S new file mode 100755 index 0000000..872235f --- /dev/null +++ b/bin/E-S @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/GNTX_EXTERN\|extern/static/g' diff --git a/bin/S-E b/bin/S-E new file mode 100755 index 0000000..94e333f --- /dev/null +++ b/bin/S-E @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/GNTX_STATIC\|static/extern/g' diff --git a/bin/c+ b/bin/c+ new file mode 100755 index 0000000..fa23571 --- /dev/null +++ b/bin/c+ @@ -0,0 +1,5 @@ +#!/bin/sh +case "$(lang "$file")" in + C) sed 's/^/\/\//g' "$@" ;; + *) sed 's/^/#/g' "$@" ;; +esac diff --git a/bin/c- b/bin/c- new file mode 100755 index 0000000..93107ad --- /dev/null +++ b/bin/c- @@ -0,0 +1,5 @@ +#!/bin/sh +case "$(lang "$file")" in + C) sed 's/^\/\///g' "$@" ;; + *) sed 's/^#//g' "$@" ;; +esac diff --git a/bin/findall b/bin/findall new file mode 100755 index 0000000..54ddc42 --- /dev/null +++ b/bin/findall @@ -0,0 +1,23 @@ +#!/bin/sh +pattern='' +dir='.' + +usage(){ + echo "Usage: pfind DIR PATTERN [FLAGS]" + echo "Usage: pfind PATTERN" + exit 1 +} + +case $# in +0) usage ;; +1) pattern=$1; shift ;; +*) dir=$1; shift; pattern=$1; shift ;; +esac + +find "$dir" \( \( \ + -type d -name '.svn' -o \ + -type d -name '.git' -o \ + -type d -iname 'build' -o \ + -type f -name 'tags' \ + \) -prune \ +\) -o -type f -exec grep -n --color=always "$@" "$pattern" {} + diff --git a/bin/i+ b/bin/i+ new file mode 100755 index 0000000..13a0f95 --- /dev/null +++ b/bin/i+ @@ -0,0 +1,6 @@ +#!/bin/sh +case "$(lang "$file")" in + ML|Python|Ruby) + sed 's/^/ /g' "$@" ;; + *) sed 's/^/ /g' "$@" ;; +esac diff --git a/bin/i- b/bin/i- new file mode 100755 index 0000000..2644f96 --- /dev/null +++ b/bin/i- @@ -0,0 +1,6 @@ +#!/bin/sh +case "$(lang "$file")" in + ML|Python|Ruby) + sed 's/^\( \?\| \? \?\)//g' "$@" ;; + *) sed 's/^\( \?\| \? \? \? \?\)//g' "$@" ;; +esac diff --git a/bin/lang b/bin/lang new file mode 100755 index 0000000..8c1806f --- /dev/null +++ b/bin/lang @@ -0,0 +1,9 @@ +#!/bin/sh +case "$1" in + *.c|*.cpp|*.cc|*.h|*.hpp) + echo "C" ;; + *.ml) echo "ML" ;; + *.py) echo "Python" ;; + *.rb) echo "Ruby" ;; + *) echo "Text" ;; +esac diff --git a/bin/no-c++ b/bin/no-c++ new file mode 100755 index 0000000..8d1474c --- /dev/null +++ b/bin/no-c++ @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's_\/\/\([^\r\n]\+\)_\/*\1 *\/_g' diff --git a/bin/pfind b/bin/pfind new file mode 100755 index 0000000..a44a5b3 --- /dev/null +++ b/bin/pfind @@ -0,0 +1,6 @@ +#!/bin/sh +path="$PWD" +while [[ "$path" != "" ]]; do + find "$path" -maxdepth 1 -mindepth 1 "$@" + path="${path%/*}" +done diff --git a/bin/pickfile b/bin/pickfile new file mode 100644 index 0000000..0334c35 --- /dev/null +++ b/bin/pickfile @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +export PICKTITLE="Pick File ($PWD)" +file="$(find $1 -not -path '*/\.*' -type f | sed 's|^\./||' | pick)" +tctl "$file" diff --git a/bin/picktag b/bin/picktag new file mode 100755 index 0000000..cf8b5cc --- /dev/null +++ b/bin/picktag @@ -0,0 +1,51 @@ +#!/bin/sh +ACTION="$1" +TAGFILE="$2" +TAG="$3" + +usage(){ + echo "Usage: $0 ACTION TAGFILE [TAG]" + echo "" + echo "Actions:" + echo " fetch - Print the filename and line number of the selcted tag" + echo " print - Print the selected tag" + exit 1 +} + +if [ "" == "$TAGFILE" ] || [ "" == "$ACTION" ]; then + usage +fi + +printtags(){ + cat "$TAGFILE" | grep -v '^!' | cut -f1 | uniq +} + +print(){ + printf "%s" "$(printtags | pick "$TAG")" +} + +fetch(){ + if [ "" == "$TAG" ]; then + TAG=$(printtags | pick) + [ "" == "$TAG" ] && exit + fi + file=$(awk -v TAG="$TAG" ' + BEGIN { FS = "[\t]+" } + ($1 == TAG) { + matchstr = $3 + sub(/^\//, "\"", matchstr) + sub(/\$?\/;"$/, "\"", matchstr) + gsub(/\*/, "\\*", matchstr) + gsub(/(\[|\])/, "\\\1", matchstr) + print "grep -Hn", matchstr, $2, "| cut -d: -f1,2" + } + ' "$TAGFILE" | /bin/sh | pick) + [ "" != "$file" ] && tctl "$file" +} + +export PICKTITLE="Pick CTag ($PWD)" +case "$ACTION" in + "print") print ;; + "fetch") fetch ;; + *) usage ;; +esac diff --git a/bin/tofn b/bin/tofn new file mode 100755 index 0000000..2eacda5 --- /dev/null +++ b/bin/tofn @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/;\r\?$/\n{\n}\n/g' diff --git a/bin/trim b/bin/trim new file mode 100755 index 0000000..4857571 --- /dev/null +++ b/bin/trim @@ -0,0 +1,2 @@ +#!/bin/sh +sed 's/[ ]*$//g' "$@"