Indexing folders
At the very start, you often encounter no match found because lots of folders are still unknown to Zoxide... What if Zoxide could know all the most important folders at the very start ? It is possible to index the most useful folders in 3 steps: build a list by querying various places, filter the list, and finally index the items in the list. This page will guide you through these steps.
Warning: these commands have been designed for Linux and might not work for Window (mostly because of xargs missing). This part is optional, if you skip it, it will just need more time before all your useful folders are in Zoxide's database, but that's not a big deal.
Listing all courses folders
My /home/sam/HEIG folder contains year1, year2 and year3, each one contains one folder per course.
We only want folder (-t d = type directory), at maximum 2 folders depth, filter the final list with the word year to remove some random folders inside HEIG.
HEIG> fd -t d --max-depth 2 | grep year
year1/
year1/ANG1/
year1/ANG2/
year1/ARO/
year1/ASD/
year1/DTS/
year1/EXP/
...
year2/
year2/ARN/
year2/BDR/
year2/CLD/
year2/DAI/
year2/EAL/
year2/GRE/
year2/MAT3/
...
year3/
year3/AMT/
year3/DAA/
year3/MAC/
year3/PLP/
...
Listing all labs folders
We are doing the same but with more depth, only for labs folders, -P with grep means to enable the "standard regex mode" (here lab|project will match anything containing lab or project as I used these 2 folders names). We can accumulate several grep to make successive filters, we can also make inverse filters with -v (we don't want any path containing imgs, those are not labs).
HEIG> fd -t d --max-depth 4 --no-ignore | grep year | grep -P "lab|project" | grep -v "imgs"
year1/ARO/labos/
year1/ARO/labos/labo1/
year1/ARO/labos/labo2/
year1/ARO/labos/labo3/
...
year1/ASD/projects/
year1/ASD/projects/L1Complexite/
year1/ASD/projects/L2Recursivite/
year1/ASD/projects/L3Tris/
...
year1/ISI/labos/
year1/ISI/labos/labo0/
year1/ISI/labos/labo1/
year1/ISI/labos/labo2/
...
year2/BDR/projects/
year2/BDR/projects/l1/
year2/BDR/projects/l2/
year2/BDR/projects/l3/
...
year3/AMT/labos/
year3/AMT/labos/amtb-lab1-data-layer-amtb/
year3/AMT/labos/amtb-lab-reflection-samuelroland/
year3/AMT/labos/lab-dev-setup-blog-samuelroland/
...
Listing other folders
If you need more options on fd please check man fd or my cheatsheet (todo: coming one day). You can build a list with any tools or even manually, those are just examples...
Index folders of your list
When your lists are ready, we would like to run zoxide add x where x is each line one after the other. We don't want to use z here, because it would also jump into the folder, we just want to add to database. zoxide add only supports one path at a time and doesn't read from stdin, this is where xargs is really powerful, it reads lines from stdin (that we piped) and transform them as arguments to a given command.
Here is an example with the first list, piped into xargs
fd -t d --max-depth 2 --no-ignore | grep year | xargs -L 1 zoxide add
-L 1means we pass lines one by one, not all of them in a list because zoxide add only supports one folder at a time (unlike for ex.lsthat can be called with multiple elements likels course slides labsto show the content of these 3 folders).- We suppose here that all path do not contain spaces ! If they do, you can use
xargs -I _ zoxide add "_"instead to wrap the path with quotes around.
Verifications
After this, you should check with a few folders if it works, w would like to jump into the poulailler exo inside HEIG/year2/POO/projects, we only need to put the shortest matching pattern poul
sam> z poul
poulailler> pwd
/home/sam/HEIG/year2/POO/projects/poulailler
It works !
Another example where fuzzy finding is really powerful, is when we would like to jump into 3-tetris-2-interaction-wednesday-untrucrigolo WEB lab. There is 3 folders with the word tetris, but actually only one that contains tetris + 2 in this order. We can even shorten tetris to tet.
sam> ls HEIG/year2/WEB/projects
0-hello-world-samuelroland
1-html-css-samuelroland
2-tetris-1-js-wednesday-untrucrigolo
3-tetris-2-interaction-wednesday-untrucrigolo
4-multi-page-application-wednesday-untrucrigolo
5-tetris-3-websockets-untrucrigolo
sam> z tet 2
3-tetris-2-interaction-wednesday-untrucrigolo> pwd
/home/sam/HEIG/year2/WEB/projects/3-tetris-2-interaction-wednesday-untrucrigolo