Home Download Buy Blog Forum Support

Command line opening should use project

Command line opening should use project

Postby phillip.koebbe on Sun Apr 08, 2012 2:50 pm

I tend to navigate to a project folder on the command line and then open the current folder with

Code: Select all
subl .


If there is a project file in the folder, it is ignored. It would be nice if ST2 would use the project file and open the project without having to use the --project switch.

http://sublimetext.userecho.com/topic/105061-/
-- 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: Command line opening should use project

Postby vojtajina on Fri Jun 08, 2012 5:25 am

+1 for this request

I've been using this shell scripts in meantime:

Code: Select all
#!/bin/sh

if test $1; then
  # passing args -> open given file
  sublime $@
else
   # no arguments
   PRJ=`find . -iname *.sublime-project`
   if test $PRJ; then
      # project exists in current folder, open it
      sublime --project $PRJ
   else
      # no project, open current folder
      sublime .
   fi
fi
vojtajina
 
Posts: 6
Joined: Tue Mar 13, 2012 8:27 am

Re: Command line opening should use project

Postby phillip.koebbe on Fri Jun 08, 2012 6:07 pm

*facepalm*

Writing a wrapper script didn't even occur to me.

*sigh*
-- 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: Command line opening should use project

Postby phillip.koebbe on Mon Jun 11, 2012 2:14 pm

Using @vojtajina's script as a starting point, I tweaked it until I came up with something that works well for me. I thought I'd share it just in case someone else might find it useful.

Code: Select all
#! /bin/bash

if [ -z $@ ]; then
   # no arguments, let's just open sublime
   sublime
elif [ $1 != '.' ]; then
   # passing args and $1 is not a .
   sublime $@
else
   # look for a project file ... redirect stderr to /dev/null so
   # we won't see the error message if the file does not exist.
   # changed this from `find . -iname *.sublime-project` because
   # that does a recursive find which is problematic when wanting
   # to open something like a home directory (recursively looks
   # for all sublime projects ... not good). this also assumes
   # there will at most one project file in a directory. not sure
   # why someone might have more, but if they do, they should
   # specify on the command line which one they want to open

   PROJECT=`ls *.sublime-project 2>/dev/null`

   # added quotes around $PROJECT to account for spaces and such
   # in the file name
   if [ -e "$PROJECT" ]; then
      # project exists in current folder, open it
      sublime . --project "$PROJECT"
   else
      # no project, open current folder
      sublime .
   fi
fi


Two things:

1) This script works on Mac OS X 10.7.4. I make not guarantees it will work unmodified anywhere else.
2) This script depends on a symlink in your path as such:

Code: Select all
sublime -> /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl
-- 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


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests

cron