0

How can I make an alias either run a script in another directory or both cd and run the script?

I have commands in my .bashrc file to cd /home/myname/my_dir

and also

rake sunspot:solr:start  

when I am in our app directory (that contains the /script subdirectory).

I have not been able to put either put the directory in the rake command or have the alias do a cd and then the rake command that it currently does.

For instance I attempted rake /home/my_dir/out_code_directory/sunspot:solr:start RAILS_ENV=test but that didn't work.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

3 Answers3

2
alias rakesolr='cd dir; rake sunspot:solr:start; cd -'

works for me (in bash). Does that do what you need?

[ Ahh, semicolon ! Michael.]

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
Edd Steel
  • 719
  • 4
  • 16
0

Maybe can you edit your rake task ? Or you can make a new task that do a Dir.chdir and then execute the task wanted.

Edit : resource about execute a task within another here

Community
  • 1
  • 1
Thomas Guillory
  • 5,719
  • 3
  • 24
  • 47
0

Why not write a small bash script that cds then executes the script and have that run via an aliased command?

Tyler K
  • 526
  • 1
  • 4
  • 12