-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--index switch #48
--index switch #48
Conversation
Known bug: Directories lower in the directory tree will receive a higher rating, probably due to the way the _z --add command works. Caution is advised when using this, but I think this or something similar would probably be a good feature for z, as long as you know what you are getting yourself into.
@@ -29,6 +29,11 @@ _z() { | |||
|
|||
# bail out if we don't own ~/.z (we're another user but our ENV is still set) | |||
[ -f "$datafile" -a ! -O "$datafile" ] && return | |||
# Index subdirectories | |||
if [ "$1" = "--index"]; then | |||
find `pwd` -type d | while read line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a more effective way to go about this if you know the exact implementation of the --add-algorithm, I just had no time to look into that. As always, feel free to tweak it with your knowledge ;-)
+1 |
[FIXED] Ow. Please don't (blindly) merge this yet, as it still has bugs: bash: /bin/z: line 36: syntax error near unexpected token `fi'
bash: /bin/z: line 36: ` fi' (on startup of the console). |
I haven't tested it, but if it's going to be used, I suggest to put double quotes around |
What difference would that make? Honest question, I am pretty new to Shell Code, (perhaps 2 weeks on Linux) as you might see from my code ;-) |
Congratulations on finding z besides so short time spent. :) Hm, I took a look once again and that $line should be double quoted too. On most UNIX-like file systems file name can contain any character besides '\0' (null) and '/'. Even some "special" characters, like a space, * and a newline are allowed, which means your snipped would break if: a) directory structure contains a character used by the shell to split parameters, for example a space: if pwd is "/abc/x y", then `pwd` or $PWD would be two args: "/tmp/x" and "y", which is bad; "`pwd`" or "$PWD" correctly one: "/abc/x y"; b) if it's named, for example, *: * is a glob meaning "all items (excl. those with start with a dot)". Try yourself: mkdir '/tmp/*'; cd '/tmp/*'; ls -l `pwd` (compare with ls -l "`pwd`"); c) your while read line snippet reads find output line by line which means it would not behave correctly if a directory contains a newline :) - find … -exec … should fix it (entries with newlines seem to be pruned from z's datafile anyway). PS Sorry for stupid formatting but I'm not keen on fighting with this shiny markup to preserve what I actually wrote. |
…so rewrite the script to use the -exec option of find, which is probably better than my previous implementation.
Although this is a small change, and I appreciate the pull request, I'm not inclined to merge it. It doesn't seem like something enough people would need often enough to justify an option (and I begrudge options). In addition, indexing a directory would set each subdir to a rank of 1 - see #53 about how that would probably lead to almost all of the indexed directories being dropped from the datafile rather quickly, en masse. I'm also don't think it works
throws an error cause of the single quotes (but you don't need to start a subshell anyway - see below). I think this is a pretty cool way to deal with a potential use case, but I think it's more suited as something to throw in the wiki, possibly in a for loop, like:
|
I added a new Switch, --index, to index all subdirectories of the current dir. Might be useful if you have a massive folder structure you want indexed, but dont want to go through them by hand.
Known bug: Folders lower in the folder structure seem to rated higher, probably due to the way z's ranking and counting works.
Feel free to improve or reject this, I just thought this to be a useful feature.