diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-10-20 03:45:52 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-10-20 03:50:24 -0400 |
commit | a037f1227765630a7f01c75515117e1511157f7c (patch) | |
tree | c0ab82126382879f3d5f3f12c85f3afe1b89216c /bin | |
parent | c6e0a22476f2a3ae9e2994f8b0f8e470c82eaadb (diff) | |
download | conf-a037f1227765630a7f01c75515117e1511157f7c.tar.gz conf-a037f1227765630a7f01c75515117e1511157f7c.zip |
more random config cleanups
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/all-mail | 3 | ||||
-rwxr-xr-x | bin/combine_csv | 27 | ||||
-rwxr-xr-x | bin/devnull | 6 | ||||
-rwxr-xr-x | bin/diff-highlight | 218 | ||||
-rwxr-xr-x | bin/explode_csv | 46 | ||||
-rwxr-xr-x | bin/get_ip | 16 | ||||
-rwxr-xr-x | bin/mp3q | 75 | ||||
-rwxr-xr-x | bin/on_lock | 2 | ||||
-rwxr-xr-x | bin/pwsafe2pass | 41 | ||||
-rwxr-xr-x | bin/rusti | 11 | ||||
-rwxr-xr-x | bin/screenshot | 20 |
11 files changed, 0 insertions, 465 deletions
diff --git a/bin/all-mail b/bin/all-mail deleted file mode 100755 index 5a9c1a8..0000000 --- a/bin/all-mail +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -find $HOME/Maildir -type d -name new -not -empty | sed "s+^$HOME/Maildir/++" | sed 's+/new$++' | sort diff --git a/bin/combine_csv b/bin/combine_csv deleted file mode 100755 index f17db89..0000000 --- a/bin/combine_csv +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Path::Class; -use Spreadsheet::WriteExcel; -use Text::CSV; - -my @csv_files = map { file($_) } @ARGV; - -my $ss = Spreadsheet::WriteExcel->new('combined.xls'); - -for my $csv_file (@csv_files) { - my $name = $csv_file->stringify; - $name =~ s/\.csv$//; - my $ws = $ss->add_worksheet($name); - - my $parser = Text::CSV->new; - my $fh = $csv_file->openr; - my $row_num = 1; - while (my $row = $parser->getline($fh)) { - for my $col_num (0..$#$row) { - $ws->write($row_num, $col_num, $row->[$col_num]); - } - $row_num++; - } -} diff --git a/bin/devnull b/bin/devnull deleted file mode 100755 index 11bbfbd..0000000 --- a/bin/devnull +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -ttrtail doy > /dev/null 2>&1 & -pid=$! -ttyrec $(date +%Y-%m-%d-%H%M%S.ttyrec) -e "ssh nethack.kraln.com" -kill $pid > /dev/null 2>&1 diff --git a/bin/diff-highlight b/bin/diff-highlight deleted file mode 100755 index ffefc31..0000000 --- a/bin/diff-highlight +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/perl - -use 5.008; -use warnings FATAL => 'all'; -use strict; - -# Highlight by reversing foreground and background. You could do -# other things like bold or underline if you prefer. -my @OLD_HIGHLIGHT = ( - color_config('color.diff-highlight.oldnormal'), - color_config('color.diff-highlight.oldhighlight', "\x1b[7m"), - color_config('color.diff-highlight.oldreset', "\x1b[27m") -); -my @NEW_HIGHLIGHT = ( - color_config('color.diff-highlight.newnormal', $OLD_HIGHLIGHT[0]), - color_config('color.diff-highlight.newhighlight', $OLD_HIGHLIGHT[1]), - color_config('color.diff-highlight.newreset', $OLD_HIGHLIGHT[2]) -); - -my $RESET = "\x1b[m"; -my $COLOR = qr/\x1b\[[0-9;]*m/; -my $BORING = qr/$COLOR|\s/; - -my @removed; -my @added; -my $in_hunk; - -# Some scripts may not realize that SIGPIPE is being ignored when launching the -# pager--for instance scripts written in Python. -$SIG{PIPE} = 'DEFAULT'; - -while (<>) { - if (!$in_hunk) { - print; - $in_hunk = /^$COLOR*\@/; - } - elsif (/^$COLOR*-/) { - push @removed, $_; - } - elsif (/^$COLOR*\+/) { - push @added, $_; - } - else { - show_hunk(\@removed, \@added); - @removed = (); - @added = (); - - print; - $in_hunk = /^$COLOR*[\@ ]/; - } - - # Most of the time there is enough output to keep things streaming, - # but for something like "git log -Sfoo", you can get one early - # commit and then many seconds of nothing. We want to show - # that one commit as soon as possible. - # - # Since we can receive arbitrary input, there's no optimal - # place to flush. Flushing on a blank line is a heuristic that - # happens to match git-log output. - if (!length) { - local $| = 1; - } -} - -# Flush any queued hunk (this can happen when there is no trailing context in -# the final diff of the input). -show_hunk(\@removed, \@added); - -exit 0; - -# Ideally we would feed the default as a human-readable color to -# git-config as the fallback value. But diff-highlight does -# not otherwise depend on git at all, and there are reports -# of it being used in other settings. Let's handle our own -# fallback, which means we will work even if git can't be run. -sub color_config { - my ($key, $default) = @_; - my $s = `git config --get-color $key 2>/dev/null`; - return length($s) ? $s : $default; -} - -sub show_hunk { - my ($a, $b) = @_; - - # If one side is empty, then there is nothing to compare or highlight. - if (!@$a || !@$b) { - print @$a, @$b; - return; - } - - # If we have mismatched numbers of lines on each side, we could try to - # be clever and match up similar lines. But for now we are simple and - # stupid, and only handle multi-line hunks that remove and add the same - # number of lines. - if (@$a != @$b) { - print @$a, @$b; - return; - } - - my @queue; - for (my $i = 0; $i < @$a; $i++) { - my ($rm, $add) = highlight_pair($a->[$i], $b->[$i]); - print $rm; - push @queue, $add; - } - print @queue; -} - -sub highlight_pair { - my @a = split_line(shift); - my @b = split_line(shift); - - # Find common prefix, taking care to skip any ansi - # color codes. - my $seen_plusminus; - my ($pa, $pb) = (0, 0); - while ($pa < @a && $pb < @b) { - if ($a[$pa] =~ /$COLOR/) { - $pa++; - } - elsif ($b[$pb] =~ /$COLOR/) { - $pb++; - } - elsif ($a[$pa] eq $b[$pb]) { - $pa++; - $pb++; - } - elsif (!$seen_plusminus && $a[$pa] eq '-' && $b[$pb] eq '+') { - $seen_plusminus = 1; - $pa++; - $pb++; - } - else { - last; - } - } - - # Find common suffix, ignoring colors. - my ($sa, $sb) = ($#a, $#b); - while ($sa >= $pa && $sb >= $pb) { - if ($a[$sa] =~ /$COLOR/) { - $sa--; - } - elsif ($b[$sb] =~ /$COLOR/) { - $sb--; - } - elsif ($a[$sa] eq $b[$sb]) { - $sa--; - $sb--; - } - else { - last; - } - } - - if (is_pair_interesting(\@a, $pa, $sa, \@b, $pb, $sb)) { - return highlight_line(\@a, $pa, $sa, \@OLD_HIGHLIGHT), - highlight_line(\@b, $pb, $sb, \@NEW_HIGHLIGHT); - } - else { - return join('', @a), - join('', @b); - } -} - -sub split_line { - local $_ = shift; - return utf8::decode($_) ? - map { utf8::encode($_); $_ } - map { /$COLOR/ ? $_ : (split //) } - split /($COLOR+)/ : - map { /$COLOR/ ? $_ : (split //) } - split /($COLOR+)/; -} - -sub highlight_line { - my ($line, $prefix, $suffix, $theme) = @_; - - my $start = join('', @{$line}[0..($prefix-1)]); - my $mid = join('', @{$line}[$prefix..$suffix]); - my $end = join('', @{$line}[($suffix+1)..$#$line]); - - # If we have a "normal" color specified, then take over the whole line. - # Otherwise, we try to just manipulate the highlighted bits. - if (defined $theme->[0]) { - s/$COLOR//g for ($start, $mid, $end); - chomp $end; - return join('', - $theme->[0], $start, $RESET, - $theme->[1], $mid, $RESET, - $theme->[0], $end, $RESET, - "\n" - ); - } else { - return join('', - $start, - $theme->[1], $mid, $theme->[2], - $end - ); - } -} - -# Pairs are interesting to highlight only if we are going to end up -# highlighting a subset (i.e., not the whole line). Otherwise, the highlighting -# is just useless noise. We can detect this by finding either a matching prefix -# or suffix (disregarding boring bits like whitespace and colorization). -sub is_pair_interesting { - my ($a, $pa, $sa, $b, $pb, $sb) = @_; - my $prefix_a = join('', @$a[0..($pa-1)]); - my $prefix_b = join('', @$b[0..($pb-1)]); - my $suffix_a = join('', @$a[($sa+1)..$#$a]); - my $suffix_b = join('', @$b[($sb+1)..$#$b]); - - return $prefix_a !~ /^$COLOR*-$BORING*$/ || - $prefix_b !~ /^$COLOR*\+$BORING*$/ || - $suffix_a !~ /^$BORING*$/ || - $suffix_b !~ /^$BORING*$/; -} diff --git a/bin/explode_csv b/bin/explode_csv deleted file mode 100755 index 8f50ebc..0000000 --- a/bin/explode_csv +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Module::Runtime qw< require_module >; -use Text::CSV; - -my $filename = $ARGV[0]; -my $parser_class = $filename =~ /\.xlsx$/ - ? "Spreadsheet::ParseXLSX" - : "Spreadsheet::ParseExcel"; - -require_module($parser_class); - -my $parser = $parser_class->new; -my $wb = $parser->parse($filename) || die $parser->error; - -(my $dir = $filename) =~ s/\.[^.]*$//; -mkdir $dir; -chdir $dir; - -for my $ws ($wb->worksheets) { - my $csv = Text::CSV->new({ binary => 1, eol => "\n" }); - my $filename = $ws->get_name . '.csv'; - open my $fh, '>:encoding(UTF-8)', $filename - or die "Couldn't open $filename: $!"; - - my ($rmin, $rmax) = $ws->row_range; - my ($cmin, $cmax) = $ws->col_range; - - for my $row (0..$rmin - 1) { - $csv->print($fh, [ ('') x ($cmax + 1) ]); - } - - for my $row ($rmin..$rmax) { - my @row = (('') x $cmin); - for my $col ($cmin..$cmax) { - my $cell = $ws->get_cell($row, $col); - push @row, $cell ? $cell->value : ''; - } - $csv->print($fh, \@row); - } - - close $fh - or die "Couldn't close $filename: $!"; -} diff --git a/bin/get_ip b/bin/get_ip deleted file mode 100755 index 879e0cd..0000000 --- a/bin/get_ip +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl - -my $page = "http://www.lawrencegoetz.com/programs/ipinfo/"; - -open my $site, "wget -qO- $page|" or die "Could not get web page"; - -my $next_line_is_ip = 0; -while (<$site>) { - s/[\r\n]+$//; - if ($next_line_is_ip == 1) { - s/ //g; - print $_, "\n"; - last; - } - $next_line_is_ip = 1 if /Your IP address is/; -} diff --git a/bin/mp3q b/bin/mp3q deleted file mode 100755 index 17831b8..0000000 --- a/bin/mp3q +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use File::Next; -use File::Basename; -use MP3::Info; -use MP4::Info; -use Ogg::Vorbis::Header::PurePerl; - -sub color { - my ($bitrate) = @_; - $bitrate ||= 0; - if ($bitrate >= 192) { - return "1;32"; - } - elsif ($bitrate >= 160) { - return "32"; - } - elsif ($bitrate >= 128) { - return "33"; - } - elsif ($bitrate >= 96) { - return "31"; - } - elsif ($bitrate == 0) { - return "1;30"; - } - else { - return "37;41"; - } -} - -sub bitrate { - my ($file) = @_; - if ($file =~ /\.mp3$/i) { - return MP3::Info->new($file)->bitrate; - } - elsif ($file =~ /\.m4a$/i) { - return MP4::Info->new($file)->bitrate; - } - elsif ($file =~ /\.ogg$/i) { - return Ogg::Vorbis::Header::PurePerl->new($file)->info->{bitrate_nominal} / 1000.0; - } - elsif ($file =~ /\.(?:m4p|jpg|ini|db|exe|wma|nfo|m3u|zip|m4v|txt|DS_Store|mpe?g|mov|cue|ncd|xml|rar|png)$/i) { - return 0; - } - elsif ($file =~ /\.(?:wav|flac)$/i) { - return 1440; - } - elsif ($file !~ /\./) { - return 0; - } - else { - die "unknown file type: $file"; - } -} - -my @dirs = @ARGV; -push @dirs, '.' unless @dirs; - -my $files = File::Next::files({sort_files => 1}, @dirs); - -#mkdir 'unnecessary'; - -while (defined (my $file = $files->())) { - my $bitrate = bitrate($file); - print "\e[", color($bitrate), "m"; - print "$file: $bitrate"; - print "\e[m\n"; - if ($bitrate < 96) { - my $new_name = fileparse $file; - $new_name = 'unnecessary/'.$new_name; - #rename $file, $new_name; - } -} diff --git a/bin/on_lock b/bin/on_lock index 3eafe2c..a0bb411 100755 --- a/bin/on_lock +++ b/bin/on_lock @@ -1,5 +1,3 @@ #!/bin/bash sudo -k -keychain -k mine -keybase logout diff --git a/bin/pwsafe2pass b/bin/pwsafe2pass deleted file mode 100755 index fa7b634..0000000 --- a/bin/pwsafe2pass +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -# run as pwsafe --exportdb | pwsafe2pass -# requires an already initialized pass database - -# headers -readline; -readline; - -while (my $line = <>) { - chomp $line; - my ($uuid, $group, $name, $login, $passwd, $notes) = map { - s/^"(.*)"$/$1/; - - # sigh - s/\\\\/\\/g; - s/>/>/g; # not a typo, they really forgot the ; - s/</</g; - s/&/\&/g; - - $_ - } split /\t/, $line; - - # XXX pass doesn't handle filenames with spaces properly - s/\s/-/g for $group, $name; - die "pass can't handle files with spaces" if $login =~ /\s/; - - my $entry = join '/', $group, $name, length($login) ? ($login) : (); - - open my $fh, '|-', 'pass', 'insert', ($notes ? ('-m') : ('-e')), $entry - or die "Couldn't insert!"; - $fh->print("$passwd\n"); - $fh->print("$notes\n") if $notes; - $fh->close; - - # XXX pass doesn't propagate git failure exit codes to the overall process, - # so failures in 'git add' or whatever will fail silently - die "Failed to insert $entry: $?" if $?; -} diff --git a/bin/rusti b/bin/rusti deleted file mode 100755 index 9111d0f..0000000 --- a/bin/rusti +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -set -e - -RUSTI_TEMP=$(mktemp -d) -trap "rm -f $RUSTI_TEMP/test $RUSTI_TEMP/test.rs && rmdir $RUSTI_TEMP" EXIT - -cd $RUSTI_TEMP -vim test.rs -rustc test.rs -./test diff --git a/bin/screenshot b/bin/screenshot deleted file mode 100755 index 2471bc8..0000000 --- a/bin/screenshot +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use 5.010; - -use Clipboard; -use File::Temp 'tempfile'; - -my $file = File::Temp->new(SUFFIX => '.png', CLEANUP => 1); -my $filename = $file->filename; - -system( - "import", - (@ARGV && ($ARGV[0] eq '--full') ? (qw(-window root)) : ()), - $filename, -); - -chomp(my $url = `nopaste $filename`); -Clipboard->copy($url); -say $url; |