-
Notifications
You must be signed in to change notification settings - Fork 1
/
.functions
169 lines (148 loc) · 3.18 KB
/
.functions
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh
# Convert to lowercase.
lc() { tr A-Z a-z }
# Convert to uppercase.
uc() { tr a-z A-Z }
# Operate on the body of a file but not the header
body() {
IFS= read -r header
printf '%s\n' "$header"
eval $@
}
# Sort rust use statements.
cargo-fmt-sort-use()
{
cargo fmt -- --config=group_imports=One,imports_granularity=Module "$@"
}
# Remove unused docker images
docker-cleanup-images()
{
docker rmi `docker images --filter dangling=true --quiet`
}
# Remove unused docker containers and images
docker-cleanup()
{
docker rm `docker ps -aq`
docker-cleanup-images
}
# Move the specified files to a newly-created directory
stash()
{
t=`gdate +'%Y-%m-%dT%H:%M'`
mkdir $t && mv "$@" $t/ && echo $t || rmdir $t
}
# Remove duplicate elements
unique()
{
awk '!x[$0]++' "$@"
}
# Add Homebrew kegs to the PATH
require()
{
cellar=`brew --cellar`
for i; do
case $i in
*/*)
bin=$cellar/$i/bin
;;
*)
keg=`brew --prefix $i`
bin=`realpath $keg`/bin
;;
esac
if [ -r $bin ]; then
PATH=$bin:$PATH
fi
done
}
# Wrangle data with dplyr and tidyr
# This prototype does not work well. I often use datamash.
dplyr()
{
Rscript \
-e 'library(dplyr, warn.conflicts = FALSE)' \
-e 'library(tidyr, warn.conflicts = FALSE)' \
-e 'args <- commandArgs(trailingOnly = TRUE)' \
-e 'f <- args[1]' \
-e 'args <- as.list(args[-1])' \
-e 'data <- read.delim(file("stdin"))' \
-e 'output <- do.call(f, c(list(data), args))' \
-e 'write.table(output, sep = "\\t", quote = FALSE, row.names = FALSE)' \
"$@"
}
# Convert a DOI to a text citation.
cite()
{
for i; do curl -LH "Accept: text/bibliography" "http://doi.org/$i"; done
}
# Convert a DOI to bibtex.
bib()
{
for i; do curl -sLH "Accept: text/bibliography; style=bibtex" "http://doi.org/$i" | sed 's/^ *//'; done
}
# Add a DOI to bibtex.
bib-add()
{
bibfile = $1
shift
(cat "$bibfile"; bib "$@") | sort -u -o "$bibfile"
}
# Add a DOI to references.
add-doi()
{
doifile=$1
bibfile=$1.bib
shift
for i; do
echo "$i" >>$doifile
brew cite "$i" >>$bibfile
done
sort -u $doifile -o $doifile
sort -u $bibfile -o $bibfile
}
# Convert arXiv to bibtex.
arxiv()
{
for i; do curl -s "https://arxiv2bibtex.org/?outputformat=raw&q=$i" | paste -sd' ' - | sed 's/}, }/}}/'; done
}
# Daff a TSV/CSV file and open it in a browser
daff-render()
{
daff $1 $2 >! $1-$2
daff render --output $1-$2.html $1-$2
open $1-$2.html
}
# Create a Bintray package for Linuxbrew
linuxbrew-create-package()
{
curl -u$BINTRAY_USER:$BINTRAY_KEY \
-H 'Content-Type: application/json' \
-d '{"name":"'$2'", "licenses":["BSD 2-Clause"], "vcs_url":"https://github.com/Linuxbrew/linuxbrew.git", "public_download_numbers":true, "public_stats":true}' \
"https://api.bintray.com/packages/linuxbrew/$1"
}
# Upload a file to Bintray for Linuxbrew
linuxbrew-upload()
{
curl -u$BINTRAY_USER:$BINTRAY_KEY \
-T $4 "https://api.bintray.com/content/linuxbrew/$1/$2/$3/$4?publish=1"
}
# git: Add a file
git-add()
{
for i; do
git add "$i"
git commit "$i" -m "Add $i"
done
}
# git: Fixup a file
git-fixup()
{
for i; do
git commit "$i" -m "fixup $i"
done
}
# Reverse complement nucleotide sequences.
rc()
{
awk '{print ">" NR "\n" $0}' | seqtk seq -r | grep -v '^>'
}