#
fish snippet of the day: in-place arrays & ‘i’m feeling lucky’ searches
Suppose you want to search for a file, and view its contents in a single shell invocation (a bit like google’s “i’m feeling lucky” feature). In fish, you can, if you know the filename, do this:
open (mlocate FOO)[1]
If you want to search for contents, you can do something like
open (grep -rl FOO)[1]
Maybe you are searching normally and find that you were lucky! (the first item found was the file you were looking for :) ). You can recall the history and apply this trick. But it’s better if you have a function for that:
function iwaslucky
open (eval (echo "$history[2]"))[1]
end
This function only works if the last command you’ve executed was the search, and will fail otherwise.
I’ll keep exploring the possibilities of fish scripting.
This was posted 1 year ago. It has 0 notes and 0 comments.