Home Download Buy Blog Forum Support

Opening multiple files from command line with xargs

Opening multiple files from command line with xargs

Postby phillip.koebbe on Fri Dec 30, 2011 9:18 pm

I just did

Code: Select all
ack search_string -l | xargs subl


and all of the matching files were opened in an existing window. I checked subl --help and saw that -n instructs Sublime to open the file(s) in a new window, which is nice. Is there a way, other than an alias, to default to this behavior?
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Opening multiple files from command line with xargs

Postby hibbelig on Sat Dec 31, 2011 10:17 am

If you create a project, you can do Command+Shift+F (or Ctrl+Shift+F I guess) to search in the project. You might like it.

(What I like about it is that the list of search results is a normal buffer in the editor, and I can use code folding on it.)
hibbelig
 
Posts: 77
Joined: Wed Dec 21, 2011 11:24 pm

Re: Opening multiple files from command line with xargs

Postby svenax on Sat Dec 31, 2011 1:26 pm

phillip.koebbe wrote:I just did

Code: Select all
ack search_string -l | xargs subl


and all of the matching files were opened in an existing window. I checked subl --help and saw that -n instructs Sublime to open the file(s) in a new window, which is nice. Is there a way, other than an alias, to default to this behavior?


Is there a problem with using the argumet, like this?

Code: Select all
ack search_string -l | xargs subl -n
svenax
 
Posts: 154
Joined: Tue Dec 20, 2011 12:47 pm

Re: Opening multiple files from command line with xargs

Postby phillip.koebbe on Sat Dec 31, 2011 4:24 pm

svenax wrote:
phillip.koebbe wrote:I just did

Code: Select all
ack search_string -l | xargs subl


and all of the matching files were opened in an existing window. I checked subl --help and saw that -n instructs Sublime to open the file(s) in a new window, which is nice. Is there a way, other than an alias, to default to this behavior?


Is there a problem with using the argumet, like this?

Code: Select all
ack search_string -l | xargs subl -n


No, there's no problem, per se, and it's what I'm doing now. It's just a memory thing and it seems to make sense (to me anyway) to set as a default that which I will likely do more often than not. I know I can set an alias, which is fine, except for those times when I want to override the default. Since an alias is not the same thing as a default, when I want to use an existing window, I would be passing both arguments in, which seems a bit less than ideal.

Just a simple question, really. Just curious if a default could be set. Not a big deal.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Opening multiple files from command line with xargs

Postby phillip.koebbe on Sat Dec 31, 2011 4:29 pm

hibbelig wrote:If you create a project, you can do Command+Shift+F (or Ctrl+Shift+F I guess) to search in the project. You might like it.

(What I like about it is that the list of search results is a normal buffer in the editor, and I can use code folding on it.)


I used project-wide search in TextMate some times, but it was a memory hog on larger projects. I like using ack on the command line because it's pretty fast and I can quite easily narrow the scope to certain files. For example, if I'm looking for a particular string but I only want to search in JavaScript files, I can do

Code: Select all
ack --js somestring


Conversely, if I wanted to ignore JavaScript files, I could do

Code: Select all
ack --nojs somestring


I can also define my own "types" of files to search through, so if I wanted to search through all Rails related files in one shot, I could define something like:

Code: Select all
--type-set=rails=.rb,.js,.css,.haml,.feature,*_steps.rb,*_spec.rb


and then search with

Code: Select all
ack --rails somestring


Quite powerful really. And also off-topic :)
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Opening multiple files from command line with xargs

Postby hibbelig on Sat Dec 31, 2011 11:53 pm

Yes, file types à la ack would be really nice. I guess that entering "*.js" versus "js" doesn't make that much of a difference, but for file types with multiple extensions it becomes a burden.

Find in Files in Sublime Text is very fast, though. Please don't extrapolate from TextMate, please try it for yourself. Trying costs you a few minutes and afterwards you have learned something. And who knows, maybe if you submit feature requests they'll be implemented someday...
hibbelig
 
Posts: 77
Joined: Wed Dec 21, 2011 11:24 pm

Re: Opening multiple files from command line with xargs

Postby phillip.koebbe on Sun Jan 01, 2012 4:01 pm

hibbelig wrote:Yes, file types à la ack would be really nice. I guess that entering "*.js" versus "js" doesn't make that much of a difference, but for file types with multiple extensions it becomes a burden.

Find in Files in Sublime Text is very fast, though. Please don't extrapolate from TextMate, please try it for yourself. Trying costs you a few minutes and afterwards you have learned something. And who knows, maybe if you submit feature requests they'll be implemented someday...


I didn't mean to suggest that because find/replace in project was slow in TextMate that I assumed it would be slow in ST2. Rather, since I had that experience in TextMate, I found myself doing things another way (ack) which has become my standard and preferred way of doing things. I fully expect that one of these days I'll get around to experimenting with projects and find/replace, but so far, I haven't had a need to.

Thanks for your thoughts. I might just try to remember to try it out the next time I need to do something like this again.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Opening multiple files from command line with xargs

Postby hibbelig on Sun Jan 01, 2012 5:20 pm

I've been thinking about your original request again. What Jon could do is to add a command line switch "-1" (say) that does the opposite of "-n" and if both are passed on the command line, the last one wins. Then you could create an alias or shell function that always invokes "subl -n" and then it would work as you wanted:

Code: Select all
function pksubl () {
    subl -n "$@"
}


But as long as this isn't implemented, you could do it yourself. Hm... But difficult to get the command line parsing right. Oh, subl doesn't complain if you pass -1. So:

Code: Select all
function pksubl () {
    found=0
    for x in "$@"; do
        if [ "x$x" = "x-1" ]; then
            found=1
        fi
    done
    if [ "x$found" = "x1" ]; then
        subl "$@"
    else
        subl -n "$@"
    fi
}


I've only tested parts of this, not the whole thing. Maybe it works.
hibbelig
 
Posts: 77
Joined: Wed Dec 21, 2011 11:24 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 37 guests