I had finessed in bash a function that changes to any directory below the current working directory by having that directory name as a parameter to the function. If there are multiple results by that name, a menu appears to allow the user to choose the intended destination. The bash code is:

function cdb() {
  select dir in $(find -type d -name "$1" -not -path '*/\.*' -prune);
  do
    cd "${dir}" && break;
  done 
}

An example it of at play would be:

android@cybaryme:~/octos$ cdb av
1) ./frameworks/av
2) ./system/bt/bta/av
#? 1
android@cybaryme:~/octos/frameworks/av$

I use fish most of the time though, and would like to have this function there as well. But for the life of me I cannot find the select command, or its equivalent. Possibly thought that "complete" would do the job, but I got confused over what it is for.

Can anyone shed light on what is available? Or maybe an example of a Perl script that can shim the missing gaps?

up vote 1 down vote accepted

Fish does not have a select command. Nor can I find any indication that anyone has requested it be added. You can find an example of how to do the equivalent in a couple of the functions that ship with fish as well as my mcd function which will probably be added to the core package. Note that my implementation allows selecting by number or letter which is a pretty useful convenience. Feel free to open an enhancement request.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.