Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active September 26, 2024 07:15
Show Gist options
  • Save Konfekt/63243655f116eb546d3fc67dfa345cb0 to your computer and use it in GitHub Desktop.
Save Konfekt/63243655f116eb546d3fc67dfa345cb0 to your computer and use it in GitHub Desktop.
apt / apt-* / dpkg command-line aliases
#!/bin/bash
command -v apt >/dev/null 2>&1 || return 1
# apt commands {{{
apt_commands=(
"ls list"
"cl changelog"
"se search"
"sh show"
"po policy"
"dp depends"
"rdp rdepends"
"if info"
"h help"
)
len=${#apt_commands[*]}
for (( i=1; i<len; i++ )); do
short=$(echo ${apt_commands[$i]} | cut -d' ' -f1)
full=$(echo ${apt_commands[$i]} | cut -d' ' -f2)
eval "alias a$short='apt $full'"
done
alias ahse="apt help search"
# }}}
# sudo apt commands {{{
alias sa='sudo apt'
sudo_apt_commands=(
"rm remove"
"arm autoremove"
"pu purge"
"ac autoclean"
"cl clean"
"es edit-source"
"ho hold"
"uh unhold"
)
len=${#sudo_apt_commands[*]}
for (( i=1; i<len; i++ )); do
short=$(echo ${sudo_apt_commands[$i]} | cut -d' ' -f1)
full=$(echo ${sudo_apt_commands[$i]} | cut -d' ' -f2)
eval "alias sa$short='sudo apt $full'"
done
sa="sudo apt"
# params="--no-install-recommends"
alias sain="$sa install --auto-remove $params"
alias saup="$sa update $params"
alias saug="$sa upgrade --with-new-pkgs $params"
alias safup="$sa full-upgrade $params"
alias sayin="$sa -y install --auto-remove $params"
alias sayup="$sa -y update $params"
alias sayug="$sa -y upgrade --with-new-pkgs $params"
alias sayfup="$sa -y full-upgrade $params"
alias sarmp="$sa remove --auto-remove --purge $params"
unset params
unset sa
# List Packages Repo
alpr(){ apt list --installed | grep "$1"; }
# }}}
# apt-get commands {{{
alias agdl="apt-get download"
alias agso="apt-get source"
alias sag="sudo apt-get"
sudo_apt_get_commands=(
"dl download"
"so source"
"ch check"
"bd build-dep"
"dsup dselect-upgrade"
"dug dist-upgrade"
)
# apt_get_commands+=( "${apt_commands[@]}" )
len=${#sudo_apt_get_commands[*]}
for (( i=1; i<len; i++ )); do
short=$(echo ${sudo_apt_get_commands[$i]} | cut -d' ' -f1)
full=$(echo ${sudo_apt_get_commands[$i]} | cut -d' ' -f2)
eval "alias sag$short='sudo apt-get $full'"
done
# }}}
saar() { sudo apt-add-repository -y "$1" && sudo aptitude update; }
# apt-cache commands {{{
alias ac="apt-cache"
alias acse='apt-cache search'
alias acpo='apt-cache policy'
alias acdp='apt-cache depends'
alias acrdp='apt-cache depends'
alias acsh='apt-cache show'
alias acshs='apt-cache showsrc'
# }}}
alias af="apt-file"
alias afls='apt-file list'
alias afse='apt-file search'
afsec() { apt-file search "$(command -v "$1")"; }
alias am="apt-mark"
alias pah="$PAGER /var/log/apt/history.log"
# dpkg commands {{{
command -v dpkg >/dev/null 2>&1 || return 1
alias sdpi='sudo dpkg -i'
alias dpL='dpkg -L'
alias dps='dpkg -s'
alias dpS='dpkg -S'
dpSw() { dpkg -S "$(command -v "$1")"; }
alias dplg='dpkg -l | grep -Ei'
# Build package downloaded with apt-get source after cd into it.
dpbp() ( dpkg-buildpackage -rfakeroot -uc -b )
# }}}
# ex: set foldmethod=marker:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment