-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_fns
93 lines (77 loc) · 2.45 KB
/
.bash_fns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
## coding analysis
function lines_coded {
perl -ne'print unless /^\s*$/ || /^\s*(?:#|\/\*|\*)/' $* | wl
}
function lines_commented {
perl -ne'print if /^\s*(?:#|\/\*|\*)/' $* | wl
}
## get all SVN commits after a certain date by a certain user
## e.g. $ svn_date_user 2013-01-31 jmcguire
svn_date_user () {
svn log -v -r{$1}:HEAD | sed -n "/$2/,/-----\$/ p"
}
## get breakpoints from a CSS file
## e.g. $ get_css_breakpoints time.css
get_css_breakpoints () {
grep ^@media $1 \
| perl -pe's/\@media screen and \(([^)]+)\) {/$1/' \
| perl -pe's/^\@media(?: (?:only )?screen and )?//;
s/,\s*/\n/g;
s/only screen and//g;
s/^\s+//mg;
s/ {\s*$/\n/mg;' \
| sort -u
}
## add a blank space to the Mac OSX Dock
add_spacer_to_dock () {
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
killall Dock
}
## see the structure of a json file
## e.g. $ json_structure input.json
## (delete this because I just use JQ now?)
json_structure() {
perl -ne'if(/^[\W_]+$/ or /"\w+" \s* : \s* [\[{]/x){ print }' $1
}
## see the module and function of perl code in a directory
## e.g. $ perl_dir_structure
function perl_dir_structure {
find . -name "*_Test.pm" -prune -o -type f -print0 \
| xargs -0 perl -nle'
BEGIN{ $last_p = undef}
$last_p = undef if eof;
($p) = /^package (.+);/;
$last_p = $p if $p;
($s) = /^sub (\w+)\b/;
next unless $s;
$all{$last_p}{$s}++;
END{ for $p (keys %all) { print "\n$p"; print "\t$_" foreach keys %{$all{$p}} }}'
}
function tailgrep {
tailf $1 | grep --line-buffered "$2"
}
function v {
wl $1
l $1
head $1
}
function perl_sub_size {
for sub in $(grep ^sub $1 | cut -d\ -f2); do len=`perl_get_sub $sub $1 | wl`; printf "%d %s:%s\n" $len $1 $sub; done
}
# given a file with categories and tabbed-in items in those categories, count the number of items in each category
function count_categories {
perl -nE'if($seq = /^\w/ .. /^$/) { if ($seq == 1){ $total=0; print } elsif ($seq =~ /E/){say $total} else {$total++} }' $1
}
# usage: perl_ppi_dump <perlfile>
function perl_ppi_dump {
perl -MAthena::Lib -MPPI::Document -MPPI::Dumper -E'$m = PPI::Document->new($ARGV[0]); $d = PPI::Dumper->new($m); $d->print' $1
}
function mkc {
mkdir $1 && cd "$_"
}
# settitle "window terminal title"
settitle()
{
printf "\e]2;$*\a\e]1;$*\a\e]0;$*\a";
}