Alex Coplan
Alex Coplan

Reputation: 13371

How to open an app in terminal and passing the current working directory?

I often want to open the entire directory I'm working in by using the mate command, but how do I pass in the working directory itself?

For example, if I'm working in a rails app and I want to open the app folder into the TextMate tree, I would do mate app, but how could I pass in the working directory itself (i.e. open the entire rails app in the tree)?

Upvotes: 16

Views: 55020

Answers (7)

kenorb
kenorb

Reputation: 166419

The current working directory as set by the cd command is available in shell variable PWD, e.g.

echo $PWD

Upvotes: 1

nvvetal
nvvetal

Reputation: 1793

DIR=$(readlink -f $0);
IFS='/' read -a array <<< "$DIR";
apath=("${array[@]:0:${#array[@]}-1}");
rpath=$(IFS=/ ; echo "${apath[*]}");
cd $rpath

Upvotes: 1

alk
alk

Reputation: 70931

# Assign the current work directory to the bash script variable 'CWD'.
CWD=$(pwd)

# Print it.
printf "%s\n" ${CWD}

Upvotes: 36

Mattias Wadman
Mattias Wadman

Reputation: 11425

mate . will open the currently directory. I use the . directory a lot, for example open finder for the current directory open ..

Upvotes: 6

Pikaurd
Pikaurd

Reputation: 1124

mate `pwd`/yourfile

mate `pwd`/app

Or you can using mate $PWD/app

Upvotes: 4

fge
fge

Reputation: 121710

Getting the current directory is as simple as typing pwd, or echo $PWD.

Now, if you want to open TextMate in a particular directory, you can do:

(cd /target/directory && mate)

Upvotes: 4

JohnRos
JohnRos

Reputation: 1247

The command you might be looking for is

pwd

Upvotes: 58

Related Questions