16

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

kenorb
  • 155,785
  • 88
  • 678
  • 743
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138

7 Answers7

58

The command you might be looking for is

pwd
JohnRos
  • 1,091
  • 2
  • 10
  • 20
36
# Assign the current work directory to the bash script variable 'CWD'.
CWD=$(pwd)

# Print it.
printf "%s\n" ${CWD}
alk
  • 69,737
  • 10
  • 105
  • 255
6

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

Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
4

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)
fge
  • 119,121
  • 33
  • 254
  • 329
4
mate `pwd`/yourfile

mate `pwd`/app

Or you can using mate $PWD/app

Pikaurd
  • 1,114
  • 1
  • 8
  • 22
1
DIR=$(readlink -f $0);
IFS='/' read -a array <<< "$DIR";
apath=("${array[@]:0:${#array[@]}-1}");
rpath=$(IFS=/ ; echo "${apath[*]}");
cd $rpath
nvvetal
  • 1,756
  • 1
  • 17
  • 19
1

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

echo $PWD
kenorb
  • 155,785
  • 88
  • 678
  • 743