Skip to content

Instantly share code, notes, and snippets.

@NIA
Created March 19, 2015 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NIA/653fcbce8a284b347242 to your computer and use it in GitHub Desktop.
Save NIA/653fcbce8a284b347242 to your computer and use it in GitHub Desktop.
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