[nSLUG] Directory Maven

Oliver Doepner odoepner at gmail.com
Sat Apr 8 11:43:59 ADT 2017


Here is a version that excludes all paths that have path segments starting
with a dot:

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


On Sat, Apr 8, 2017 at 11:08 AM, Oliver Doepner <odoepner at gmail.com> wrote:

> You can also use the "select" bash builtin for picking from the list:
>
> function cdb() { select dir in $(find -type d -name "$1"); do cd "${dir}"
> && break; done  }
>
> You might want to tweak this to exclude subdirectories that start with a
> dot.
>
>
>
>
> On Wed, Apr 5, 2017 at 10:38 PM, Joel Maxuel <j.maxuel at gmail.com> wrote:
>
>> Hi all,
>>
>> At this past social meeting, Richard and I sat down and shared some notes
>> and files regarding DOS, and running it in VirtualBox.  One of the programs
>> that really caught my eye is Directory Maven.  This program allows you to
>> change directory to any location on the drive, at the command line, by
>> typing a single keyword as parameter (as in, does not need the whole
>> path).
>>
>> I was curious if this could be duplicated or at least mimicked in some
>> way, I think I have something of interest now, called "cdb" or Change
>> Directory Below.
>>
>> For bash users (in .bashrc) - dumb method:
>>
>> cdb() {
>>        cd `find . -type d -name $1 -print -quit 2> /dev/null`;
>> }
>>
>> For bash users (in .bashrc) - smarter method:
>>
>> cdb() {
>>         find . -type d -name "$1" 2> /dev/null > ~/.config/dirmaven.tmp ;
>>         dirmaven ~/.config/dirmaven.tmp ;
>>         cd `cat ~/.config/dirmaven.tmp` ;
>> }
>>
>> For fish (in ~/.config/fish/functions/cdb.fish) - smarter method:
>>
>> function cdb
>>     find . -type d -name "$argv" 2> /dev/null > ~/.config/dirmaven.tmp ;
>>     dirmaven ~/.config/dirmaven.tmp
>>     cd (cat ~/.config/dirmaven.tmp) ;
>> end
>>
>> The smarter method(s) require a program in your path...source code linked
>> below:
>> https://pastebin.com/Jfs3QXk6
>>
>> The "dumb" method automatically chooses the first result.  The "smarter"
>> method allows you to choose from up to 16 results.  Also, there seems to be
>> basic expressions (wildcards) in both, but in fish you have to quote the
>> parameter or an error will occour.
>>
>> Example:
>>
>> joel at cybaryme ~> cdb "*8916*"
>> Multiples found.  Pick a directory:
>> 1. ./Build/github/proprietary_vendor_asus/msm8916-common
>> 2. ./Build/github/proprietary_vendor_asus/msm8916-common/propri
>> etary/etc/firmware/8916_volte_modem
>> 3. ./Build/github/android_device_asus_msm8916-common
>> 4. ./Build/github/android_kernel_asus_msm8916
>> #?: 3
>> joel at cybaryme ~/B/g/android_device_asus_msm8916-common> cdb sepolicy
>> joel at cybaryme ~/B/g/a/sepolicy>
>>
>> Only caveat I have left (besides the quotes for fish thing) is that it
>> can be quite slow if very high up in the directory tree (like /home or /).
>> YMMV.
>>
>> Also, I know there is a potential bug with my pascal code, if anything
>> but a number is typed in.  I may get around to type/error handling.
>>
>> Finally, if you want to pick this for yourself, you are free to do
>> anything with it.
>>
>> Enjoy!
>>
>> --
>> Cheers,
>> Joel Maxuel
>>
>> "One should strive to achieve, not sit in bitter regret."
>>  - Ronan Harris / Mark Jackson
>>
>> _______________________________________________
>> nSLUG mailing list
>> nSLUG at nslug.ns.ca
>> http://nslug.ns.ca/mailman/listinfo/nslug
>>
>>
>
>
> --
> Oliver Doepner
> Halifax, Nova Scotia
> http://oliver.doepner.net/
> Buchstabensalat : ßäöüÄÖÜ
>



-- 
Oliver Doepner
Halifax, Nova Scotia
http://oliver.doepner.net/
Buchstabensalat : ßäöüÄÖÜ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/pipermail/nslug/attachments/20170408/7ebf80ff/attachment.html>


More information about the nSLUG mailing list