---
title: A Bash function for finding your Bash functions
date: 2015-03-21 16:44
slug: a-bash-function-for-finding-your-bash-functions
categories:
- Code
tags:
- bash
- where
- scripting
- terminal
---

[where]: /projects/where/
[gh]: https://github.com/ttscoff/where/

![](https://brettterpstra.com/images/projecticons/where-full.png)

As you may have noticed if you've followed this blog lately, I write a _lot_ of Bash functions and aliases. I keep them in distinct files using a plugin system based on [bash-it](https://github.com/Bash-it/bash-it). It works really well, and makes upkeep simple. However, I very often lose track of exactly where I defined a function or alias after a few months go by.

Unix commands like `type` and `which` will tell you where executable scripts and binaries are, but they'll fail finding a function. Thus, ["where"][where] was born. It's a Bash function that indexes every function and alias in any files that are sourced during login. Then you can type `where func_name` and find out exactly where a function or alias was defined. If a function/alias appears multiple times in your sourced files, the last version sourced (and thus likely the one Bash will default to) will win.

`where` has options for degrees of fuzzy search, too. You can use `-k` (aliased to `where?`) to find any functions _containing_ the search string. There's `-a` (or `where*`) to do a completely fuzzy search of the index as well.

The search will fall back to using `type` if there are no results in its index, so it becomes a universal command for me, replacing `which` and `type` for the most part.

The basic command outputs a full path (with :lineno) if a match is found. In iTerm, you can just ⌘-click that to edit the file. You can also use a `-E` flag to immediately open a match in your `$EDITOR`.

The fully-automatic version hooks the builtin `source` command. (There are included routines for taking a more manual approach as well.) Because hooking the `source` command and parsing every file you load can be slow, the index that `where` creates can be cached with any expiration time you want. See [the project page][where] for more info.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
