Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2015 09:50
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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`!
# else (if it is not a file) just print the full `type` message, it is informative
type $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment