]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/ubuntu/ubuntu.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / ubuntu / ubuntu.plugin.zsh
1 (( $+commands[apt] )) && APT=apt || APT=apt-get
2
3 alias acs='apt-cache search'
4
5 alias afs='apt-file search --regexp'
6
7 # These are apt/apt-get only
8 alias ags="$APT source"
9
10 alias acp='apt-cache policy'
11
12 #List all installed packages
13 alias agli='apt list --installed'
14
15 # List available updates only
16 alias aglu='apt list --upgradable'
17
18 alias acsp='apt-cache showpkg'
19 compdef _acsp acsp='apt-cache showpkg'
20
21 # superuser operations ######################################################
22
23 alias afu='sudo apt-file update'
24
25 alias ppap='sudo ppa-purge'
26
27 alias age="sudo $APT"
28 alias aga="sudo $APT autoclean"
29 alias agb="sudo $APT build-dep"
30 alias agc="sudo $APT clean"
31 alias agd="sudo $APT dselect-upgrade"
32 alias agi="sudo $APT install"
33 alias agp="sudo $APT purge"
34 alias agr="sudo $APT remove"
35 alias agu="sudo $APT update"
36 alias agud="sudo $APT update && sudo $APT dist-upgrade"
37 alias agug="sudo $APT upgrade"
38 alias aguu="sudo $APT update && sudo $APT upgrade"
39 alias agar="sudo $APT autoremove"
40
41
42 # Remove ALL kernel images and headers EXCEPT the one in use
43 alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n`uname -r`))'
44
45 # Misc. #####################################################################
46 # print all installed packages
47 alias allpkgs='dpkg --get-selections | grep -v deinstall'
48
49 # Create a basic .deb package
50 alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
51
52 # apt-add-repository with automatic install/upgrade of the desired package
53 # Usage: aar ppa:xxxxxx/xxxxxx [packagename]
54 # If packagename is not given as 2nd argument the function will ask for it and guess the default by taking
55 # the part after the / from the ppa name which is sometimes the right name for the package you want to install
56 function aar() {
57         if [ -n "$2" ]; then
58                 PACKAGE=$2
59         else
60                 read "PACKAGE?Type in the package name to install/upgrade with this ppa [${1##*/}]: "
61         fi
62
63         if [ -z "$PACKAGE" ]; then
64                 PACKAGE=${1##*/}
65         fi
66
67         sudo apt-add-repository $1 && sudo $APT update
68         sudo $APT install $PACKAGE
69 }
70
71 # Prints apt history
72 # Usage:
73 #   apt-history install
74 #   apt-history upgrade
75 #   apt-history remove
76 #   apt-history rollback
77 #   apt-history list
78 # Based On: https://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
79 function apt-history() {
80   case "$1" in
81     install)
82       zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
83       ;;
84     upgrade|remove)
85       zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
86       ;;
87     rollback)
88       zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
89         grep "$2" -A10000000 | \
90         grep "$3" -B10000000 | \
91         awk '{print $4"="$5}'
92       ;;
93     list)
94       zgrep --no-filename '' $(ls -rt /var/log/dpkg*)
95       ;;
96     *)
97       echo "Parameters:"
98       echo " install - Lists all packages that have been installed."
99       echo " upgrade - Lists all packages that have been upgraded."
100       echo " remove - Lists all packages that have been removed."
101       echo " rollback - Lists rollback information."
102       echo " list - Lists all contains of dpkg logs."
103       ;;
104   esac
105 }
106
107 # Kernel-package building shortcut
108 function kerndeb() {
109   # temporarily unset MAKEFLAGS ( '-j3' will fail )
110   MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
111   print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
112   appendage='-custom' # this shows up in $(uname -r)
113   revision=$(date +"%Y%m%d") # this shows up in the .deb file name
114
115   make-kpkg clean
116
117   time fakeroot make-kpkg --append-to-version "$appendage" --revision \
118       "$revision" kernel_image kernel_headers
119 }
120
121 # List packages by size
122 function apt-list-packages {
123   dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
124   grep -v deinstall | \
125   sort -n | \
126   awk '{print $1" "$2}'
127 }