3 # rename pictures based on information found in exif headers
4 #f5# Rename pictures based on information found in exif headers
7 if [[ $# -lt 1 ]] ; then
8 echo 'Usage: jpgrename $FILES' >& 2
11 echo -n 'Checking for jhead with version newer than 1.9: '
12 jhead_version
=`jhead -h | grep 'used by most Digital Cameras. v.*' | awk '{print $6}' | tr -d v`
13 if [[ $jhead_version > '1.9' ]]; then
14 echo 'success - now running jhead.'
15 jhead
-n%Y-
%m-
%d_
%Hh
%M_
%f $
*
17 echo 'failed - exiting.'
22 # get_ic() - queries imap servers for capabilities; real simple. no imaps
26 if [[ ! -z $1 ]] ; then
28 print
"querying imap server on $1:${port}...\n";
29 print
"a1 capability\na2 logout\n" | nc
$1 ${port}
31 print
"usage:\n $0 <imap-server> [port]"
35 # creates a Maildir/ with its {new,cur,tmp} subdirs
39 root
=${MAILDIR_ROOT:-${HOME}/Mail}
40 if [[ -z ${1} ]] ; then print
"Usage:\n $0 <dirname>" ; return 1 ; fi
42 mkdir
-p ${root}/${subdir}/{cur,new,tmp}
45 #f5# Change the xterm title from within GNU-screen
48 if [[ $1 != "-f" ]] ; then
49 if [[ -z ${DISPLAY} ]] ; then
50 printf 'xtrename only makes sense in X11.\n'
57 printf 'usage: xtrename [-f] "title for xterm"\n'
58 printf ' renames the title of xterm from _within_ screen.\n'
59 printf ' also works without screen.\n'
60 printf ' will not work if DISPLAY is unset, use -f to override.\n'
63 print
-n "\eP\e]0;${1}\C-G\e\\"
67 #f2# Find history events by search pattern and list them by date.
71 local usage
help ident format_l format_s first_char remain first last
72 usage
='USAGE: whatwhen [options] <searchstring> <search range>'
73 help='Use' \
`'whatwhen -h'\'' for further explanations.'
74 ident=${(l,${#${:-Usage: }},, ,)}
75 format_l="${ident}%s\t\t\t%s\n"
76 format_s="${format_l//(\\t)##/\\t}"
77 # Make the first char of the word to search for case
78 # insensitive; e.g. [aA]
79 first_char=[${(L)1[1]}${(U)1[1]}]
81 # Default search range is `-100'.
83 # Optional, just used for `<first> <last>' given.
87 printf '%s\n\n' 'ERROR: No search string specified. Aborting.'
88 printf '%s\n%s\n\n' ${usage} ${help} && return 1
91 printf '%s\n\n' ${usage}
93 printf $format_l '-h' 'show help text'
96 printf $format_l "'0'" 'the whole history,'
97 printf $format_l '-<n>' 'offset to the current history number; (default: -100)'
98 printf $format_s '<[-]first> [<last>]' 'just searching within a give range'
99 printf '\n%s\n' 'EXAMPLES:'
100 printf ${format_l/(\\t)/} 'whatwhen grml' '# Range is set to -100 by default.'
101 printf $format_l 'whatwhen zsh -250'
102 printf $format_l 'whatwhen foo 1 99'
105 printf '%s\n%s\n\n' ${usage} ${help} && return 1
108 # -l list results on stout rather than invoking $EDITOR.
109 # -i Print dates as in YYYY-MM-DD.
110 # -m Search for a - quoted - pattern within the history.
111 fc -li -m "*${first_char}${remain}*" $first $last
117 # change fluxbox keys from 'Alt-#' to 'Alt-F#' and vice versa
120 [[ -n "$FLUXKEYS" ]] ||
local FLUXKEYS
="$HOME/.fluxbox/keys"
121 if ! [[ -r "$FLUXKEYS" ]] ; then
122 echo "Sorry, \$FLUXKEYS file $FLUXKEYS could not be read - nothing to be done."
125 if grep -q 'Mod1 F[0-9] :Workspace [0-9]' $FLUXKEYS ; then
126 echo -n 'Switching to Alt-# mode in ~/.fluxbox/keys: '
127 sed -i -e 's|^\(Mod[0-9]\+[: space :]\+\)F\([0-9]\+[: space :]\+:Workspace.*\)|\1\2|' $FLUXKEYS && echo done ||
echo failed
128 elif grep -q 'Mod1 [0-9] :Workspace [0-9]' $FLUXKEYS ; then
129 echo -n 'Switching to Alt-F# mode in ~/.fluxbox/keys: '
130 sed -i -e 's|^\(Mod[0-9]\+[: space :]\+\)\([0-9]\+[: space :]\+:Workspace.*\)|\1F\2|' $FLUXKEYS && echo done ||
echo failed
132 echo 'Sorry, do not know what to do.'
138 # retrieve weather information on the console
139 # Usage example: 'weather LOWG'
142 [ $1 = "-v" ] && local VERBOSE
=1 && shift
144 print
'Usage: weather [-v] <station_id>' >&2
145 print
'List of stations: http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code'>&2
146 print
'With -v, displays everything' >&2
151 local FILE
="$HOME/.weather/$PLACE"
152 local LOG
="$HOME/.weather/log"
154 [[ -d $HOME/.weather
]] ||
{
155 print
-n "Creating $HOME/.weather: "
160 print
"Retrieving information for ${PLACE}:"
162 wget
-T 10 --no-verbose --output-file=$LOG --output-document=$FILE --timestamping http
://weather.noaa.gov
/pub
/data
/observations
/metar
/decoded
/$PLACE.TXT
164 if [[ $?
-eq 0 ]] ; then
165 if [[ -n "$VERBOSE" ]] ; then
168 DATE
=$
(grep 'UTC' $FILE |
sed 's#.* /##')
169 TEMPERATURE
=$
(awk '/Temperature/ { print $4" degree Celcius / " $2" degree Fahrenheit" }' $FILE|
tr -d '(')
171 echo "temp: $TEMPERATURE"
174 print
"There was an error retrieving the weather information for $PLACE" >&2
180 # d():Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
181 # note: option AUTO_PUSHD has to be set
182 #f5# Jump between directories
186 local color
=$fg_bold[blue
]
188 dirs -p |
while read dir
; do
189 local num
="${$(printf "%-4d " $i)/ /.}"
190 printf " %s $color%s$reset_color\n" $num $dir
194 read -r 'dir?Jump to directory: ' ||
return
195 (( dir
== -1 )) && return
196 if (( dir
< 0 || dir
>= i
)); then
197 echo d
: no such directory stack entry
: $dir
206 diff -crd "$*" |
egrep -v "^Only in |^Binary files "
208 #f5# Disassemble source files using gcc and as
211 gcc
-pipe -S -o - -O -g $
* | as
-aldh -o /dev
/null
213 #f5# Firefox remote control - open given URL
215 if [ -e /etc
/debian_version
]; then
216 firefox
-a iceweasel
-remote "openURL($1)" || firefox
${1}&
218 firefox
-a firefox
-remote "openURL($1)" || firefox
${1}&
221 #f5# Unified diff to timestamped outputfile
223 diff -udrP "$1" "$2" > diff.
`date "+%Y-%m-%d"`.
"$1"
225 #f5# Show contents of gzipped tar file
228 gunzip
-c $1 |
tar -tf - -- |
$PAGER
230 #f5# Show contents of zip file
238 diff -urd $
* |
egrep -v "^Only in |^Binary files "
240 #f5# (Mis)use \kbd{vim} as \kbd{less}
243 vim
--cmd 'let no_plugin_maps = 1' -c "so \$VIMRUNTIME/macros/less.vim" "${@:--}"
246 # Function Usage: uopen $URL/$file
247 #f5# Download a file and display it locally
250 if ! [[ -n "$1" ]] ; then
251 print
"Usage: uopen \$URL/\$file">&2
255 MIME
=$
(curl
--head $FILE |
grep Content-Type | cut
-d ' ' -f 2 | cut
-d\
; -f 1)
257 curl
$FILE | see
${MIME}:-
263 [[ ! -d ~
/shots
]] && mkdir ~
/shots
264 #cd ~/shots ; sleep 5 ; import -window root -depth 8 -quality 80 `date "+%Y-%m-%d--%H:%M:%S"`.png
265 cd ~
/shots
; sleep 5; import
-window root shot_
`date --iso-8601=m`.jpg
271 images
=( *.
{jpg
,gif
,png
}(.N
) )
273 if [[ $#images -eq 0 ]] ; then
274 print
"No image files found"
280 #f5# Create PDF file from source code
285 a2ps
--medium A4dj
-E -o $output $
*
289 # zsh with perl-regex - use it e.g. via:
290 # regcheck '\s\d\.\d{3}\.\d{3} Euro' ' 1.000.000 Euro'
291 #f5# Checks whether a regex matches or not.\\&\quad Example: \kbd{regcheck '.\{3\} EUR' '500 EUR'}
296 pcre_match
$2 && echo "regex matches" ||
echo "regex does not match"
299 #f5# List files which have been changed within the last {\it n} days, {\it n} defaults to 1
305 #f5# List files which have been modified within the last {\it n} days, {\it n} defaults to 1
311 # just press 'asdf' keys to toggle between dvorak and us keyboard layout
313 echo -n 'Switching to us keyboard layout: '
314 [[ -z "$DISPLAY" ]] && $SUDO loadkeys us
&>/dev
/null || setxkbmap us
&>/dev
/null
318 echo -n 'Switching to dvorak keyboard layout: '
319 [[ -z "$DISPLAY" ]] && $SUDO loadkeys dvorak
&>/dev
/null || setxkbmap dvorak
&>/dev
/null
322 # just press 'asdf' key to toggle from neon layout to us keyboard layout
324 echo -n 'Switching to us keyboard layout: '
325 setxkbmap us
&& echo 'Done' ||
echo 'Failed'
328 # set up an ipv6 tunnel
333 if ifconfig sit1
2>/dev
/null |
grep -q 'inet6 addr: 2002:.*:1::1' ; then
334 print
'ipv6 tunnel already set up, nothing to be done.'
335 print
'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
337 [[ -n "$PUBLIC_IP" ]] || \
338 local PUBLIC_IP
=$
(ifconfig $
(route
-n |
awk '/^0\.0\.0\.0/{print $8; exit}') | \
339 awk '/inet addr:/ {print $2}' |
tr -d 'addr:')
341 [[ -n "$PUBLIC_IP" ]] ||
{ print
'No $PUBLIC_IP set and could not determine default one.' ; return 1 }
342 local IPV6ADDR
=$
(printf "2002:%02x%02x:%02x%02x:1::1" $
(print
${PUBLIC_IP//./ }))
343 print
-n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
344 ifconfig sit0 tunnel
::192.88.99.1 up
345 ifconfig sit1 add
"$IPV6ADDR" && print
done || print failed
349 if ifconfig sit1
2>/dev
/null |
grep -q 'inet6 addr: 2002:.*:1::1' ; then
350 print
'ipv6 tunnel available' ; return 0
352 print
'ipv6 tunnel not available' ; return 1
356 if ifconfig sit1
2>/dev
/null |
grep -q 'inet6 addr: 2002:.*:1::1' ; then
357 print
-n 'Stopping ipv6 tunnel (sit0 + sit1): '
358 ifconfig sit1 down
; ifconfig sit0 down
&& print
done || print failed
360 print
'No ipv6 tunnel found, nothing to be done.' ; return 1
364 print
"Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
369 # run dhclient for wireless device
371 salias dhclient
"$(wavemon -d | awk '/device/{print $2}')"
374 # spawn a minimally set up mksh - useful if you want to umount /usr/.
377 local shell
="/bin/mksh"
379 if [[ ! -x ${shell} ]]; then
380 printf '`%s'\'' not available, giving up.\n' ${shell} >&2
384 exec env
-i ENV
="/etc/minimal-shellrc" HOME
="$HOME" TERM
="$TERM" ${shell}
387 #f1# grep for patterns in grml's zsh setup
393 print "usage: zg -[anr] <pattern>\n";
394 print " Search for patterns in grml'\''s zshrc.\n";
395 print " zg takes no or exactly one option plus a non empty pattern.\n\n";
397 print " -- no options (use if your pattern starts in with a dash.\n";
398 print " -a search for the pattern in all code regions\n";
399 print " -n search for the pattern in non-root code only\n";
400 print " -r search in code for everyone (also root) only\n\n";
401 print " The default is -a for non-root users and -r for root.\n\n";
402 print " If you installed the zshrc to a non-default locations (ie *NOT*\n";
403 print " in /etc/zsh/zshrc) do: export GRML_ZSHRC=\$HOME/.zshrc\n";
404 print " ...in case you copied the file to that location.\n\n";
408 if ($ENV{GRML_ZSHRC} ne "") {
409 $RC = $ENV{GRML_ZSHRC};
411 $RC = "/etc/zsh/zshrc";
414 usage if ($#ARGV < 0 || $#ARGV > 1);
415 if ($> == 0) { $mode = "allonly"; }
416 else { $mode = "all"; }
419 if ($opt eq "--") { shift; }
420 elsif ($opt eq "-a") { $mode = "all"; shift; }
421 elsif ($opt eq "-n") { $mode = "nonroot"; shift; }
422 elsif ($opt eq "-r" ) { $mode = "allonly"; shift; }
423 elsif ($opt =~ m/^-/ || $#ARGV > 0) { usage(); }
426 usage() if ($pattern eq "");
428 open FH, "<$RC" or die "zg: Could not open $RC: $!\n";
429 while ($line = <FH>) {
431 if ($line =~ m/^#:grep:marker:for:mika:/) { $markerfound = 1; next; }
432 next if ($mode eq "nonroot" && markerfound == 0);
433 break if ($mode eq "allonly" && markerfound == 1);
434 print $line, "\n" if ($line =~ /$pattern/);
444 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
445 # You use it as follows:
446 # $ NTREF=/reference/file
448 # This lists all the files in the current directory newer than the reference file.
449 # You can also specify the reference file inline; note quotes:
450 # $ ls -l *(e:'nt ~/.zshenv':)
452 if [[ -n $1 ]] ; then
455 [[ $REPLY -nt $NTREF ]]
459 # shell functions {{{
461 #f1# Provide csh compatibility
462 setenv
() { typeset
-x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility
464 #f1# Reload an autoloadable function
465 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
466 compdef _functions freload
468 #f1# List symlinks in detail (more detailed version of 'readlink -f' and 'whence -s')
470 [[ -z "$1" ]] && printf 'Usage: %s <file(s)>\n' "$0" && return 1
471 for file in "$@
" ; do
472 while [[ -h "$file" ]] ; do
474 file=$(readlink "$file")
480 if check_com qma ; then
481 #f1# View the zsh manual
482 manzsh() { qma zshall "$1" }
485 manzsh() { /usr/bin/man zshall | vim -c "se ft
=man| se hlsearch
" +/"$1" - ; }
490 ZSH_PROFILE_RC=1 $SHELL "$@
"
493 #f1# Edit an alias via zle
495 [[ -z "$1" ]] && { echo "Usage
: edalias
<alias_to_edit
>" ; return 1 } || vared aliases'[$1]' ;
497 compdef _aliases edalias
499 #f1# Edit a function via zle
501 [[ -z "$1" ]] && { echo "Usage
: edfun
<function_to_edit
>" ; return 1 } || zed -f "$1" ;
503 compdef _functions edfunc
505 #f1# Provides useful information on globbing
512 p named pipes
(FIFOs
)
513 * executable plain files
(0100)
514 % device files
(character or block special
)
515 %b block special files
516 %c character special files
517 r owner-readable files
(0400)
518 w owner-writable files
(0200)
519 x owner-executable files
(0100)
520 A group-readable files
(0040)
521 I group-writable files
(0020)
522 E group-executable files
(0010)
523 R world-readable files
(0004)
524 W world-writable files
(0002)
525 X world-executable files
(0001)
526 s setuid files
(04000)
527 S setgid files
(02000)
528 t files with the sticky bit
(01000)
530 print
*(m-1
) # Files modified up to a day ago
531 print
*(a1
) # Files accessed a day ago
532 print
*(@
) # Just symlinks
533 print
*(Lk
+50) # Files bigger than 50 kilobytes
534 print
*(Lk-50
) # Files smaller than 50 kilobytes
535 print
**/*.c
# All *.c files recursively starting in \$PWD
536 print
**/*.c~
file.c
# Same as above, but excluding 'file.c'
537 print
(foo|bar
).
* # Files starting with 'foo' or 'bar'
538 print
*~
*.
* # All Files that do not contain a dot
539 chmod 644 *(.^x
) # make all plain non-executable files publically readable
540 print
-l *(.c|.h
) # Lists *.c and *.h
541 print
**/*(g
:users
:) # Recursively match all files that are owned by group 'users'
542 echo /proc
/*/cwd
(:h
:t
:s
/self
//) # Analogous to >ps ax | awk '{print $1}'<"
544 alias help-zshglob
=H-Glob
#dépendant du truc au dessus
546 function swapfiles
(){