Skip to content

Conversation

@gungun974
Copy link

@gungun974 gungun974 commented Oct 30, 2024

This is an early hack of my personal edit of tmux-sessionizer.

I did some "voodoo magic" with bash arrays a long time ago, and I know it's not ideal.

This implementation performs a recursive search to create a list when .tmux-scan is present and will ignore .tmux-exclude in the search.

I'll write a proper PR message later since I still have work to do, but I thought you might be interested in something like this.

gungun974 and others added 2 commits October 30, 2024 18:50
… include sub directory and ".tmux-exclude" to ignore directory as project
@gungun974
Copy link
Author

gungun974 commented Oct 30, 2024

Example

Here is my lab project structure:

.
├── foss
│   ├── neovim
│   └── .tmux-exclude
├── perso
│   ├── Melodink
│   └── .tmux-scan
└── work
    ├── myFirstClient
    │   ├── ProjectA
    │   ├── ProjectB
    │   └── .tmux-scan
    ├── mySecondClient
    │   ├── ProjectC
    │   └── .tmux-scan
    └── .tmux-scan

Here what fzf give me :

/home/gungun974/lab/work/mySecondClient/ProjectC
/home/gungun974/lab/work/myFirstClient/ProjectB
/home/gungun974/lab/work/myFirstClient/ProjectA
/home/gungun974/lab/perso/Melodink

The ROOT env is set to $HOME/lab in my example

@Blechlawine
Copy link

You could probably achieve something similar by just using find, like what i did in my version:
https://github.com/Blechlawine/dotfiles/blob/b30b5148146ad0f6626a7a1af2417daea85234f6/home/.local/bin/tmux-sessionizer#L11

I just used find to get all .git files and directories and then get their parent dir with dirname

@gungun974
Copy link
Author

You could probably achieve something similar by just using find, like what i did in my version: https://github.com/Blechlawine/dotfiles/blob/b30b5148146ad0f6626a7a1af2417daea85234f6/home/.local/bin/tmux-sessionizer#L11

I just used find to get all .git files and directories and then get their parent dir with dirname

Initially, I also thought I could do this scan using only find.

My issue is that find is a program designed to do a complete exploration of all existing directories, and in the context of projects that can contain folders like node_modules where many subdirectories are present. This makes find slow.

The solution would seem to be limiting find to a certain depth, but this would block the principle that the basic scan applies in subdirectories when the scanned folder contains .tmux-scan.

So a manual exploration of each directory to scan with my search_roots_directories_scan function is ultimately more efficient and, after all, not that complicated. (I'd say it's a textbook case of recursion)

@gungun974
Copy link
Author

However, if I were to make a self-critique of my PR, I think the part about excluding certain directories with .tmux-exclude could be done more efficiently and without black regex magic.

For now, my implementation, which was sufficient for my personal use, relies on first determining the list of directories to skip, then generating a hellish regex with only the paths that need to be ignored, and then passing everything through ripgrep to erase them from the list.

So this code should probably be replaced before this PR is merged (or not).

I will probably look into this on Sunday, but before that, I'm mainly interested in whether @ThePrimeagen is interested in my concept of files that recursive sub-scan with .tmux-scan or if it's something too "advanced" for his project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants