-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
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.
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.
functions/to.fish
Outdated
@@ -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 ) |
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.
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.
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.
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) |
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.
Use fish's native string function instead of cut
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.
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
end | ||
end | ||
if not test $result | ||
echo 'there is no to-fish link for this dir' |
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.
"dir" -> "directory"
There could also be multiple bookmarks to the same location, so you should handle that as well and list them. |
I'm old - I just don't even think of directories with spaces or special chars in them! |
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). |
a break so duplicates are returned properly. The cuts are more useful than strings to keep both link and dir in the same variable.
can't figure out how to update a pull request with changes, I'll just open a new one |
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.