Browse code

Add options for su(do) and apt(itude|-get)

Daniel Bolton authored on 07/08/2011 at 19:30:55
Showing 1 changed files
... ...
@@ -1,48 +1,76 @@
1
-# https://github.com/dbb/
1
+# Authors:
2
+# https://github.com/AlexBio
3
+# https://github.com/dbb
2 4
 #
3 5
 # Debian-related zsh aliases and functions for zsh
4 6
 
7
+# Set to 'apt-get' or 'aptitude'
8
+apt_pref='aptitude'
9
+
10
+# Use sudo by default if it's installed
11
+if [[ -e $( which sudo ) ]]; then
12
+    use_sudo=1
13
+fi
5 14
 
6 15
 # Aliases ###################################################################
7 16
 
8 17
 # Some self-explanatory aliases
9 18
 alias acs="apt-cache search"
10
-alias afs='apt-file search --regexp'
11 19
 alias aps='aptitude search'
12 20
 alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
13 21
 		--no-gui --disable-columns search"	# search package
14
-alias apsrc='apt-get source'
15
-alias apv='apt-cache policy'
16
-
17
-# aliases that use su -c ##############
18
-alias apdg='su -lc "aptitude update && aptitude safe-upgrade" root'
19
-alias apud='su -lc "aptitude update" root'
20
-alias apug='su -lc "aptitude safe-upgrade" root'
21
-# end aliases that use su -c ##########
22
-
23
-# aliases that use sudo ###############
24
-alias ad="sudo apt-get update"				# update packages lists
25
-alias au="sudo apt-get update && \
26
-		sudo apt-get dselect-upgrade"		# upgrade packages
27
-alias ai="sudo apt-get install"				# install package
28
-alias ar="sudo apt-get remove --purge && \
29
-		sudo apt-get autoremove --purge"	# remove package
30
-alias ac="sudo apt-get clean && sudo apt-get autoclean" # clean apt cache
31
-# end aliases that use sudo ###########
22
+
23
+# apt-file
24
+alias afs='apt-file search --regexp'
25
+
26
+
27
+# These are apt-get only
28
+alias asrc='apt-get source'
29
+alias ap='apt-cache policy'
30
+
31
+# superuser operations ################
32
+if [[ $use_sudo -eq 1 ]]; then
33
+    alias ai="sudo $apt_pref install"
34
+    alias ad="sudo $apt_pref update"
35
+    alias afu='sudo apt-file update'
36
+    alias ag="sudo $apt_pref upgrade"
37
+    alias adg="sudo $apt_pref update && sudo $apt_pref upgrade"
38
+    alias ap="sudo $apt_pref purge"
39
+    alias ar="sudo $apt_pref remove"
40
+
41
+    if [[ $apt_pref -eq 'apt-get' ]]; then
42
+        alias ads="sudo $apt_pref dselect-upgrade"
43
+    fi
44
+    
45
+    # Install all .deb files in the current directory.
46
+    # Warning: you will need to put the glob in single quotes if you use:
47
+    # glob_subst
48
+    alias di='sudo dpkg -i ./*.deb'
49
+
50
+    # Remove ALL kernel images and headers EXCEPT the one in use
51
+    alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'
52
+else
53
+    alias ai='apin' 
54
+    alias ad='su -lc "'"$apt_pref"' update" root'
55
+    alias afu='su -lc "apt-file update"'
56
+    alias ag='su -lc "'"$apt_pref"' safe-upgrade" root'
57
+    alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root'
58
+    alias di='su -lc "dpkg -i ./*.deb" root'
59
+    # Remove ALL kernel images and headers EXCEPT the one in use
60
+    alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root'
61
+fi
62
+# end superuser operations ##########
63
+
32 64
 
33 65
 # print all installed packages
34 66
 alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
35 67
 
36
-# Install all .deb files in the current directory.
37
-# Warning: you will need to put the glob in single quotes if you use:
38
-# glob_subst
39
-alias di='su -lc "dpkg -i ./*.deb" root'
68
+
40 69
 
41 70
 # Create a basic .deb package
42 71
 alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
43 72
 
44
-# Remove ALL kernel images and headers EXCEPT the one in use
45
-alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root'
73
+
46 74
 
47 75
 
48 76