scripts

random scripts
git clone git://parazyd.org/scripts.git
Log | Files | Refs

commit b0b5f6e551e11c25cfda08111a983aa265d6b3f7
parent ec341a07b44bd9aac24270916e52ca817320a346
Author: parazyd <parazyd@dyne.org>
Date:   Mon,  9 Jan 2017 00:22:30 +0100

latest updates

Diffstat:
Maddrepo.sh | 14+++++++-------
Daliens.sh | 7-------
Mapk | 58+++++++++++++++++++++++++++++-----------------------------
Aauphone | 16++++++++++++++++
Mautoup | 2+-
Dbackup.sh | 1-
Mbeepop | 3---
Mbright | 6++----
Dcdmenu | 21---------------------
Dcdump | 3---
Acuesplit.sh | 47+++++++++++++++++++++++++++++++++++++++++++++++
Dddg | 2--
Adillo | 5+++++
Admenuraise | 35+++++++++++++++++++++++++++++++++++
Ddmenuwindows | 36------------------------------------
Mdn | 4++--
Aemerupd | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mextmon | 11+++++++----
Afbits | 42++++++++++++++++++++++++++++++++++++++++++
Dfind-https-debian-archives.py | 136-------------------------------------------------------------------------------
Dg | 2--
Dgit-update-all | 20--------------------
Ainterjection.sh | 6++++++
Amaclookup | 11+++++++++++
Rgetmagnet -> magnet2torrent | 0
Anet | 3+++
Anote | 2++
Anotify-send | 2++
Rlock -> obsolete/lock | 0
Dopen | 295-------------------------------------------------------------------------------
Dpacmans.sh | 45---------------------------------------------
Mpipesx | 6+++---
Aradio | 40++++++++++++++++++++++++++++++++++++++++
Dskrot | 7-------
Aspark | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aspin | 8++++++++
Asurf.sh | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aupdate-gits | 10++++++++++
Mvolume | 1+
Awifi2qr | 18++++++++++++++++++
Mxurls | 116++-----------------------------------------------------------------------------
Cxurls -> xurls.pl | 0
Mydl | 2+-
Ayt | 5+++++
44 files changed, 607 insertions(+), 743 deletions(-)

diff --git a/addrepo.sh b/addrepo.sh @@ -3,7 +3,8 @@ # parazyd - (c) wtfpl 2016 # add a repository to gitolite conf and push -GITOLITE="/home/parazyd/devel/gitolite-admin" +GITOLITE="/home/parazyd/devel/parazyd.cf-gitolite" +GITSERVER="git.parazyd.cf" reponame="$1" repodesc="$2" @@ -12,7 +13,7 @@ repoowner=`awk '/name =/ {print $3}' ~/.gitconfig` writeconf() { - if [ "$repodesc" == "unlisted" || $repodesc == "private" ]; then + if [ $repodesc = private ]; then cat <<EOF repo $reponame RW = $repoowner @@ -22,16 +23,13 @@ EOF cat <<EOF repo $reponame RW+ = $repoowner - R = gitweb - config core.sharedRepository = true - config gitweb.description = "${repodesc}" - config gitweb.owner = "${repoowner}" + R = gitweb daemon EOF fi } -if [ -n $reponame ] && [ -n $repodesc ]; then +if [ -n $reponame ]; then cd $GITOLITE writeconf >> conf/gitolite.conf git commit conf/gitolite.conf -m "added $reponame repository" @@ -41,3 +39,5 @@ else echo "usage: `basename $0` [repo name] [repo description] [repo owner]" fi + +ssh $GITSERVER ~/bin/gitadd.sh "$reponame" "$repodesc" "$repoowner" diff --git a/aliens.sh b/aliens.sh @@ -1,7 +0,0 @@ -#!/bin/sh -# -# parazyd - (c) wtfpl 2016 -# some disco - -x="if(t%2)else" -python3 -c "[print(t>>15&(t>>(2$x 4))%(3+(t>>(8$x 11))%4)+(t>>10)|42&t>>7&t<<9,end='')for t in range(2**20)]" | aplay -c2 -r4 diff --git a/apk b/apk @@ -1,36 +1,36 @@ #!/bin/sh # wtfpl (c) parazyd _arch="x86_64";_query="$@" - test -n "$_query" || exit 1 - _url="http://pkgs.alpinel" - _url="${_url}inux.org" # | + test -n "$_query" || exit 1 + _url="http://pkgs.alpinel" + _url="${_url}inux.org" # | _url="${_url}/packages?" # - _page="$(elinks -dump \ - "${_url}name=${_query}&arch=${_arch}")" - pkgtable="$(echo "$_page"|sed 34q | - grep $_query | grep '^\[')"; # xxx| - test -n "$pkgtable" || { - echo "(*) no packages found"; exit 1 - }; pkgurl="$(echo "$_page" | grep http | - grep '/package/'\ - | sed 1q | tr -d '\t')" ; - eval "echo $pkgurl | - grep main >/dev/null"\ - && pkgname=main ; eval \ - "echo $pkgurl | grep community >/dev/null"\ + _page="$(elinks -dump \ + "${_url}name=${_query}&arch=${_arch}")" + pkgtable="$(printf "%s\\n" "$_page"| sed 34q | + grep $_query | grep '^\[')"; # xxx| + test -n "$pkgtable" || { + printf "(*) no packages found\\n"; exit 1 + }; pkgurl="$(printf "%s\\n" "$_page" | grep http | + grep '/package/'\ + | sed 1q | tr -d '\t')" ; + eval "printf '%s\\n' $pkgurl | + grep main >/dev/null"\ + && pkgname=main ; eval \ + "printf '%s\\n' $pkgurl | grep community >/dev/null"\ && pkgname=community;eval \ - "echo $pkgurl | grep testing >/dev/null" \ + "printf '%s\\n' $pkgurl | grep testing >/dev/null" \ && pkgname=testing # random - pkgver="$(echo "$pkgtable"| - awk -F']' '{print $3}' | - awk -F'[' '{print $1}' | - tr '\n' ' ')" - home="$( echo "$_page" | - grep http | awk '/18/ {print $2}')" - desc="$( echo "$_page" | - awk '/16\./ { for (i=2; i<=NF; i++) print $i}' | + pkgver="$(printf "%s\\n" "$pkgtable"| \ + awk -F']' '{print $3}' | \ + awk -F'[' '{print $1}' | \ + tr '\n' ' ')" + home="$( printf "%s\\n" "$_page" | + grep http | awk '/18/ {print $2}')" + desc="$( printf "%s\\n" "$_page" | + awk '/16\./ { for (i=2; i<=NF; i++) print $i}' | tr '\n' ' ')" ; pkgname="$pkgname/$(\ - echo $pkgtable | awk -F']' '{print $2}' | - awk -F'[' '{print $1}')"; echo -e "* $pkgname" - echo -e "\tavailable versions: $pkgver"; echo -e "\thomepage: $home" - echo -e "\tdescription: $desc"; echo -e "\tpackage url: $pkgurl" + printf "%s\\n" $pkgtable | awk -F']' '{print $2}' | + awk -F'[' '{print $1}')"; printf "* %s\\n" "$pkgname" + printf "\tavailable versions: %s\\n" "$pkgver"; printf "\thomepage: %s\\n" "$home" + printf "\tdescription: %s\\n" "$desc"; printf "\tpackage url: %s\\n" "$pkgurl" diff --git a/auphone b/auphone @@ -0,0 +1,16 @@ +#!/bin/sh + +PROVIDER=2f30.org +if [ $1 ] +then + OTHER=$1 +else + echo "Use $O to talk with someone..." && exit 1 +fi +AUARGS="-b 1 -r 11000 -e u8" + +ssh $PROVIDER "rm -f /tmp/$USER && mkfifo /tmp/$USER" + +aucat $AUARGS -o - \ +| ssh $PROVIDER "cat > /tmp/$USER & cat /tmp/$OTHER" \ +| aucat $AUARGS -i - diff --git a/autoup b/autoup @@ -3,7 +3,7 @@ sshuser=parazyd sshkey="$HOME/.ssh/id_ed25519" server=pub.parazyd.cf -webroot=/home/parazyd/public_html/pub +webroot=/home/parazyd/public_html/pub.parazyd.cf webdir=dev/random test -z "$1" && exit 1 || filename=$(basename $1) diff --git a/backup.sh b/backup.sh @@ -1 +0,0 @@ -rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/parazyd/mnt"} / /home/parazyd/mnt/backup/ diff --git a/beepop b/beepop @@ -15,9 +15,6 @@ default_geometry() { FIFO=/tmp/beepop.fifo GEOM=$(default_geometry) -FONT=Terminus -BG=#00aabbcc -FG=#00ccbbaa SLEEP=3 case $(basename $0) in diff --git a/bright b/bright @@ -1,19 +1,17 @@ #!/bin/sh syspath="/sys/class/backlight/intel_backlight" - step=300 - case "$1" in +) curr="$(cat $syspath/brightness)" - let curr=$curr+$step + curr=$(($curr+$step)) printf "%s" "$curr" > "$syspath"/brightness ;; -) curr="$(cat $syspath/brightness)" - let curr=$curr-$step + curr=$(($curr-$step)) printf "%s" "$curr" > "$syspath"/brightness ;; *) diff --git a/cdmenu b/cdmenu @@ -1,21 +0,0 @@ -#!/bin/sh - -normfg="#939393" -normbg="#000000" -selbg="#800000" -selfg="#ffffff" -font="Terminus:size=9" - -list="$(ls -d */ \ - | dmenu -p 'cd' \ - -l 20 \ - -fn $font \ - -nb $normbg \ - -nf $normfg \ - -sb $selbg \ - -sf $selfg \ - $@)" - -if [ ! -z "$list" ]; then - echo $list -fi diff --git a/cdump b/cdump @@ -1,3 +0,0 @@ -#!/bin/sh - -xrdb -query | grep -P '^\*color[0-9]*:' | tr -d '\t' | cut -d: -f2 #| hex2col diff --git a/cuesplit.sh b/cuesplit.sh @@ -0,0 +1,47 @@ +#!/bin/sh +#dependencies: cuetools, shntool, flac + +if [ $# -ne 2 ] || [ "$1" = "-h" ] +then + printf "Usage: %s image cue\n" "$0" + exit 1 +fi + +MUSIC_DIR="$HOME/Data/Music" +ARTIST="$(tr -d '\r' < "$2" | grep -F PERFORMER | head -n 1 | sed -e 's#.*"\(.*\)"#\1#' -e 's#/#_#g')" +ALBUM="$(tr -d '\r' < "$2" | grep -F TITLE | head -n 1 | sed -e 's#.*"\(.*\)"#\1#' -e 's#/#_#g')" +DATE="$(tr -d '\r' < "$2" | grep -F 'REM DATE' | head -n 1 | cut -d ' ' -f 3)" + +split() +{ + mkdir -p split + shnsplit -d split -f "$2" -o "flac flac -V -8 -o %f -" "$1" -t "%n - %t" + rm -- split/00*pregap* +} + +tag() +{ + cuetag.sh "$1" split/*.flac + # add the date tag since cuetag can't do it + if [ -n "$DATE" ] + then + metaflac --set-tag="date=$DATE" split/*.flac + fi + printf 'Calculating replay gain values...' + metaflac --add-replay-gain split/*.flac +} + +movedir() +{ + printf 'Move split/ to "%s/%s/(%s) %s"? y/n' "$MUSIC_DIR" "$ARTIST" "$DATE" "$ALBUM" + read -r CHOICE + if [ "$CHOICE" = "y" ] + then + mkdir -p -- "$MUSIC_DIR/$ARTIST/($DATE) $ALBUM" + mv -T -- split "$MUSIC_DIR/$ARTIST/($DATE) $ALBUM" + fi +} + +split "$1" "$2" +tag "$2" +movedir diff --git a/ddg b/ddg @@ -1,2 +0,0 @@ -#!/bin/sh -palemoon -new-tab "https://duckduckgo.com/html/?q=$*" diff --git a/dillo b/dillo @@ -0,0 +1,5 @@ +#!/bin/sh + +/usr/bin/dillo "$@" + +killall dpid diff --git a/dmenuraise b/dmenuraise @@ -0,0 +1,35 @@ +#!/bin/sh +# +# parayzd - (c) wtfpl 2016 +# list open windows in a dmenu + +normfg="#939393" +normbg="#000000" +selbg="#800000" +selfg="#ffffff" +font="6X13 for Powerline:size=10:antialias=true:autohint=true" + +height=$(wmctrl -l | wc -l) +if [[ $height -gt 30 ]]; then + heightfit=30 +else + heightfit=$height +fi + +num=$(wmctrl -l \ + | sed 's/ tatooine/ /' \ + | cut -d " " -f 4- \ + | nl -w 3 -n rn \ + | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' \ + | dmenu -i \ + -fn $font \ + -nb $normbg \ + -nf $normfg \ + -sb $selbg \ + -sf $selfg \ + -l $heightfit \ + | cut -d '-' -f -1 \ +) + +[ -z "$num" ] && exit +wmctrl -l | sed -n "$num p" | cut -c -10 | xargs wmctrl -i -a diff --git a/dmenuwindows b/dmenuwindows @@ -1,36 +0,0 @@ -#!/bin/sh -# -# parayzd - (c) wtfpl 2016 -# list open windows in a dmenu - -normfg="#939393" -normbg="#000000" -selbg="#800000" -selfg="#ffffff" -#font="Terminus:size=9" -font="Tamsyn:pixelsize=12:antialias=true:autohint=true" - -height=$(wmctrl -l | wc -l) -if [[ $height -gt 30 ]]; then - heightfit=30 -else - heightfit=$height -fi - -num=$(wmctrl -l \ - | sed 's/ hansolo/ /' \ - | cut -d " " -f 4- \ - | nl -w 3 -n rn \ - | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' \ - | dmenu -i \ - -fn $font \ - -nb $normbg \ - -nf $normfg \ - -sb $selbg \ - -sf $selfg \ - -l $heightfit \ - | cut -d '-' -f -1 \ -) - -[ -z "$num" ] && exit -wmctrl -l | sed -n "$num p" | cut -c -10 | xargs wmctrl -i -a diff --git a/dn b/dn @@ -27,8 +27,8 @@ use() { case "$1" in out|o) use "out" "127.0.0.1";; - home|h) use "multiverse" "10.0.1.1";; - bridge|b) use "bridge" "172.16.17.250";; + home|h) use "fq" "10.0.2.1";; + bridge|b) use "bridge" "10.11.11.1";; goog|g) use "goog" "8.8.8.8";; dynevpn|dv) use "dyne" "10.8.0.1";; ti) use "ti" "10.209.20.254";; diff --git a/emerupd b/emerupd @@ -0,0 +1,58 @@ +#!/bin/sh + +usage() { + cat <<EOM +$(basename $0): gentoo update wrapper +usage: + $(basename $0) [-a] [-1] + + steps: + 1) sync (runs eix-sync) + 2) update (does a complete system upgrade) + 3) glsa (does a GLSA check on the system) + 4) depclean (removes unused packages) + 5) preserved-rebuild (runs @preserved-rebuild if needed) + 6) revdep-rebuild (runs revdep-rebuild if needed) +EOM + exit 1 +} + +emersync() { + sudo eix-sync -a +} + +emerupdt() { + sudo emerge -av \ + --verbose-conflicts \ + --with-bdeps=y \ + --update \ + --newuse \ + --deep \ + @world +} + +emerglsa() { + sudo glsa-check -t all +} + +emerdeps() { + sudo emerge -av --depclean +} + +emerpres() { + sudo emerge -av @preserved-rebuild +} + +emerrevd() { + sudo revdep-rebuild.sh -v +} + +case "x$1" in + x-1) emersync || exit 1;; + x-2) emerupdt || exit 1;; + x-3) emerglsa || exit 1;; + x-4) emerdeps || exit 1;; + x-5) emerpres || exit 1;; + x-6) emerrevd || exit 1;; + *) usage ;; +esac diff --git a/extmon b/extmon @@ -6,25 +6,28 @@ IN="LVDS1" EXT="VGA1" +WALL="/home/parazyd/.config/wallpapers/f165f4ddcc12861aa70beb208316b2cea852193ff7b7e4b96839652656db8512.jpg" + case "$1" in left|l) xrandr --output $IN --auto --primary --output $EXT --auto --left-of $IN - nitrogen --restore + feh --no-fehbg --bg-fill "$WALL" ;; right|r) xrandr --output $IN --auto --primary --output $EXT --auto --right-of $IN - nitrogen --restore + feh --no-fehbg --bg-fill "$WALL" ;; above|a) xrandr --output $IN --auto --primary --output $EXT --auto --above $IN - nitrogen --restore + feh --no-fehbg --bg-fill "$WALL" ;; dup|d) xrandr --output $EXT --same-as $IN --output $IN --primary + feh --no-fehbg --bg-fill "$WALL" ;; off|o) xrandr --output $IN --auto --output $EXT --off - nitrogen --restore + feh --no-fehbg --bg-fill "$WALL" ;; list) xrandr | grep \<connected\> | cut -d\ -f1 diff --git a/fbits b/fbits @@ -0,0 +1,42 @@ +#!/bin/bash + +me="${0##*/}" + +if [ -w "$TMPDIR" ]; then + tdir="$TMPDIR" +elif [ -w '/tmp' ]; then + tdir='/tmp' +elif [ -w "$HOME" ]; then + tdir="$HOME" +elif [ -w "$PWD" ]; then + tdir="$PWD" +else + echo "$me: error: can't find a writable directory for creating the temporary file" 1>&2 ; exit 1 +fi + +tf="$( TMPDIR="$tdir" mktemp "${tdir}/${me}.XXXX" 2>/dev/null )" +if [ -z "$tf" ]; then + echo "$me: error: can't create temporary file" 1>&2 ; exit 1 +fi + +checkbits () +{ + local bps abps tbps=0 n=0 + bps="$( metaflac --show-bps "$1" )" + flac -ac "$1" 2>/dev/null | fgrep 'wasted_bits' | cut -d '=' -f 3 | cut -f 1 > "$tf" + while read wb; do + tbps=$(( tbps + ( bps - wb ) )) + ((n++)) + done < "$tf" + abps=$(( ( ( tbps * 10 / n) + 5 ) / 10 )) # (* 10 + 5) / 10 for proper rounding + printf "%2u/%2u bits\t%s\n" "$abps" "$bps" "$1" +} + +for f in "$@"; do + case "$f" in + *.flac) checkbits "$f" ;; + *) continue ;; + esac +done + +rm -f "$tf" diff --git a/find-https-debian-archives.py b/find-https-debian-archives.py @@ -1,136 +0,0 @@ -#!/usr/bin/python2 -# -# tries to find debian mirrors with https enabled - -import urllib2 -import re -import ssl -import sys - -# # find generic mirrors -mirrors = urllib2.urlopen('http://www.debian.org/mirror/list') -https = [] -for line in mirrors.readlines(): - m = re.match('.*<td valign="top"><a rel="nofollow" href="http(.*)">.*', line) - if m: - url = 'https' + m.group(1) - print 'trying: ', - print url, - print '...', - sys.stdout.flush() - try: - response=urllib2.urlopen(url, timeout=1) - https.append(url) - print 'success!' - except urllib2.URLError as err: - print 'fail!' - except ssl.SSLError as err: - print 'bad SSL!' - -# print 'HTTPS apt repos:' -#for url in https: -# print url - - -# # find security mirrors -mirrors = urllib2.urlopen('http://www.debian.org/mirror/list-full') -securitys = [] -for line in mirrors.readlines(): - m = re.match('.*</tt><br>Security updates over HTTP: <tt><a rel="nofollow" href="http(.*)">.*/debian-security/</a>.*', line) - if m: - url = 'https' + m.group(1) - print 'trying: ', - print url, - print '...', - sys.stdout.flush() - try: - response=urllib2.urlopen(url, timeout=1) - securitys.append(url) - print 'success!' - except urllib2.URLError as err: - print 'fail!' - except ssl.SSLError as err: - print 'bad SSL!' - -# print 'HTTPS security repos:' -# for url in securitys: -# print url - - -# now find the backports mirrors -mirrors = urllib2.urlopen('http://backports-master.debian.org/Mirrors/') -backports = [] -for line in mirrors.readlines(): -#<td><a href="http://be.mirror.eurid.eu/debian-backports/">/debian-backports/</a> - m = re.match('.*<td><a href="http(.*)">.*/debian-backports/</a>.*', line) - if m: - url = 'https' + m.group(1) - print 'trying: ', - print url, - print '...', - sys.stdout.flush() - try: - response=urllib2.urlopen(url, timeout=1) - backports.append(url) - print 'success!' - except urllib2.URLError as err: - print 'fail!' - except ssl.SSLError as err: - print 'bad SSL!' - -#print 'HTTPS backports repos:' -#for url in backports: -# print url - - -# now find the CD image mirrors -mirrors = urllib2.urlopen('http://www.debian.org/CD/http-ftp/') -cds = [] -for line in mirrors.readlines(): -# <a rel="nofollow" href="http://mirror.easyspeedy.com/debian-cd/">HTTP</a></li> - m = re.match('.*<a rel="nofollow" href="http(:.*)">HTTP</a></li>.*', line) - if m: - url = 'https' + m.group(1) - print 'trying: ', - print url, - print '...', - sys.stdout.flush() - try: - response=urllib2.urlopen(url, timeout=1) - cds.append(url) - print 'success!' - except urllib2.URLError as err: - print 'fail!' - except ssl.SSLError as err: - print 'bad SSL!' - -print 'HTTPS CD image repos:' -for url in cds: - print url - - -# now write everything to a file -f = open('/tmp/https-debian-archives.txt', 'w') - -f.write('HTTPS apt repos\n') -f.write('---------------\n') -for url in https: - f.write(url + '\n') - -f.write('\n\nHTTPS security repos\n') -f.write('---------------\n') -for url in securitys: - f.write(url + '\n') - -f.write('\n\nHTTPS backports repos\n') -f.write('--------------------\n') -for url in backports: - f.write(url + '\n') - -f.write('\n\nHTTPS CD image repos\n') -f.write('--------------------\n') -for url in cds: - f.write(url + '\n') - - -f.close() diff --git a/g b/g @@ -1,2 +0,0 @@ -#!/bin/sh -surf "https://google.com/search?q=$*" diff --git a/git-update-all b/git-update-all @@ -1,20 +0,0 @@ -#!/bin/sh -# -# parazyd - (c) wtfpl 2016 -# update all git repos in current folder - -for i in *; do - if test -d "$i/.git"; then - cd "$i" - echo "[$i] updating" - git remote update - git pull --rebase - if test $? -eq 1; then - echo "[$i] backing out rebase, fix manually" - git rebase --abort - fi - cd - >/dev/null - else - echo "[$i] not a git repo" 1>&2 - fi -done diff --git a/interjection.sh b/interjection.sh @@ -0,0 +1,6 @@ +#!/bin/sh +echo "I'd just like to interject for a moment. What you're referring to as $1, is in fact, $2/$1, or as I've recently taken to calling it, $2 plus $1. $1 is not an operating system unto itself, but rather another free component of a fully functioning $2 system made useful by the $2 corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. + +Many computer users run a modified version of the $2 system every day, without realizing it. Through a peculiar turn of events, the version of $2 which is widely used today is often called \"$1\", and many of its users are not aware that it is basically the $2 system, developed by the $2 Project. There really is a $1, and these people are using it, but it is just a part of the system they use. + +$1 is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. $1 is normally used in combination with the $2 operating system: the whole system is basically $2 with $1 added, or $2/$1. All the so-called \"$1\" distributions are really distributions of $2/$1." diff --git a/maclookup b/maclookup @@ -0,0 +1,11 @@ +#!/bin/sh + +MACFILE="/usr/share/nmap/nmap-mac-prefixes" + +MACADDR="$@" + +MACADDR="$(printf "%s" "$MACADDR" | tr -d ":" | cut -c1-6)" + +grep "^$MACADDR" "$MACFILE" + + diff --git a/getmagnet b/magnet2torrent diff --git a/net b/net @@ -0,0 +1,3 @@ +#!/bin/sh + +/etc/init.d/net."$1" restart diff --git a/note b/note @@ -0,0 +1 @@ +../notefy/notefy+ \ No newline at end of file diff --git a/notify-send b/notify-send @@ -0,0 +1 @@ +popup+ \ No newline at end of file diff --git a/lock b/obsolete/lock diff --git a/open b/open @@ -1,295 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use constant -{ - PROG_REVEAL => 'rox', - PROG_EDIT => 'vim', -}; - -sub open_smart; -sub edit; -sub stdin_to_editor; -sub reveal; -sub header_edit; -sub wait_or_not; - -sub usage -{ - print STDERR <<"!"; -Usage: $0 -[efWwRh] --e: edit --f: stdin-edit --W: wait for exit (true by default for editing) --w: don't wait for exit --R: reveal --h: header search -! - exit 1; -} - -my $cmd = \&open_smart; -my(@files, @args); - -my %opts = ( - 'e' => 0, - 'f' => 0, - 'W' => 0, - 'R' => 0, - 'h' => 0, -); - -my $wait_set = 0; - -usage() unless @ARGV; - -for(my $i = 0; $i < @ARGV; ++$i){ - $_ = $ARGV[$i]; - - if($_ eq '--'){ - push @files, @ARGV[$i + 1 .. $#ARGV]; - last; - } - - if(/^-([a-z])$/i){ - my $k = $1; - - if(exists $opts{$k}){ - $opts{$k} = 1; - $wait_set = 1 if $k eq 'W'; - }elsif($k eq 'w'){ - $opts{W} = 0; - $wait_set = 1; - }else{ - usage(); - } - - }elsif($_ eq '--args'){ - push @args, @ARGV[$i + 1 .. $#ARGV]; - last; - - }elsif(/^-/){ - usage(); - - }else{ - push @files, $_; - - } -} - -if($opts{e} + $opts{f} + $opts{R} + $opts{h} > 1){ - print STDERR "Can't combine -e, -f, -R and -h\n"; - usage(); -} - -my $should_wait = 1; -if($opts{e}){ - $cmd = \&edit; - -}elsif($opts{f}){ - # <STDIN> | $EDITOR - - $cmd = \&stdin_to_editor; - -}elsif($opts{R}){ - # open with rox - $cmd = \&reveal; - $should_wait = 0; - -}elsif($opts{h}){ - # search /usr/include/$_ for @files - $cmd = \&header_edit; - -} - -$opts{W} = 1 if $should_wait and not $wait_set; - -exit(&{$cmd}(( - wait => !!$opts{W}, - args => [@args], - files => [@files]))); - -# end --- - -sub open_smart -{ - sub read_maps - { - my $rc = "$ENV{HOME}/.openrc"; - open F, '<', $rc or die "open $rc: $!\n"; - - my %maps; - - my $suffix = 0; - while(<F>){ - chomp; - s/#.*//; - - if(/^\[(.*)\]$/){ - if($1 eq 'full'){ - $suffix = 0; - }elsif($1 eq 'suffix'){ - $suffix = 1; - }else{ - die "invalid section \"$1\" in $rc\n"; - } - - }elsif(my($prog, $matches) = /^([^:]+): *(.*)/){ - sub getenv - { - my $k = shift; - return $ENV{$k} if $ENV{$k}; - my %backup = ( - "TERM" => "urxvt", - "VISUAL" => "vim", - ); - return $backup{$k} if $backup{$k}; - return "\$$k"; - } - - my @matches = split / *, */, $matches; - - $prog =~ s/\$([A-Z_]+)/getenv($1)/e; - - push @{$maps{$prog}}, [ $_, $suffix ] for @matches; - - }elsif(length){ - die "invalid confiuration line: \"$1\" in $rc\n"; - } - } - - close F; - - return %maps; - } - - my %maps = read_maps(); - my $ec = 0; - my %h = @_; - - my @to_open; - -file: - for my $fnam (@{$h{files}}){ - #print "maps:\n"; - - if(-d $fnam){ - push @to_open, [($h{wait}, PROG_REVEAL, @{$h{args}}, $fnam)]; - next file; - } - - for my $prog (keys %maps){ - #print " $_:\n"; - for(@{$maps{$prog}}){ - my($reg, $suffix) = ($_->[0], $_->[1]); - if($suffix){ - $reg = "\\.$reg\$"; - } - #print " $reg\n" - - if($fnam =~ /$reg/){ - push @to_open, [($h{wait}, $prog, @{$h{args}}, $fnam)]; - next file; - } - } - } - - die "no program found for $fnam\n"; - } - - wait_or_not(@{$_}) for @to_open; - - return 0; -} - -sub wait_or_not -{ - my($wait, @rest) = @_; - my $pid = fork(); - - die "fork(): $!\n" unless defined $pid; - - if($pid == 0){ - if($rest[0] =~ / /){ - my $a = shift @rest; - unshift @rest, split / +/, $a; - } - - exec @rest; - die; - }else{ - # parent - if($wait){ - my $reaped = wait(); - my $ret = $?; - - die "wait(): $!\n" if $reaped == -1; - warn "unexpected dead child $reaped (expected $pid)\n" if $reaped != $pid; - - return $ret; - } - } -} - -sub edit -{ - my %h = @_; - my $e = $ENV{VISUAL} || $ENV{EDITOR} || PROG_EDIT; - return wait_or_not($h{wait}, $e, @{$h{args}}, @{$h{files}}); -} - -sub stdin_to_editor -{ - my $tmp = "/tmp/stdin_$$"; - - open F, '>', $tmp or die "open $tmp: $!\n"; - print F $_ while <STDIN>; - close F; - - my %h = @_; - push @{$h{files}}, $tmp; - my $r = edit(%h); - unlink $tmp; - return $r; -} - -sub reveal -{ - my %h = @_; - return wait_or_not($h{wait}, PROG_REVEAL, @{$h{args}}, @{$h{files}}); -} - -sub header_edit -{ - my %h = @_; - my @files = @{$h{files}}; - @{$h{files}} = (); - - for my $name (@files){ - sub find_header - { - my @inc = ("", "arpa", "net", "sys"); - my $r = shift; - my @matches; - - for(my @tmp = @inc){ - push @inc, "x86_64-linux-gnu/$_"; - } - - for my $inc (@inc){ - $inc = "/usr/include/$inc"; - - opendir D, $inc or next; - push @matches, map { "$inc/$_" } grep /$r/, readdir D; - closedir D; - } - - return @matches; - } - - my @paths = find_header($name); - push @{$h{files}}, @paths if @paths; - } - - return edit(%h); -} diff --git a/pacmans.sh b/pacmans.sh @@ -1,45 +0,0 @@ -#!/bin/sh -initializeANSI() -{ - esc="$(echo -en '\e')" - - blackf="${esc}[30m"; redf="${esc}[31m"; greenf="${esc}[32m" - yellowf="${esc}[33m" bluef="${esc}[34m"; purplef="${esc}[35m" - cyanf="${esc}[36m"; whitef="${esc}[37m" - - blackb="${esc}[40m"; redb="${esc}[41m"; greenb="${esc}[42m" - yellowb="${esc}[43m" blueb="${esc}[44m"; purpleb="${esc}[45m" - cyanb="${esc}[46m"; whiteb="${esc}[47m" - - boldon="${esc}[1m"; boldoff="${esc}[22m" - italicson="${esc}[3m"; italicsoff="${esc}[23m" - ulon="${esc}[4m"; uloff="${esc}[24m" - invon="${esc}[7m"; invoff="${esc}[27m" - - reset="${esc}[0m" -} - -# note in this first use that switching colors doesn't require a reset -# first - the new color overrides the old one. - -#clear - -initializeANSI - -cat << EOF - - ${yellowf} ▄███████▄${reset} ${redf} ▄██████▄${reset} ${greenf} ▄██████▄${reset} ${bluef} ▄██████▄${reset} ${purplef} ▄██████▄${reset} ${cyanf} ▄██████▄${reset} - ${yellowf}▄█████████▀▀${reset} ${redf}▄${whitef}█▀█${redf}██${whitef}█▀█${redf}██▄${reset} ${greenf}▄${whitef}█▀█${greenf}██${whitef}█▀█${greenf}██▄${reset} ${bluef}▄${whitef}█▀█${bluef}██${whitef}█▀█${bluef}██▄${reset} ${purplef}▄${whitef}█▀█${purplef}██${whitef}█▀█${purplef}██▄${reset} ${cyanf}▄${whitef}█▀█${cyanf}██${whitef}█▀█${cyanf}██▄${reset} - ${yellowf}███████▀${reset} ${redf}█${whitef}▄▄█${redf}██${whitef}▄▄█${redf}███${reset} ${greenf}█${whitef}▄▄█${greenf}██${whitef}▄▄█${greenf}███${reset} ${bluef}█${whitef}▄▄█${bluef}██${whitef}▄▄█${bluef}███${reset} ${purplef}█${whitef}▄▄█${purplef}██${whitef}▄▄█${purplef}███${reset} ${cyanf}█${whitef}▄▄█${cyanf}██${whitef}▄▄█${cyanf}███${reset} - ${yellowf}███████▄${reset} ${redf}████████████${reset} ${greenf}████████████${reset} ${bluef}████████████${reset} ${purplef}████████████${reset} ${cyanf}████████████${reset} - ${yellowf}▀█████████▄▄${reset} ${redf}██▀██▀▀██▀██${reset} ${greenf}██▀██▀▀██▀██${reset} ${bluef}██▀██▀▀██▀██${reset} ${purplef}██▀██▀▀██▀██${reset} ${cyanf}██▀██▀▀██▀██${reset} - ${yellowf} ▀███████▀${reset} ${redf}▀ ▀ ▀ ▀${reset} ${greenf}▀ ▀ ▀ ▀${reset} ${bluef}▀ ▀ ▀ ▀${reset} ${purplef}▀ ▀ ▀ ▀${reset} ${cyanf}▀ ▀ ▀ ▀${reset} - - ${boldon}${yellowf} ▄███████▄ ${redf} ▄██████▄ ${greenf} ▄██████▄ ${bluef} ▄██████▄ ${purplef} ▄██████▄ ${cyanf} ▄██████▄${reset} - ${boldon}${yellowf}▄█████████▀▀ ${redf}▄${whitef}█▀█${redf}██${whitef}█▀█${redf}██▄ ${greenf}▄${whitef}█▀█${greenf}██${whitef}█▀█${greenf}██▄ ${bluef}▄${whitef}█▀█${bluef}██${whitef}█▀█${bluef}██▄ ${purplef}▄${whitef}█▀█${purplef}██${whitef}█▀█${purplef}██▄ ${cyanf}▄${whitef}█▀█${cyanf}██${whitef}█▀█${cyanf}██▄${reset} - ${boldon}${yellowf}███████▀ ${redf}█${whitef}▄▄█${redf}██${whitef}▄▄█${redf}███ ${greenf}█${whitef}▄▄█${greenf}██${whitef}▄▄█${greenf}███ ${bluef}█${whitef}▄▄█${bluef}██${whitef}▄▄█${bluef}███ ${purplef}█${whitef}▄▄█${purplef}██${whitef}▄▄█${purplef}███ ${cyanf}█${whitef}▄▄█${cyanf}██${whitef}▄▄█${cyanf}███${reset} - ${boldon}${yellowf}███████▄ ${redf}████████████ ${greenf}████████████ ${bluef}████████████ ${purplef}████████████ ${cyanf}████████████${reset} - ${boldon}${yellowf}▀█████████▄▄ ${redf}██▀██▀▀██▀██ ${greenf}██▀██▀▀██▀██ ${bluef}██▀██▀▀██▀██ ${purplef}██▀██▀▀██▀██ ${cyanf}██▀██▀▀██▀██${reset} - ${boldon}${yellowf} ▀███████▀ ${redf}▀ ▀ ▀ ▀ ${greenf}▀ ▀ ▀ ▀ ${bluef}▀ ▀ ▀ ▀ ${purplef}▀ ▀ ▀ ▀ ${cyanf}▀ ▀ ▀ ▀${reset} - -EOF diff --git a/pipesx b/pipesx @@ -28,7 +28,8 @@ W=$(tput cols) H=$(tput lines) # maximal random value + 1 M=32768 -SETS=('╱╲' '/\') +#SETS=('╱╲' '/\') +SETS=('|-' '') COLORS=(31 32 33 34 35 36 37) # default values @@ -190,4 +191,4 @@ while :; do ((R)) && ((r += N, r >= R)) && r=0 && clear done -do_exit- \ No newline at end of file +do_exit diff --git a/radio b/radio @@ -0,0 +1,40 @@ +#!/bin/sh + +usage() { + cat <<EOM +usage: $(basename $0) play [number|name] + +list of radios: + 1. Radio Ondarossa + 2. Radio Mercadosul + 3. BlurFM02 + 4. Auroville + 5. 2f30 +EOM + exit 1 +} + +play() { + /usr/bin/mpv --no-video "$@" +} + +case "$1" in + 1|ondarossa) + play "http://radio.dyne.org/ondarossa.mp3.m3u" + ;; + 2|mercadosul) + play "http://radio.dyne.org/mercadosul.ogg.m3u" + ;; + 3|blurfm) + play "http://radio.dyne.org/blurfm02.m3u" + ;; + 4|auroville) + play "http://radio.dyne.org/auroville.mp3.m3u" + ;; + 5|2f30) + play "http://radio.2f30.org:8000/live.mp3" + ;; + *) + usage + ;; +esac diff --git a/skrot b/skrot @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ "$1" == "-s" ]; then - scrot -s '%Y-%m-%d_%H-%M-%S_$wx$h.png' -e 'mv $f ~/screenshots/' -else - scrot '%Y-%m-%d_%H-%M-%S_$wx$h.png' -e 'mv $f ~/screenshots/' -fi diff --git a/spark b/spark @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# +# spark +# https://github.com/holman/spark +# +# Generates sparklines for a set of data. +# +# Here's a good web-based sparkline generator that was a bit of inspiration +# for spark: +# +# https://datacollective.org/sparkblocks +# +# spark takes a comma-separated or space-separated list of data and then prints +# a sparkline out of it. +# +# Examples: +# +# spark 1 5 22 13 53 +# # => ▁▁▃▂▇ +# +# spark 0 30 55 80 33 150 +# # => ▁▂▃▅▂▇ +# +# spark -h +# # => Prints the spark help text. + +# Generates sparklines. +# +# $1 - The data we'd like to graph. +_echo() +{ + if [ "X$1" = "X-n" ]; then + shift + printf "%s" "$*" + else + printf "%s\n" "$*" + fi +} + +spark() +{ + local n numbers= + + # find min/max values + local min=0xffffffff max=0 + + for n in ${@//,/ } + do + # on Linux (or with bash4) we could use `printf %.0f $n` here to + # round the number but that doesn't work on OS X (bash3) nor does + # `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off + n=${n%.*} + (( n < min )) && min=$n + (( n > max )) && max=$n + numbers=$numbers${numbers:+ }$n + done + + # print ticks + local ticks=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █) + + # use a high tick if data is constant + (( min == max )) && ticks=(▅ ▆) + + local f=$(( (($max-$min)<<8)/(${#ticks[@]}-1) )) + (( f < 1 )) && f=1 + + for n in $numbers + do + _echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]} + done + _echo +} + +# If we're being sourced, don't worry about such things +if [ "$BASH_SOURCE" == "$0" ]; then + # Prints the help text for spark. + help() + { + local spark=$(basename $0) + cat <<EOF + + USAGE: + $spark [-h|--help] VALUE,... + + EXAMPLES: + $spark 1 5 22 13 53 + ▁▁▃▂█ + $spark 0,30,55,80,33,150 + ▁▂▃▄▂█ + echo 9 13 5 17 1 | $spark + ▄▆▂█▁ +EOF + } + + # show help for no arguments if stdin is a terminal + if { [ -z "$1" ] && [ -t 0 ] ; } || [ "$1" == '-h' ] || [ "$1" == '--help' ] + then + help + exit 0 + fi + + spark ${@:-`cat`} +fi diff --git a/spin b/spin @@ -0,0 +1,8 @@ +#!/bin/sh + +while true; do + printf " |" + printf " /" + printf " -" + printf " \\" +done diff --git a/surf.sh b/surf.sh @@ -0,0 +1,141 @@ +#!/bin/sh +# v. 2.0 - upgrade based on surf 4.0 +# Creative Commons License. Peter John Hartman (http://individual.utoronto.ca/peterjh) +# Much thanks to nibble and pancake who have a different surf.sh script available which +# doesn't do the history bit. +# +# this script does: +# * stores history of: (1) successful uri entries; (2) certain smart prefix entries, e.g., "g foobar"; (3) find entries +# * direct bookmark (via ^b) +# * information debug (via ^I) +# * smart prefixes e.g. g for google search, t for tinyurl, etc. +# * delete (with smart prefix x) +# +# $1 = $xid +# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI (what SETPROP sets in config.h) +# +# // replace default setprop with this one +# #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $0 $1 $2", p, q, winid, NULL } } +# +# { MODKEY, GDK_b, spawn, SETPROP("_SURF_BMARK") }, +# { MODKEY|GDK_SHIFT_MASK, GDK_i, spawn, SETPROP("_SURF_INFO") }, +# { MODKEY|GDK_SHIFT_MASK, GDK_g, spawn, SETPROP("_SURF_URI_RAW") }, + +#font='-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*' +font='Terminus:pixelsize=14' +normbgcolor='#181818' +normfgcolor='#e9e9e9' +selbgcolor=$normbgcolor +selfgcolor='#dd6003' +bmarks=~/.surf/history.txt +ffile=~/.surf/find.txt + +pid=$1 +fid=$2 +xid=$3 + +dmenu="dmenu -nb $normbgcolor -nf $normfgcolor \ + -sb $selbgcolor -sf $selfgcolor" + +s_get_prop() { # xprop + xprop -id $xid $1 | cut -d '"' -f 2 +} + +s_set_prop() { # xprop value + [ -n "$2" ] && xprop -id $xid -f $1 8s -set $1 "$2" +} + +s_write_f() { # file value + [ -n "$2" ] && (sed -i "\|$2|d" $1; echo "$2" >> $1) + #grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $bmarks +} + +s_set_write_proper_uri() { # uri + # TODO: (xprop -spy _SURF_URI ... | while read name __ value; do echo $value; done works quite nice for eventloops) + # input is whatever the use inputed, so don't store that! + # first, clear the name field because surf doesn't sometimes + #s_set_prop WM_ICON_NAME "" + # set the uri + s_set_prop _SURF_GO "$1" + # get the new name + name=`s_get_prop WM_ICON_NAME` + # loop until the [10%] stuff is finished and we have a load (is this necessary?) + #while echo $name | grep "[*%\]" >/dev/null 2>&1; do + # name=`s_get_prop WM_ICON_NAME` + #done + # bail on error and don't store + #if [[ $name != "Error" ]]; then + # uri=`s_get_prop _SURF_URI` + # store to the bmarks file the OFFICIAL url (with http://whatever) + s_write_f $bmarks "$1" + #grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $bmarks + #fi +} + +case "$pid" in +"_SURF_INFO") + xprop -id $xid | sed 's/\t/ /g' | $dmenu -fn "$font" -b -l 20 + ;; +"_SURF_FIND") + find="`tac $ffile 2>/dev/null | $dmenu -fn "$font" -b -p find:`" + s_set_prop _SURF_FIND "$find" + s_write_f $ffile "$find" + ;; +"_SURF_BMARK") + uri=`s_get_prop _SURF_URI` + s_write_f $bmarks "$uri" + ;; +"_SURF_URI_RAW") + uri=`echo $(s_get_prop _SURF_URI) | $dmenu -fn "$font" -b -p "uri:"` + s_set_prop _SURF_GO "$uri" + ;; +"_SURF_URI") + sel=`tac $bmarks 2> /dev/null | $dmenu -fn "$font" -b -l 5 -p "uri [dgtwuy*]:"` + [ -z "$sel" ] && exit + opt=$(echo $sel | cut -d ' ' -f 1) + arg=$(echo $sel | cut -d ' ' -f 2-) + save=0 + case "$opt" in + "d") # del.icio.us + uri="http://del.icio.us/save?url=`s_get_prop _SURF_URI`" + ;; + "g") # google for it + uri="http://www.google.com/search?q=$arg" + save=1 + ;; + "t") # tinyurl + uri="http://tinyurl.com/create.php?url=`s_get_prop _SURF_URI`" + ;; + "w") # wikipedia + uri="http://wikipedia.org/wiki/$arg" + save=1 + ;; + "u") # utoronto + uri="http://search2.library.utoronto.ca/UTL/index?N=0&Ntk=Anywhere&Ntt=$arg&Ntx=mode%2Bmatchallpartial&Nu=p_work_normalized&Np=1&formName=search_form_simple" + save=1 + ;; + "y") # youtube + uri="http://www.youtube.com/results?search_query=$arg&aq=f" + save=1 + ;; + "x") # delete + sed -i "\|$arg|d" $bmarks + exit; + ;; + *) + uri="$sel" + save=2 + ;; + esac + + # only set the uri; don't write to file + [ $save -eq 0 ] && s_set_prop _SURF_GO "$uri" + # set the url and write exactly what the user inputed to the file + [ $save -eq 1 ] && (s_set_prop _SURF_GO "$uri"; s_write_f $bmarks "$sel") + # try to set the uri only if it is a success + [ $save -eq 2 ] && s_set_write_proper_uri "$uri" + ;; +*) + echo Unknown xprop + ;; +esac diff --git a/update-gits b/update-gits @@ -0,0 +1,10 @@ +#!/bin/sh + +for i in $(printf %s\\n */); do + cd "$i" + test -d .git && { + printf "\nupdating %s...\\n" "$i" + git pull origin master + } + cd - >/dev/null +done diff --git a/volume b/volume @@ -35,5 +35,6 @@ case $1 in up|+) amixer set $CHANNEL 5%+ >/dev/null;; down|-) amixer set $CHANNEL 5%- >/dev/null;; toggle|!) amixer set $CHANNEL toggle >/dev/null;; + X) amixer set Capture toggle >/dev/null;; *) amixer set $CHANNEL $1 >/dev/null;; esac diff --git a/wifi2qr b/wifi2qr @@ -0,0 +1,18 @@ +#!/bin/sh + +usage() { + printf "usage: %s [essid] [passphrase]\\n" "$(basename $0)" + exit 1 +} + +test -n "$1" || usage + +test -n "$2" || { + qrencode -s 13 -o qr-wifi.png "WIFI:S:${1};T:nopass;;" + printf "qr saved to qr-wifi.png\\n" + exit 0 +} + +qrencode -s 13 -o qr-wifi.png "WIFI:S:${1};T:WPA;P:${2};;" +printf "qr saved to qr-wifi.png\\n" +exit 0 diff --git a/xurls b/xurls @@ -1,115 +1,3 @@ -#!/usr/bin/perl +#!/bin/sh -use warnings; - -$hostchars = '[a-z0-9-._+]'; -$pathchars = '[a-z0-9-._+#=?&:;%/!,~]'; - -sub scan($$$) -{ - my ($file, $lineno, $line) = @_; - - chomp $line; - - while($line =~ s! - ([a-z]+://)? - -# http:// - - $hostchars+\.[a-z]+/ - -# www.tim.google.com/ - the [a-z].com is the main anchor for the whole regex - incase http:// is omitted - - ($pathchars+/\?)* - -# check for the index.php? part - - ($pathchars+|\($pathchars+\))* - -# check for pathchars, or a set of nested parens - !!xoi){ # allow space + comments, compile once, strcasecmp - - my($p,$m,$e) = ($`,$&,$'); - - $e = '.' . $e if $m =~ s/\.$//; - - if($opt{fname} && $file){ - print "$col{red}$file$col{none}:"; - } - - if($opt{lineno}){ - print "$col{green}$lineno$col{none}: "; - }elsif($opt{fname} && $file){ - print ' '; - } - - if($opt{hl}){ - print "$p$col{brown}$m$col{none}$e\n"; - }else{ - print "$m\n"; - } - } -} - -sub usage(){ - $printme =<<"!"; -Usage: $0 -[Chn] [FILES...] - -h: highlight - -c: force colour on (for pipes) - -C: colour off (only makes sense with -h) - -n: show line number -! - print STDERR $printme; - exit 1; -} - - -%opt = ( - colour => 1, - lineno => 0, - fname => 0, - hl => 0 -); -%col = ( - brown => "\e[0;31m", # hl - red => "\e[0;35m", # fname - green => "\e[0;32m", # lineno - none => "\e[0;0m" -); - -for $arg (@ARGV){ - if($arg eq '-h'){ - $opt{hl} = 1; - }elsif($arg eq '-n'){ - $opt{lineno} = 1; - }elsif($arg eq '-C'){ - $opt{colour} = 0; - }elsif($arg eq '-c'){ - usage() if $opt{colour} == 0; - $opt{colour} = 2; # force on - }elsif($arg eq '--help'){ - usage(); - }else{ - push @files, $arg; - } -} - -usage() if $opt{hl} && !$opt{colour}; - -$opt{fname} = 1 if $#files > 0 || $opt{lineno}; -if(!$opt{colour} || ($opt{colour} == 1 && !-t STDOUT)){ - $col{$_} = '' for keys %col; -} - -$| = 1; - -if(@files){ - for my $f (@files){ - my $n = 1; - open F, '<', $f or warn "$f: $!\n"; - scan($f, $n++, $_) for <F>; - close F; - } -}else{ - scan(undef, $., $_) while <STDIN>; -} +grep -E -o 'https?://[^ ]+' diff --git a/xurls b/xurls.pl diff --git a/ydl b/ydl @@ -3,7 +3,7 @@ # download the audio track of the first result of a youtube search # and add it to MPD library (will end up with a .mp3, for tags) -MPD_DOWNLOAD_DIR=~/usr/msc/youtube/ +MPD_DOWNLOAD_DIR=$PWD usage() { echo "`basename $0` [-h] <query>" diff --git a/yt b/yt @@ -0,0 +1,5 @@ +#!/bin/sh + +url="$1" + +mpv --ytdl-format=best "$1"