initial checkin
[zsh-lovers.git] / zsh_people / bruno_bonfils / rc / functions.rc
1 # -*- shell-script -*-
2 #
3 # Trace libraries load by first argument (ELF only)
4 # (note: exactly same result with ldd)
5 tracelib () {
6         LD_TRACE_LOADED_OBJECTS=1 $1
7 }
8
9 # debian upgrade
10 # if the first argument is void, proceed local upgrade
11 # else, send command via ssh
12 # assume user have sufficient permission for upgrade
13 # without interaction
14 #
15 # Note:
16 # i use sudo with the follow lines
17
18 # Cmnd_Alias      DEBIAN  = /usr/bin/apt-get, /usr/bin/dpkg
19 # asyd            ALL = PASSWD: ALL, NOPASSWD: DEBIAN
20 upgrade () {
21     if [ -z $1 ] ; then
22         sudo apt-get update
23         sudo apt-get -u upgrade
24     else
25         ssh $1 sudo apt-get update
26         # ask before the upgrade
27         local dummy
28         ssh $1 sudo apt-get --no-act upgrade
29         echo -n "Process the upgrade ?"
30         read -q dummy
31         if [[ $dummy == "y" ]] ; then
32             ssh $1 sudo apt-get -u upgrade --yes
33         fi
34     fi
35 }
36
37 compdef _hosts upgrade
38
39 lsperm () {
40         echo $1 | perl -e 'chomp($s=<>);$p=(stat($s))[2] & 07777;printf "$s -> %04o\n",$p'
41 }
42
43 findnosecure () {
44         find / -perm +4000 -print
45 }
46
47 function cd () {
48 if [[ -z $2 ]]; then
49   if [[ -f $1 ]]; then
50     builtin cd $1:h
51   else
52     builtin cd $1
53   fi
54 else
55   if [[ -z $3 ]]; then
56     builtin cd $1 $2
57   else
58     echo cd: too many arguments
59   fi
60 fi
61 }