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

旧街凉风 提交于 2019-12-08 14:44:27

问题


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


回答1:


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




回答2:


The command you might be looking for is

pwd



回答3:


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

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



回答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)



回答5:


mate `pwd`/yourfile

mate `pwd`/app

Or you can using mate $PWD/app




回答6:


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



回答7:


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

echo $PWD


来源:https://stackoverflow.com/questions/8635456/how-to-open-an-app-in-terminal-and-passing-the-current-working-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!