On how to write this alias:
The alias does not need to open the files separately - gedit
can take multiple files.
alias a="gedit ~/Desktop/abc/test1.c ~/Desktop/xyz/test2.c"
This also replaces the path of your home directory by ~
. If it should work for other users, use ~konstantinosubuntu
instead of the ~
.
To make the command independent of the terminal, so that it keeps running if you close the terminal, you can add &
to run it in the background, and nohup
to make it not exit when the terminal closes:
alias a="nohup gedit ~/Desktop/abc/test1.c ~/Desktop/xyz/test2.c &"
On the syntax of your example:
The problem with the &&
is that the &&
needs to be put at the end of the previous line. Otherwise the end of the line is just the end of the command - no problem so far - and the start of the next line has a "&&" that makes no sense in this place.
alias a="
cd /home/konstantinosubuntu/Desktop/abc && gedit test1.c &&
cd /home/konstantinosubuntu/Desktop/xyz && gedit test2.c"
As alternative, the whole alias could be put in one line. Or, very similar, a line continuation with \ at the end of the line could be used. That would be writing it as two lines, but executing it as one line, logically.
You note in your comments that the first gedit
needs to be closed before the second file is opended, and that you do not want this. The command gedit file.txt
runs gedit
in foreground if it's the first instance. If gedit
is already running, it opens a new tab in that instance, and exits. To make the alias open both files in gedit at the same time, run the first instance in background with &
. That does not work together with &&
, that needs to be removed:
alias a="
cd /home/konstantinosubuntu/Desktop/abc && gedit test1.c &
cd /home/konstantinosubuntu/Desktop/xyz && gedit test2.c"
(Interesting how it is only different by one character, but very different in meaning.)
In case you intended to have multiple current working directories in some way associated with the running gedit
by using the cd
commands, that can not work. A process has exactly one current working directory. It will be the one of the first gedit
instance here.
Just to be clear after discussing these examples, I think you should better use something like in the first section, opening one gedit
with multiple files at once.