Skip to content

Instantly share code, notes, and snippets.

@NIA
Created Mar 19, 2015
Embed
What would you like to do?
whichpkg: who installed this command?
# whichpkg: which package installed this command?
# Detects builtins and follows symlinks. Add the code below to .bashrc/.bash_aliases
# Usage examples:
#
# nia$ whichpkg vim
# vim-gtk: /usr/bin/vim.gtk
#
# nia$ whichpkg type
# type встроена в оболочку
#
# nia$ whichpkg ll
# ll является алиасом для `ls -lh'
#
# nia$ whichpkg foobarbaz
# No such command: foobarbaz
whichpkg() {
the_type=$(type -t $1)
if [[ -z $the_type ]]; then
echo No such command: $1
elif [[ "file" == $the_type ]]; then
# readlink -f: Follow all symlinks till the end
dpkg -S $(readlink -f $(type -p $1)) # NB: avoid `which` in favor of `type -p`! http://stackoverflow.com/a/677212/693538
else
# else (if it is not a file) just print the full `type` message, it is informative
type $1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment