]> gitweb.pimeys.fr Git - config-20-100.git/blob - .zsh/rc/extra/98_useless
Ajout du zshrc, même s'il manque encore de commentaires etc.
[config-20-100.git] / .zsh / rc / extra / 98_useless
1 #!/bin/zsh
2
3 # Found in the mailinglistarchive from Zsh (IIRC ~1996)
4 #f5# Select items for specific command(s) from history
5 selhist() {
6 emulate -L zsh
7 local TAB=$'\t';
8 (( $# < 1 )) && {
9 echo "Usage: $0 command"
10 return 1
11 };
12 cmd=(${(f)"$(grep -w $1 $HISTFILE | sort | uniq | pr -tn)"})
13 print -l $cmd | less -F
14 echo -n "enter number of desired command [1 - $(( ${#cmd[@]} - 1 ))]: "
15 local answer
16 read answer
17 print -z "${cmd[$answer]#*$TAB}"
18 }
19
20 # Use vim to convert plaintext to HTML
21 #f5# Transform files to html with highlighting
22 2html() {
23 emulate -L zsh
24 vim -u NONE -n -c ':syntax on' -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 &>/dev/null
25 }
26
27 # function readme() { $PAGER -- (#ia3)readme* }
28 #f5# View all README-like files in current directory in pager
29 readme() {
30 emulate -L zsh
31 local files
32 files=(./(#i)*(read*me|lue*m(in|)ut)*(ND))
33 if (($#files)) ; then
34 $PAGER $files
35 else
36 print 'No README files.'
37 fi
38 }
39
40 # function ansi-colors()
41 #f5# Display ANSI colors
42 ansi-colors() {
43 typeset esc="\033[" line1 line2
44 echo " _ _ _40 _ _ _41_ _ _ _42 _ _ 43_ _ _ 44_ _ _45 _ _ _ 46_ _ _ 47_ _ _ 49_ _"
45 for fore in 30 31 32 33 34 35 36 37; do
46 line1="$fore "
47 line2=" "
48 for back in 40 41 42 43 44 45 46 47 49; do
49 line1="${line1}${esc}${back};${fore}m Normal ${esc}0m"
50 line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m"
51 done
52 echo -e "$line1\n$line2"
53 done
54 }
55
56 # % slow_print `cat /etc/passwd`
57 #f5# Slowly print out parameters
58 slow_print() {
59 for argument in "$@" ; do
60 for ((i = 1; i <= ${#1} ;i++)) ; do
61 print -n "${argument[i]}"
62 sleep 0.08
63 done
64 print -n " "
65 done
66 print ""
67 }
68
69 # Rip an audio CD
70 #f5# Rip an audio CD
71 audiorip() {
72 mkdir -p ~/ripps
73 cd ~/ripps
74 cdrdao read-cd --device $DEVICE --driver generic-mmc audiocd.toc
75 cdrdao read-cddb --device $DEVICE --driver generic-mmc audiocd.toc
76 echo " * Would you like to burn the cd now? (yes/no)"
77 read input
78 if [[ "$input" = "yes" ]] ; then
79 echo " ! Burning Audio CD"
80 audioburn
81 echo " * done."
82 else
83 echo " ! Invalid response."
84 fi
85 }
86
87 # and burn it
88 #f5# Burn an audio CD (in combination with audiorip)
89 audioburn() {
90 cd ~/ripps
91 cdrdao write --device $DEVICE --driver generic-mmc audiocd.toc
92 echo " * Should I remove the temporary files? (yes/no)"
93 read input
94 if [[ "$input" = "yes" ]] ; then
95 echo " ! Removing Temporary Files."
96 cd ~
97 rm -rf ~/ripps
98 echo " * done."
99 else
100 echo " ! Invalid response."
101 fi
102 }
103
104 #f5# Make an audio CD from all mp3 files
105 mkaudiocd() {
106 # TODO: do the renaming more zshish, possibly with zmv()
107 emulate -L zsh
108 cd ~/ripps
109 for i in *.[Mm][Pp]3; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
110 for i in *.mp3; do mv "$i" `echo $i | tr ' ' '_'`; done
111 for i in *.mp3; do mpg123 -w `basename $i .mp3`.wav $i; done
112 normalize -m *.wav
113 for i in *.wav; do sox $i.wav -r 44100 $i.wav resample; done
114 }
115
116 #f5# Create an ISO image. You are prompted for\\&\quad volume name, filename and directory
117 mkiso() {
118 emulate -L zsh
119 echo " * Volume name "
120 read volume
121 echo " * ISO Name (ie. tmp.iso)"
122 read iso
123 echo " * Directory or File"
124 read files
125 mkisofs -o ~/$iso -A $volume -allow-multidot -J -R -iso-level 3 -V $volume -R $files
126 }
127
128 #f5# Simple thumbnails generator
129 genthumbs() {
130 rm -rf thumb-* index.html
131 echo "
132 <html>
133 <head>
134 <title>Images</title>
135 </head>
136 <body>" > index.html
137 for f in *.(gif|jpeg|jpg|png) ; do
138 convert -size 100x200 "$f" -resize 100x200 thumb-"$f"
139 echo " <a href=\"$f\"><img src=\"thumb-$f\"></a>" >> index.html
140 done
141 echo "
142 </body>
143 </html>" >> index.html
144 }
145
146 #f5# Set all ulimit parameters to \kbd{unlimited}
147 allulimit() {
148 ulimit -c unlimited
149 ulimit -d unlimited
150 ulimit -f unlimited
151 ulimit -l unlimited
152 ulimit -n unlimited
153 ulimit -s unlimited
154 ulimit -t unlimited
155 }
156
157 # ogg2mp3 with bitrate of 192
158 ogg2mp3_192() {
159 emulate -L zsh
160 oggdec -o - $1 | lame -b 192 - ${1:r}.mp3
161 }
162
163 #f5# Install x-lite (VoIP software)
164 getxlite() {
165 emulate -L zsh
166 setopt errreturn
167 [[ -d ~/tmp ]] || mkdir ~/tmp
168 cd ~/tmp
169
170 echo "Downloading http://www.counterpath.com/download/X-Lite_Install.tar.gz and storing it in ~/tmp:"
171 if wget http://www.counterpath.com/download/X-Lite_Install.tar.gz ; then
172 unp X-Lite_Install.tar.gz && echo done || echo failed
173 else
174 echo "Error while downloading." ; return 1
175 fi
176
177 if [[ -x xten-xlite/xtensoftphone ]] ; then
178 echo "Execute xten-xlite/xtensoftphone to start xlite."
179 fi
180 }
181
182 #f5# Install skype
183 getskype() {
184 emulate -L zsh
185 setopt errreturn
186 echo "Downloading debian package of skype."
187 echo "Notice: If you want to use a more recent skype version run 'getskypebeta'."
188 wget http://www.skype.com/go/getskype-linux-deb
189 $SUDO dpkg -i skype*.deb && echo "skype installed."
190 }
191
192 #f5# Install beta-version of skype
193 getskypebeta() {
194 emulate -L zsh
195 setopt errreturn
196 echo "Downloading debian package of skype (beta version)."
197 wget http://www.skype.com/go/getskype-linux-beta-deb
198 $SUDO dpkg -i skype-beta*.deb && echo "skype installed."
199 }
200
201 #f5# Install gizmo (VoIP software)
202 getgizmo() {
203 emulate -L zsh
204 setopt errreturn
205 echo "libgtk2.0-0, gconf2, libstdc++6, libasound2 and zlib1g have to be available. Installing."
206 $SUDO apt-get update
207 $SUDO apt-get install libgtk2.0-0 gconf2 libstdc++6 libasound2 zlib1g
208 wget "$(lynx --dump http://gizmo5.com/pc/download/linux/ | awk '/libstdc\+\+6.*\.deb/ {print $2}')"
209 $SUDO dpkg -i gizmo-project*.deb && echo "gizmo installed."
210 }
211
212 #f5# Get and run AIR (Automated Image and Restore)
213 getair() {
214 emulate -L zsh
215 setopt errreturn
216 [[ -w . ]] || { echo 'Error: you do not have write permissions in this directory. Exiting.' ; return 1 }
217 local VER='1.2.8'
218 wget http://puzzle.dl.sourceforge.net/sourceforge/air-imager/air-$VER.tar.gz
219 tar zxf air-$VER.tar.gz
220 cd air-$VER
221 INTERACTIVE=no $SUDO ./install-air-1.2.8
222 [[ -x /usr/local/bin/air ]] && [[ -n "$DISPLAY" ]] && $SUDO air
223 }
224
225 # http://strcat.de/blog/index.php?/archives/335-Software-sauber-deinstallieren...html
226 #f5# Log 'make install' output
227 mmake() {
228 emulate -L zsh
229 [[ ! -d ~/.errorlogs ]] && mkdir ~/.errorlogs
230 make -n install > ~/.errorlogs/${PWD##*/}-makelog
231 }
232
233 # usage example: 'lcheck strcpy'
234 #f5# Find out which libs define a symbol
235 lcheck() {
236 if [[ -n "$1" ]] ; then
237 nm -go /usr/lib/lib*.a 2>/dev/null | grep ":[[:xdigit:]]\{8\} . .*$1"
238 else
239 echo "Usage: lcheck <function>" >&2
240 fi
241 }
242
243 # make sure it is not assigned yet
244 [[ -n ${aliases[utf2iso]} ]] && unalias utf2iso
245 utf2iso() {
246 if isutfenv ; then
247 for ENV in $(env | command grep -i '.utf') ; do
248 eval export "$(echo $ENV | sed 's/UTF-8/iso885915/ ; s/utf8/iso885915/')"
249 done
250 fi
251 }
252
253 # make sure it is not assigned yet
254 [[ -n ${aliases[iso2utf]} ]] && unalias iso2utf
255 iso2utf() {
256 if ! isutfenv ; then
257 for ENV in $(env | command grep -i '\.iso') ; do
258 eval export "$(echo $ENV | sed 's/iso.*/UTF-8/ ; s/ISO.*/UTF-8/')"
259 done
260 fi
261 }
262
263 # if cdrecord is a symlink (to wodim) or isn't present at all warn:
264 if [[ -L /usr/bin/cdrecord ]] || ! check_com -c cdrecord; then
265 if check_com -c wodim; then
266 cdrecord() {
267 cat <<EOMESS
268 cdrecord is not provided under its original name by Debian anymore.
269 See #377109 in the BTS of Debian for more details.
270
271 Please use the wodim binary instead
272 EOMESS
273 return 1
274 }
275 fi
276 fi
277
278 # get_tw_cli has been renamed into get_3ware
279 if check_com -c get_3ware ; then
280 get_tw_cli() {
281 echo 'Warning: get_tw_cli has been renamed into get_3ware. Invoking get_3ware for you.'>&2
282 get_3ware
283 }
284 fi
285
286 ###############################
287 # When I was young… #
288 ###############################
289
290 stp() {
291 COMMAND=$(tail -n 2 ~/.zsh/history-$h | head -n 1)
292 COMMAND=${COMMAND#*;}
293 COMMAND=$(echo $COMMAND | sed -e "s/^sudo //")
294 echo "sudo ${COMMAND}" | zsh
295 }
296
297 mytest() {
298 key="${1%\=*}" ; val="${1#*\=}"
299 strictkey="${1%%\=*}" ; strictval="${1##*\=}"
300 arg="${1%\=}"
301 echo "Key : ${key}"
302 echo "Val : ${val}"
303 echo "Arg : ${arg}"
304 }
305