Browse code

Merge pull request #529 from dbb/master

Merge 'deb' and 'debian' plugins

Robby Russell authored on 10/10/2011 at 12:48:49
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,13 +0,0 @@
1
-# Aliases
2
-alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
3
-		--no-gui --disable-columns search"	# search package
4
-alias ad="sudo apt-get update"				# update packages lists
5
-alias au="sudo apt-get update && \
6
-		sudo apt-get dselect-upgrade"		# upgrade packages
7
-alias ai="sudo apt-get install"				# install package
8
-alias ar="sudo apt-get remove --purge && \
9
-		sudo apt-get autoremove --purge"	# remove package
10
-alias ap="apt-cache policy"				# apt policy
11
-alias av="apt-cache show"				# show package info
12
-alias acs="apt-cache search"                            # search package
13
-alias ac="sudo apt-get clean && sudo apt-get autoclean" # clean apt cache
... ...
@@ -1,53 +1,143 @@
1
-# https://github.com/dbbolton/
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
+# 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
14
+
15
+# Use sudo by default if it's installed
16
+if [[ -e $( which sudo ) ]]; then
17
+    use_sudo=1
18
+fi
5 19
 
6 20
 # Aliases ###################################################################
21
+# These are for more obscure uses of apt-get and aptitude that aren't covered
22
+# below.
23
+alias ag='apt-get'
24
+alias at='aptitude'
7 25
 
8 26
 # Some self-explanatory aliases
9
-alias afs='apt-file search --regexp'
27
+alias acs="apt-cache search"
10 28
 alias aps='aptitude search'
11
-alias apsrc='apt-get source'
12
-alias apv='apt-cache policy'
29
+alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
30
+		--no-gui --disable-columns search"	# search package
13 31
 
14
-alias apdg='su -c "aptitude update && aptitude safe-upgrade"'
15
-alias apud='su -c "aptitude update"'
16
-alias apug='su -c "aptitude safe-upgrade"'
32
+# apt-file
33
+alias afs='apt-file search --regexp'
17 34
 
35
+
36
+# These are apt-get only
37
+alias asrc='apt-get source'
38
+alias ap='apt-cache policy'
39
+
40
+# superuser operations ######################################################
41
+if [[ $use_sudo -eq 1 ]]; then
42
+# commands using sudo #######
43
+    alias aac="sudo $apt_pref autoclean"
44
+    alias abd="sudo $apt_pref build-dep"
45
+    alias ac="sudo $apt_pref clean"
46
+    alias ad="sudo $apt_pref update"
47
+    alias adg="sudo $apt_pref update && sudo $apt_pref upgrade"
48
+    alias adu="sudo $apt_pref update && sudo $apt_pref dist-upgrade"
49
+    alias afu='sudo apt-file update'
50
+    alias ag="sudo $apt_pref upgrade"
51
+    alias ai="sudo $apt_pref install"
52
+    alias ap="sudo $apt_pref purge"
53
+    alias ar="sudo $apt_pref remove"
54
+
55
+    # apt-get only
56
+    alias ads="sudo $apt_pref dselect-upgrade"
57
+    
58
+    # Install all .deb files in the current directory.
59
+    # Warning: you will need to put the glob in single quotes if you use:
60
+    # glob_subst
61
+    alias di='sudo dpkg -i ./*.deb'
62
+
63
+    # Remove ALL kernel images and headers EXCEPT the one in use
64
+    alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
65
+        ?not(~n`uname -r`))'
66
+
67
+
68
+# commands using su #########
69
+else
70
+    alias aac='su -ls "'"$apt_pref"' autoclean" root'
71
+    abd() {
72
+        cmd="su -lc '$apt_pref build-dep $@' root"
73
+        print "$cmd"
74
+        eval "$cmd"
75
+    }
76
+    alias ac='su -ls "'"$apt_pref"' clean" root'
77
+    alias ad='su -lc "'"$apt_pref"' update" root'
78
+    alias adg='su -lc "'"$apt_pref"' update && aptitude safe-upgrade" root'
79
+    alias adu='su -lc "'"$apt_pref"' update && aptitude dist-upgrade" root'
80
+    alias afu='su -lc "apt-file update"'
81
+    alias ag='su -lc "'"$apt_pref"' safe-upgrade" root'
82
+    ai() {
83
+        cmd="su -lc 'aptitude -P install $@' root"
84
+        print "$cmd"
85
+        eval "$cmd"
86
+    }
87
+    ap() {
88
+        cmd="su -lc '$apt_pref -P purge $@' root"
89
+        print "$cmd"
90
+        eval "$cmd"
91
+    }
92
+    ar() {
93
+        cmd="su -lc '$apt_pref -P remove $@' root"
94
+        print "$cmd"
95
+        eval "$cmd"
96
+    }
97
+
98
+    # Install all .deb files in the current directory
99
+    # Assumes glob_subst is off
100
+    alias di='su -lc "dpkg -i ./*.deb" root'
101
+
102
+    # Remove ALL kernel images and headers EXCEPT the one in use
103
+    alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
104
+        ?not(~n`uname -r`))'\'' root'
105
+fi
106
+
107
+
108
+# Misc. #####################################################################
18 109
 # print all installed packages
19 110
 alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
20 111
 
21
-# Install all .deb files in the current directory.
22
-# Warning: you will need to put the glob in single quotes if you use:
23
-# glob_subst
24
-alias di='su -c "dpkg -i ./*.deb"'
25
-
26 112
 # Create a basic .deb package
27 113
 alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
28 114
 
29
-# Remove ALL kernel images and headers EXCEPT the one in use
30
-alias kclean='su -c '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'\'' root'
31 115
 
32 116
 
33 117
 
34
-# Functions #################################################################
35 118
 
119
+# Functions #################################################################
36 120
 # create a simple script that can be used to 'duplicate' a system
37 121
 apt-copy() {
38
-	print '#!/bin/sh'"\n" > apt-copy.sh
122
+    print '#!/bin/sh'"\n" > apt-copy.sh
39 123
 
40
-	list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;')
124
+    cmd="$apt_pref install "
41 125
 
42
-	print 'aptitude install '"$list\n" >> apt-copy.sh
126
+    for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
127
+        cmd="${cmd} ${p}"
128
+    }
43 129
 
44
-	chmod +x apt-copy.sh
130
+    print $cmd "\n" >> apt-copy.sh
131
+
132
+    chmod +x apt-copy.sh
45 133
 }
46 134
 
47 135
 
48 136
 # Kernel-package building shortcut
49
-dbb-build () {
50
-	MAKEFLAGS=''		# temporarily unset MAKEFLAGS ( '-j3' will fail )
137
+kerndeb () {
138
+    # temporarily unset MAKEFLAGS ( '-j3' will fail )
139
+    MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )		
140
+    print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
51 141
 	appendage='-custom' # this shows up in $ (uname -r )
52 142
     revision=$(date +"%Y%m%d") # this shows up in the .deb file name
53 143
 
... ...
@@ -57,4 +147,3 @@ dbb-build () {
57 57
         "$revision" kernel_image kernel_headers
58 58
 }
59 59
 
60
-
... ...
@@ -3,3 +3,58 @@ if [ "$commands[(I)hub]" ] && [ "$commands[(I)ruby]" ]; then
3 3
     # eval `hub alias -s zsh`
4 4
     function git(){hub "$@"}
5 5
 fi
6
+
7
+# Functions #################################################################
8
+
9
+# https://github.com/dbb 
10
+
11
+
12
+# empty_gh [NAME_OF_REPO]
13
+#
14
+# Use this when creating a new repo from scratch.
15
+empty_gh() { # [NAME_OF_REPO]
16
+    repo = $1
17
+    ghuser=$(  git config github.user )
18
+
19
+    mkdir "$repo"
20
+    cd "$repo"
21
+    git init
22
+    touch README
23
+    git add README
24
+    git commit -m 'Initial commit.'
25
+    git remote add origin git@github.com:${ghuser}/${repo}.git
26
+    git push -u origin master
27
+}
28
+
29
+# new_gh [DIRECTORY]
30
+#
31
+# Use this when you have a directory that is not yet set up for git.
32
+# This function will add all non-hidden files to git.
33
+new_gh() { # [DIRECTORY]
34
+    cd "$1"
35
+    ghuser=$( git config github.user )
36
+
37
+    git init
38
+    # add all non-dot files
39
+    print '.*'"\n"'*~' >> .gitignore
40
+    git add ^.*
41
+    git commit -m 'Initial commit.'
42
+    git remote add origin git@github.com:${ghuser}/${repo}.git
43
+    git push -u origin master
44
+}
45
+
46
+# exist_gh [DIRECTORY]
47
+#
48
+# Use this when you have a git repo that's ready to go and you want to add it
49
+# to your GitHub.
50
+exist_gh() { # [DIRECTORY]
51
+    cd "$1"
52
+    name=$( git config user.name )
53
+    ghuser=$( git config github.user )
54
+
55
+    git remote add origin git@github.com:${ghuser}/${repo}.git
56
+    git push -u origin master
57
+}
58
+
59
+# End Functions #############################################################
60
+