Skip to content
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

added a 'here' function to show 'to' for pwd #12

Closed
wants to merge 4 commits into from

Conversation

brynjsmith
Copy link

I have accidentally added duplicate 'to' bookmarks to several directories, so I added a 'here' function to show if a bookmark already points to pwd, and if it does, what it is.

Copy link
Owner

@joehillen joehillen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea! I've been in situations where I needed this, but I didn't think to add a command for it. Thank you.

@@ -68,6 +69,22 @@ function __to_ls
end
end

function __to_here
set -x currentdir (pwd)
set -x wholepath (ls -l ~/.tofish | grep $currentdir | cut -d':' -f 2 | cut -d' ' -f 2,4 )
Copy link
Owner

@joehillen joehillen May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $TO_DIR instead of hardcoding ~/.tofish.

grep will match subdirectories of $currentdir

I think this won't work if any of the paths contain spaces. Consider using stat instead of trying to parse the output of ls. I think you should iterate through the links in ~/.tofish and match realpath of the link destination as it could be a link to a link.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the grep to match $currentdir gets all of its subdirs, yes, then the the inner loop refines to make sure it doesn't have any of the subs, that it only matches pwd

set -x currentdir (pwd)
set -x wholepath (ls -l ~/.tofish | grep $currentdir | cut -d':' -f 2 | cut -d' ' -f 2,4 )
for line in $wholepath
set -x inner (echo $line | cut -d' ' -f 2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fish's native string function instead of cut

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found a way to keep two fields together, like in line 74 the second 'cut' keeps fields 2 and 4 to get the simlink and the subdir. When the inner loop finds the dir(s) from field 4 of that cut, it just uses field 2 as the answer.

functions/to.fish Outdated Show resolved Hide resolved
end
end
if not test $result
echo 'there is no to-fish link for this dir'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dir" -> "directory"

@joehillen
Copy link
Owner

There could also be multiple bookmarks to the same location, so you should handle that as well and list them.

@brynjsmith
Copy link
Author

I'm old - I just don't even think of directories with spaces or special chars in them!
I like the other suggestions.
I'll poke at strings some more and see if I can get it to work a bit better, I'll get back to you.

@brynjsmith
Copy link
Author

I took out a 'break' that had stopped once one answer was found, so now it returns all of the TOs for the dir (but still not the subdir).
I'll keep thinking about dirnames with spaces in them, but it's not something I've considered much.

a break so duplicates are returned properly. The cuts are more useful
than strings to keep both link and dir in the same variable.
@brynjsmith brynjsmith changed the title added a 'here' function to show bm for pwd added a 'here' function to show 'to' for pwd Jun 17, 2024
@brynjsmith
Copy link
Author

can't figure out how to update a pull request with changes, I'll just open a new one

@brynjsmith brynjsmith closed this Jun 17, 2024
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.

None yet

2 participants