[nSLUG] Directory Maven

Joel Maxuel j.maxuel at gmail.com
Sat Apr 8 18:31:23 ADT 2017


Wow, that keeps things simple!  Thanks Oliver.  Just used it to search for
"bin" (as a  test) in my home space.  it came up with over 200 matches, and
it allowed me to choose from any of them!  I will adapt this for fish.

I guess I didn't know "select" existed - I was aware of "choose" in DOS,
and was reminded of that when I was working on this, but I guess I went to
design a "select" myself instead of asking the right question.

I should still note that the find process is slow for me.  Even my laptop
equipped with an SSD took several seconds to find all the bin's in
/home/joel (there is 140,000+ directories to compare names of because I
have some android source there, for example).  My main PC is why I
initially made the script/function below the current working directory.
With a mix of SSD and mechanical drives, the system as a whole contains
around 2.5 million directories (but surprisingly /home only taking up a
fifth of that).

I am, sort of wondering if there is a way to leverage the locate database
and return strictly directories.  I tried the -b parameter before, and it
returns files/folders below the matched directory (which isn't helpful to
me).  This could be used as a quick(er) "whole volume" directory
search/goto if I had the right option (which if there, would be
undocumented), but because I have daily backups[*] sent to a mounted RaidZ
tank via BackInTime (which makes lots of hard links), I would be dealing
with around 30 duplicates of what I would consider a unique-named
directory.  Unless I can get updatedb to ignore the tank in it's scan.


[*] Before I get a rant, this is not my backup solution.  This is just to
create copies to a redundant volume.  My actual backup involves portable
drives, SD cards and optical media at varying intervals, when appropriate.


--
Cheers,
Joel Maxuel

"One should strive to achieve, not sit in bitter regret."
 - Ronan Harris / Mark Jackson

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

> 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 : ßäöüÄÖÜ
>
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/pipermail/nslug/attachments/20170408/ea0e75e6/attachment.html>


More information about the nSLUG mailing list