3

I'm trying to write a simple bash script, which when run from the command line, will cd into a default directory and then open up the folder in the file-browser:

#!/bin/bash

if [ -z "$1" ]
then
  # unless $1 is specified, cd into main proj
  cd code/ruby/my-main-proj
else
  # cd into project specified by $1
  cd code/ruby/$1
fi

# open folder in file manager    
pcmanfm .

This is great, it gives me two things:

  1. a command-prompt whose working directory is set to the project I want
  2. a file-browser for the same project

The trouble is that I would like to run my bash script by clicking on a desktop icon but in it's current form, the terminal does not open up, just the file browser..

So I've made a modification to try and get the terminal to open too:

then
  # unless $1 is specified, cd into main proj
  x-terminal-emulator -e "cd code/ruby/my-main-proj"
else
  # code same as before    

But while the terminal does open, it just displays a blank screen, with no prompt or PWD. How can I get a terminal to open up, and have it's working directory change to the one I'm trying to specify in my bash script?

4

I didn't get it to work with x-terminal-emulator, but with the standard gnome terminal.

user@MacBookPro:~$ gnome-terminal --working-directory=~/code/ruby/my-main-proj

Hope this helps.

  • ahh, thanks, the --working-directory flag seems to fix this – marflar Feb 13 '13 at 15:20
4

Your problem is that you're not executing a shell in your temrinal emulator, you're trying to execute cd, which is a shell command, not an actual shell (not even an actual executable for that matter).

You could make a desktop entry file that starts a shell in a custom working directory, like this:

MyProject.desktop:

[Desktop Entry]
Type=Application
Terminal=true
Exec=x-terminal-emulator
Path=/path/to/code/ruby/my-main-proj
Name=My Project

Note the Path=… above.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.