shellutils
changeset 0:80fc0c4b11c0 tip
collection of shell scripts
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 23 Apr 2015 13:09:47 +0300 |
parents | |
children | |
files | fixname glext_cat glext_url lsflv |
diffstat | 4 files changed, 231 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/fixname Thu Apr 23 13:09:47 2015 +0300 1.3 @@ -0,0 +1,143 @@ 1.4 +#!/bin/sh 1.5 +# ___________________________________________________ 1.6 +# / \_ 1.7 +# | fixname - cleans up filenames | \ 1.8 +# | | | 1.9 +# | author: John Tsiombikas <nuclear@member.fsf.org> | | 1.10 +# | license: public domain | | 1.11 +# \___________________________________________________/ | 1.12 +# \___________________________________________________/ 1.13 +# 1.14 + 1.15 +name=`basename $0` 1.16 +proc_args=true 1.17 +rename=false 1.18 +verbose=false 1.19 + 1.20 + 1.21 +print_usage() 1.22 +{ 1.23 + echo "Usage: $name [options] name1 name2 ... namen" 1.24 + echo 1.25 + echo 'Cleans up the names passed as arguments, and writes them out one per line' 1.26 + echo 'options:' 1.27 + echo ' - use stdin instead of arguments' 1.28 + echo ' -- stop processing options, the rest are considered names to be fixed' 1.29 + echo " -r rename it, don't just print the clean name" 1.30 + echo ' -v verbose output' 1.31 + echo ' -h print usage and exit' 1.32 + echo 'more options will be added in the future to control exactly what fixes are performed' 1.33 +} 1.34 + 1.35 +uscore() 1.36 +{ 1.37 + sed 's/ /_/g' 1.38 +} 1.39 + 1.40 +udashu() 1.41 +{ 1.42 + sed 's/_-_/-/g' 1.43 +} 1.44 + 1.45 +dupl() 1.46 +{ 1.47 + sed 's/__/_/g' | sed 's/--/-/g' 1.48 +} 1.49 + 1.50 +utrail() 1.51 +{ 1.52 + sed 's/_$//g' | sed 's/-$//g' 1.53 +} 1.54 + 1.55 +tolower() 1.56 +{ 1.57 + tr [:upper:] [:lower:] 1.58 +} 1.59 + 1.60 +brac() 1.61 +{ 1.62 + sed 's/[][)(}{><]//g' 1.63 +} 1.64 + 1.65 +diacrit() 1.66 +{ 1.67 + sed s/\'//g | sed 's/["`,;\\]//g' 1.68 +} 1.69 + 1.70 +symb() 1.71 +{ 1.72 + sed 's/[!?@#$%^&*=]//g' 1.73 +} 1.74 + 1.75 +transform() 1.76 +{ 1.77 + uscore | udashu | tolower | brac | diacrit | symb | dupl | utrail 1.78 +} 1.79 + 1.80 +fix() 1.81 +{ 1.82 + fixed=`echo $1 | transform` 1.83 + 1.84 + if [ "$1" = "$fixed" ]; then 1.85 + return 1.86 + fi 1.87 + 1.88 + if $rename; then 1.89 + if $verbose; then 1.90 + echo "$1 -> $fixed" 1.91 + fi 1.92 + 1.93 + mv "$1" "$fixed" 1.94 + else 1.95 + echo "$fixed" 1.96 + fi 1.97 +} 1.98 + 1.99 +fixed_any=false 1.100 + 1.101 +while [ $# -gt 0 ]; do 1.102 + if $proc_args; then 1.103 + 1.104 + case $1 in 1.105 + -) 1.106 + shift 1.107 + transform 1.108 + exit 0 1.109 + ;; 1.110 + 1.111 + --) 1.112 + proc_args=false 1.113 + ;; 1.114 + 1.115 + -r) 1.116 + rename=true 1.117 + ;; 1.118 + 1.119 + -v) 1.120 + verbose=true 1.121 + ;; 1.122 + 1.123 + -h) 1.124 + print_usage 1.125 + exit 0 1.126 + ;; 1.127 + 1.128 + *) 1.129 + fix "$1" 1.130 + fixed_any=true 1.131 + ;; 1.132 + esac 1.133 + else 1.134 + fix "$1" 1.135 + fixed_any=true 1.136 + fi 1.137 + shift 1.138 +done 1.139 + 1.140 +if ! $fixed_any; then 1.141 + for i in *; do 1.142 + if [ -f "$i" ]; then 1.143 + fix "$i" 1.144 + fi 1.145 + done 1.146 +fi
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/glext_cat Thu Apr 23 13:09:47 2015 +0300 2.3 @@ -0,0 +1,2 @@ 2.4 +#!/bin/sh 2.5 +wget -q -O - `glext_url $1`
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/glext_url Thu Apr 23 13:09:47 2015 +0300 3.3 @@ -0,0 +1,6 @@ 3.4 +#!/bin/sh 3.5 + 3.6 +prefix=`echo $1 | sed 's/^GL_//' | sed 's/_.*$//'` 3.7 +name=`echo $1 | sed 's/^.*[A-Z]\+_//'` 3.8 + 3.9 +echo "http://www.opengl.org/registry/specs/$prefix/$name.txt"
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/lsflv Thu Apr 23 13:09:47 2015 +0300 4.3 @@ -0,0 +1,80 @@ 4.4 +#!/bin/sh 4.5 +# ------------------------------------------------------------------------- 4.6 +# lsflv - prints a list (and optionally saves copies of) videos currently 4.7 +# being played by the adobe flash player browser plugin. 4.8 +# 4.9 +# Written by John Tsiombikas <nuclear@member.fsf.org> 4.10 +# This script is placed in the public domain, do whatever you want with it. 4.11 +# ------------------------------------------------------------------------- 4.12 + 4.13 +mkcopy=no 4.14 +play=no 4.15 +player=${PLAYER:-mpv} 4.16 +bin=`basename $0` 4.17 +dir=`pwd` 4.18 + 4.19 +# if invoked as cpflv always make a copy (as in -c) 4.20 +if [ "$bin" = cpflv ]; then 4.21 + mkcopy=yes 4.22 +fi 4.23 + 4.24 +# if invoked as playflv play the video (as in -p) 4.25 +if [ "$bin" = playflv ]; then 4.26 + play=yes 4.27 +fi 4.28 + 4.29 +# process arguments 4.30 +while [ $# -gt 0 ]; do 4.31 + case "$1" in 4.32 + -c) 4.33 + mkcopy=yes 4.34 + ;; 4.35 + -p) 4.36 + play=yes 4.37 + ;; 4.38 + -d) 4.39 + dir=$2 4.40 + shift 4.41 + ;; 4.42 + -h) 4.43 + echo "Usage: $bin [options]" 4.44 + echo "Options:" 4.45 + echo " -c make copies of the video files" 4.46 + echo " -d <dir> change the directory used to copy the files to (default: cwd)" 4.47 + echo " -h print usage and exit" 4.48 + exit 0 4.49 + ;; 4.50 + esac 4.51 + shift 4.52 +done 4.53 + 4.54 + 4.55 +list=`lsof | egrep '(/tmp/Flash|/tmp/mozilla-media-cache)' | awk '{ print $2":"$4 }'` 4.56 + 4.57 +num=0 4.58 + 4.59 +for i in $list; do 4.60 + pid=`echo $i | awk -F: '{ print $1 }'` 4.61 + fd=`echo $i | awk -F: '{ print $2 }' | sed 's/[a-zA-Z]*//g'` 4.62 + 4.63 + if [ -n "$fd" ]; then 4.64 + path="/proc/$pid/fd/$fd" 4.65 + 4.66 + num=`echo "$num + 1" | bc` 4.67 + target="$dir/vid$num" 4.68 + 4.69 + if [ $mkcopy = yes ]; then 4.70 + echo "copy $path -> $target" 4.71 + if ! cp $path $target; then 4.72 + echo "failed to copy $path to $target" >&2 4.73 + exit 1 4.74 + fi 4.75 + else 4.76 + echo "$path" 4.77 + fi 4.78 + 4.79 + if [ $play = yes ]; then 4.80 + $player $path 4.81 + fi 4.82 + fi 4.83 +done