-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path60-functions
162 lines (138 loc) · 3.53 KB
/
60-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
# ls for Directories.
function lsd
{
ls -1F $* | grep '/$'
}
# ls for files - or at least non-directories
function lsf
{
ls -l $* | grep -E -v '^(d|total)' | awk '{print $NF}'
}
#
# ssh + scp without storing or prompting for keys.
#
function sshtmp
{
ssh -o "ConnectTimeout 3" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
"$@"
}
function scptmp
{
exec scp -o "ConnectTimeout 3" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
"$@"
}
#
# If we have completion function for ssh then use it for those too.
#
if [ "$(type -t _ssh)x" = "functionx" ]; then
complete -F _ssh sshtmp
complete -F _ssh scptmp
fi
#
# Extract named archive(s).
#
x ()
{
# If we have atool installed then use it.
if ( which atool 2>/dev/null >/dev/null ) ; then
atool --extract "$@"
return
fi
for archive in "$@"; do
case "$archive" in
*.tar* | *.t?z)
case $archive in
*.gz | *tgz | *.Z)
TARFLAGS="--use-compress-prog gzip"
;;
*.bz | *.bz2 | *tbz)
TARFLAGS="--use-compress-prog bzip2"
;;
*)
TARFLAGS=""
;;
esac;
tar xf "$archive" ${TARFLAGS}
;;
*.zip | *.ZIP)
unzip -q "$archive"
;;
*.gz | *.GZ)
gunzip "$archive"
;;
*.deb)
dpkg-deb -x "$archive" .
;;
*.rar)
unrar x "$archive"
;;
*.cpio)
cpio --extract --make-directories --file="$archive"
;;
*.cpio.gz)
gzip -dc "$archive" | cpio --extract --make-directories
;;
*)
echo "Unknown archive format" 1>&2
;;
esac;
done
}
#
# Create a screen session with the name of the current host, or attach to
# it here and now if it already exists.
#
screeny ()
{
screen -D -R -S `hostname`
}
#
# Play media found dynamically. Correctly copes with spaces in files.
#
function play
{
player=$*
if [ -z "$player" ]; then
player="xine --loop=shuffle+"
fi
find . \( -iname '*.avi' -o -iname '*.mkv' -o -iname '*.m4v' -o -iname '*.wmv' -o -iname '*.flv' -o -iname '*.mp4' -o -iname '*.mov' -o -iname '*.mpg' \) -exec $player "{}" +
}
# Open a new firefox instance, with a temporary profile
function firefox_temp() {
dir=$(mktemp -d)
echo "Profile directory: ${dir}"
firefox --new-instance --profile ${dir}
echo "Cleaning up .."
rm -rf ${dir}
}
# Generate a four-word pass-phrase
function passphrase() {
if [ ! -e /usr/share/dict/words ]; then
echo "/usr/share/dict/words is missing"
return
fi
# loop forever
while true; do
# Generate the random passphrase.
#
# Note: Using `shuf -n4 $file` is way faster
# than `sort --random-sort $file`.
#
out=$(shuf -n4 /usr/share/dict/words | tr '\n' ' ')
#
# If the output DOES NOT contain `-` then we show
# it, and return.
#
# Otherwise we rely upon the loop to try again :)
#
if ( ! echo ${out} | grep -E -- "[-']" 2>/dev/null >/dev/null) ; then
# convert to lower-case.
echo "${out,,}"
return
fi
done
}