I want to add an alias file to my project folder to quickly open and edit files in it with a simple shell command.
To make it more portable, I would like to use only relative paths.
I want something like this:
### .profile
source /my/project/folder/aliases.bash
and
### aliases.bash
alias editprojectfiles="edit [/my/project/folder/]afile.txt"
The problem for me now is how to retrieve [/my/project/folder/]
automatically.
I tried to use $PWD
variable, but the result is that the alias points to the folder of .profile
file and not the aliases.bash
ones.
Is there a way to get this?
UPDATE
Some user point me out to the $PWD
solution.
This does not work, since the $PWD
variable is relative to the path of the source
command, not to the project one.
So I doing this
### .profile
$~/>source /my/project/folder/aliases.bash
### aliases.bash
alias editprojectfiles="edit $PWD/afile.txt"
Will create an alias like this
editprojectfiles="edit /my/user/home/folder/afile.txt"
And doing this
### Call source from folder /foo/bar
$/foo/bar>source /my/project/folder/aliases.bash
### aliases.bash
alias editprojectfiles="edit $PWD/afile.txt"
Will create an alias like this
editprojectfiles="edit /foo/bar/afile.txt"
alias
command? As it is youraliases.bash
file is actually defining environment variables, not aliases.alias
in copy&paste. Fixed it now.