Sublime Forum

Opening multiple files from command line with xargs

#1

I just did

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?

0 Likes

#2

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.)

0 Likes

#3

[quote=“phillip.koebbe”]I just did

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?[/quote]

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

ack search_string -l | xargs subl -n
0 Likes

#4

[quote=“svenax”]

[quote=“phillip.koebbe”]I just did

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?[/quote]

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

ack search_string -l | xargs subl -n [/quote]

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.

0 Likes

#5

[quote=“hibbelig”]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.)[/quote]

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

ack --js somestring

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

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:

--type-set=rails=.rb,.js,.css,.haml,.feature,*_steps.rb,*_spec.rb

and then search with

ack --rails somestring

Quite powerful really. And also off-topic :smile:

0 Likes

#6

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…

0 Likes

#7

[quote=“hibbelig”]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…[/quote]

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.

0 Likes

#8

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:

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:

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.

0 Likes