简体   繁体   English

gnome-terminal new tab,别名为执行命令

[英]gnome-terminal new tab with alias as command to execute

I've created an alias in .bashrc file as follows 我在.bashrc文件中创建了一个别名,如下所示

alias myproject = 'cd ~/Desktop/myproject'

After saving the file when I restart my terminal, typing in myproject takes me to the project directory but when I try to use the alias as a command argument to a new gnome-terminal tab it throws an error, 在我重新启动终端时保存文件后,输入myproject我带到项目目录,但是当我尝试将别名用作新gnome-terminal选项卡的命令参数时,它会抛出错误,

gnome-terminal --tab -e "myproject"

throws the error 抛出错误

There was an error creating the child process for this terminal
Failed to execute child process "myproject" (No such file or directory)

What is wrong with this ? 这有什么问题?

When a bash shell is started, per default bash executes the commands specified in .bashrc . 启动bash shell时,默认bash执行.bashrc指定的命令。 This is how your shell knows your alias es. 这就是你的shell如何知道你的alias

Now your idea does not work because gnome-terminal never sees your .bashrc file. 现在你的想法不起作用,因为gnome-terminal永远不会看到你的.bashrc文件。

You could try 你可以试试

gnome-terminal --working-directory='<path-to-your-home-directory>/Desktop/myproject/

I was trying to do something similar... possibly not exactly what you want, but: 我试图做类似的事情...可能不完全是你想要的,但是:

alias startMyRailsProject='cd ~/Desktop/myproject; gnome-terminal --tab --tab -e "rails s" --tab -e "rails c"; exit'

This: - changes directory to where I want - starts a new gnome terminal (in the right directory from before) - creates a 2nd tab and starts my rails server - creates a 3rd tab and starts my rails console - and then closes the original terminal window which I call it from. 这: - 将目录更改为我想要的位置 - 启动一个新的gnome终端(在之前的正确目录中) - 创建第二个选项卡并启动我的rails服务器 - 创建第三个选项卡并启动我的rails控制台 - 然后关闭原始终端我称之为的窗口。
It does what I need it to and saves a bunch of repetive keystrokes :-) Cheers 它做了我需要它并保存了一堆重复击键:-)干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM