-
Notifications
You must be signed in to change notification settings - Fork 1
/
.functions
executable file
·165 lines (146 loc) · 4.29 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
# -*- mode: sh -*-
# globbing support when pulling files from smartphone with adb
function adbpull {
local source="$1"
if [ -z "$source" -o -n "$2" ]; then
echo "Usage: adbpull <source>"
echo
echo " Example: adbpull '/sdcard/DCIM/Camera/*.jpg'"
echo " Note that single quotes are important for globbing to work."
echo
echo " Use adb shell to navigate the phone's filesystem."
echo
echo " Files will be copied into the current directory."
else
adb shell ls "$source" | tr '\r' ' ' | xargs -n1 adb pull
fi
}
# transform a .cbr file into .cbz
function cbr2cbz() {
if [ -z "$1" ]; then
echo "Usage: cbr2cbz file.cbr"
exit 0
fi
unar -d "$1"
base=$(basename "$1" .cbr)
zip -9r "$base".cbz "$base"
rm -r "$base"
}
# Run deno in a Docker container
# https://hub.docker.com/r/denoland/deno
deno () {
docker run \
--interactive \
--tty \
--rm \
--volume $PWD:/app \
--volume $HOME/.deno:/deno-dir \
--workdir /app \
denoland/deno:latest \
"$@"
}
# install packages for go development
function gosetup() {
go get -u golang.org/x/tools/cmd/...
go get -u github.com/rogpeppe/godef
go get -u github.com/zmb3/gogetdoc
go get -u github.com/mdempsky/gocode
go get -u github.com/godoctor/godoctor
}
# create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# transform MTS files to MKV by copying video and audio
function mts2mkv() {
local MTS_FILE="$1"
shopt -s extglob
local MKV_FILE="${MTS_FILE%.@(mts|MTS)}.mkv"
echo
echo "### Remuxing $MTS_FILE into $MKV_FILE ###"
echo
ffmpeg -i "$MTS_FILE" -vcodec copy -acodec copy "$MKV_FILE"
}
# Get a shell inside a Docker container with NodeJS
#
# Current directory will be mounted in /app
#
# Will create a nodehome Docker volume if it doesn't exist, and map it to /home/node
# inside the Docker container. This enables persisting globally installed npm packages.
function nds() {
docker volume create nodehome > /dev/null
docker run\
-it\
--rm\
--user=node\
--mount source=nodehome,target=/home/node\
-v "$(pwd)":/app:rw\
--workdir /app\
--entrypoint=/bin/bash\
--network host\
$@\
node:18-bullseye
}
# extract images from a PDF file, needs poppler-utils package
function pdfextractimages() {
local PDF_FILE="$1";
# extract JPEG and PNG images
pdfimages -j -png "$PDF_FILE" ./;
# remove bad prefix (-) from images
# TODO: use standard shell tools instead of mmv
mmv "\-*" "#1";
}
# Transform a PDF into a CBZ comic file
# Required packages: poppler-utils
function pdf2cbz() {
local PDF_FILE="$1";
local CBZ_FILE=$(basename "$PDF_FILE" .pdf).cbz;
if [ ! -f "$PDF_FILE" ]; then
echo "$PDF_FILE doesn't exist, aborting"
return 1
fi
# extract images from PDF
pdfextractimages "$PDF_FILE";
# create CBZ comic file and delete the images
zip -9m "$CBZ_FILE" *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG;
# remove original PDF file, prompting user first
rm -i "$PDF_FILE";
}
# Split a FLAC using a CUE file and tag the splitted tracks
# Required packages: flac, shntool, cuetools
#
# For example when having two files like "Album Name.cue" and "Album Name.flac"
# call it like this:
#
# $ splitflac "Album Name"
function splitflac() {
if [ -z "$1" ]; then
echo "Usage: splitflac <basename>"
echo
echo "<basename> must be the common part to a pair of .cue and .flac pairs,"
echo "without the dot."
return 0
fi
local CUETAG=$(which cuetag cuetag.sh)
local BASE="$1"
local CUE="$BASE.cue"
local FLAC="$BASE.flac"
if [ ! -f "$CUE" ]; then
echo "$CUE doesn't exist"
return 1
fi
if [ ! -f "$FLAC" ]; then
echo "$FLAC doesn't exist"
return 1
fi
shnsplit -f "$CUE" -o flac "$FLAC" && $CUETAG "$CUE" split-track*
}
# start/stop KVM Whonix
# https://www.whonix.org/wiki/KVM
function whonixup() {
virsh start Whonix-Gateway && virsh start Whonix-Workstation
}
function whonixdown() {
virsh stop Whonix-Workstation
virsh stop Whonix-Gateway
}