... | ... |
@@ -4,8 +4,13 @@ |
4 | 4 |
# |
5 | 5 |
# Debian-related zsh aliases and functions for zsh |
6 | 6 |
|
7 |
-# Set to 'apt-get' or 'aptitude' |
|
8 |
-apt_pref='aptitude' |
|
7 |
+# Use aptitude if installed, or apt-get if not. |
|
8 |
+# You can just set apt_pref='apt-get' to override it. |
|
9 |
+if [[ -e $( which aptitude ) ]]; then |
|
10 |
+ apt_pref='aptitude' |
|
11 |
+else |
|
12 |
+ apt_pref='apt-get' |
|
13 |
+fi |
|
9 | 14 |
|
10 | 15 |
# Use sudo by default if it's installed |
11 | 16 |
if [[ -e $( which sudo ) ]]; then |
... | ... |
@@ -13,6 +18,10 @@ if [[ -e $( which sudo ) ]]; then |
13 | 13 |
fi |
14 | 14 |
|
15 | 15 |
# Aliases ################################################################### |
16 |
+# These are for more obscure uses of apt-get and aptitude that aren't covered |
|
17 |
+# below. |
|
18 |
+alias ag='apt-get' |
|
19 |
+alias at='aptitude' |
|
16 | 20 |
|
17 | 21 |
# Some self-explanatory aliases |
18 | 22 |
alias acs="apt-cache search" |
... | ... |
@@ -28,19 +37,23 @@ alias afs='apt-file search --regexp' |
28 | 28 |
alias asrc='apt-get source' |
29 | 29 |
alias ap='apt-cache policy' |
30 | 30 |
|
31 |
-# superuser operations ################ |
|
31 |
+# superuser operations ###################################################### |
|
32 | 32 |
if [[ $use_sudo -eq 1 ]]; then |
33 |
- alias ai="sudo $apt_pref install" |
|
33 |
+# commands using sudo ####### |
|
34 |
+ alias aac="sudo $apt_pref autoclean" |
|
35 |
+ alias abd="sudo $apt_pref build-dep" |
|
36 |
+ alias ac="sudo $apt_pref clean" |
|
34 | 37 |
alias ad="sudo $apt_pref update" |
38 |
+ alias adg="sudo $apt_pref update && sudo $apt_pref upgrade" |
|
39 |
+ alias adu="sudo $apt_pref update && sudo $apt_pref dist-upgrade" |
|
35 | 40 |
alias afu='sudo apt-file update' |
36 | 41 |
alias ag="sudo $apt_pref upgrade" |
37 |
- alias adg="sudo $apt_pref update && sudo $apt_pref upgrade" |
|
42 |
+ alias ai="sudo $apt_pref install" |
|
38 | 43 |
alias ap="sudo $apt_pref purge" |
39 | 44 |
alias ar="sudo $apt_pref remove" |
40 | 45 |
|
41 |
- if [[ $apt_pref -eq 'apt-get' ]]; then |
|
42 |
- alias ads="sudo $apt_pref dselect-upgrade" |
|
43 |
- fi |
|
46 |
+ # apt-get only |
|
47 |
+ alias ads="sudo $apt_pref dselect-upgrade" |
|
44 | 48 |
|
45 | 49 |
# Install all .deb files in the current directory. |
46 | 50 |
# Warning: you will need to put the glob in single quotes if you use: |
... | ... |
@@ -48,25 +61,54 @@ if [[ $use_sudo -eq 1 ]]; then |
48 | 48 |
alias di='sudo dpkg -i ./*.deb' |
49 | 49 |
|
50 | 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`))' |
|
51 |
+ alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \ |
|
52 |
+ ?not(~n`uname -r`))' |
|
53 |
+ |
|
54 |
+ |
|
55 |
+# commands using su ######### |
|
52 | 56 |
else |
53 |
- alias ai='apin' |
|
57 |
+ alias aac='su -ls "'"$apt_pref"' autoclean" root' |
|
58 |
+ abd() { |
|
59 |
+ cmd="su -lc '$apt_pref build-dep $@' root" |
|
60 |
+ print "$cmd" |
|
61 |
+ eval "$cmd" |
|
62 |
+ } |
|
63 |
+ alias ac='su -ls "'"$apt_pref"' clean" root' |
|
54 | 64 |
alias ad='su -lc "'"$apt_pref"' update" root' |
65 |
+ alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root' |
|
66 |
+ alias adu='su -lc "'"$apt_pref"' update && aptitude dist-upgrade" root' |
|
55 | 67 |
alias afu='su -lc "apt-file update"' |
56 | 68 |
alias ag='su -lc "'"$apt_pref"' safe-upgrade" root' |
57 |
- alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root' |
|
69 |
+ ai() { |
|
70 |
+ cmd="su -lc 'aptitude -P install $@' root" |
|
71 |
+ print "$cmd" |
|
72 |
+ eval "$cmd" |
|
73 |
+ } |
|
74 |
+ ap() { |
|
75 |
+ cmd="su -lc '$apt_pref -P purge $@' root" |
|
76 |
+ print "$cmd" |
|
77 |
+ eval "$cmd" |
|
78 |
+ } |
|
79 |
+ ar() { |
|
80 |
+ cmd="su -lc '$apt_pref -P remove $@' root" |
|
81 |
+ print "$cmd" |
|
82 |
+ eval "$cmd" |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ # Install all .deb files in the current directory |
|
86 |
+ # Assumes glob_subst is off |
|
58 | 87 |
alias di='su -lc "dpkg -i ./*.deb" root' |
88 |
+ |
|
59 | 89 |
# 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' |
|
90 |
+ alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \ |
|
91 |
+ ?not(~n`uname -r`))'\'' root' |
|
61 | 92 |
fi |
62 |
-# end superuser operations ########## |
|
63 | 93 |
|
64 | 94 |
|
95 |
+# Misc. ##################################################################### |
|
65 | 96 |
# print all installed packages |
66 | 97 |
alias allpkgs='aptitude search -F "%p" --disable-columns ~i' |
67 | 98 |
|
68 |
- |
|
69 |
- |
|
70 | 99 |
# Create a basic .deb package |
71 | 100 |
alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' |
72 | 101 |
|
... | ... |
@@ -75,23 +117,19 @@ alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc' |
75 | 75 |
|
76 | 76 |
|
77 | 77 |
# Functions ################################################################# |
78 |
- |
|
79 |
-# install packages without sudo |
|
80 |
-apin() { |
|
81 |
- cmd="su -lc 'aptitude -P install $@' root" |
|
82 |
- print "$cmd" |
|
83 |
- eval "$cmd" |
|
84 |
-} |
|
85 |
- |
|
86 | 78 |
# create a simple script that can be used to 'duplicate' a system |
87 | 79 |
apt-copy() { |
88 |
- print '#!/bin/sh'"\n" > apt-copy.sh |
|
80 |
+ print '#!/bin/sh'"\n" > apt-copy.sh |
|
81 |
+ |
|
82 |
+ cmd="$apt_pref install -s " |
|
89 | 83 |
|
90 |
- list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;') |
|
84 |
+ for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; { |
|
85 |
+ cmd="${cmd} ${p}" |
|
86 |
+ } |
|
91 | 87 |
|
92 |
- print 'aptitude install '"$list\n" >> apt-copy.sh |
|
88 |
+ print $cmd "\n" >> apt-copy.sh |
|
93 | 89 |
|
94 |
- chmod +x apt-copy.sh |
|
90 |
+ chmod +x apt-copy.sh |
|
95 | 91 |
} |
96 | 92 |
|
97 | 93 |
|