Created
July 12, 2023 22:54
-
-
Save chrisranderson/481e177f926d348a587ca6cadfc76b40 to your computer and use it in GitHub Desktop.
which all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function which_all() { | |
| # Like `which`, but prints each location it finds | |
| # on $PATH, not just the first one. zsh only. | |
| # | |
| # Example: | |
| # > which_all conda | |
| # /opt/homebrew/Caskroom/miniconda/base/bin/conda | |
| # /opt/homebrew/Caskroom/miniconda/base/condabin/conda | |
| # /opt/homebrew/bin/conda | |
| typeset -A which_results | |
| query=$1 | |
| for path_entry in ${(s/:/)PATH}; do | |
| query_path="${path_entry}/${query}" | |
| if [ -x "${query_path}" ]; then | |
| # We are treating this associative array | |
| # as a set; we only need the keys. | |
| which_results[${query_path}]="throwaway_value" | |
| fi | |
| done | |
| which_results_keys=("${(@k)which_results}") | |
| for which_result in "${which_results_keys[@]}"; do | |
| echo "${which_result}" | |
| done | sort | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment