In order to update the aliases for a per project install of homestead you need to manually run this script after starting up the vm for the first time. Is there a way to have this run during the initial provision similar to global installs of homestead. The after.sh bash file is used, but putting this script into that file doesn't work.
tr -d '\r' <~/.bash_aliases >~/tmp
mv ~/tmp ~/.bash_aliases
unalias -a
source .bash_aliases
Windows 10 (64-bit)
Not Applicable
Not Applicable
What should have happened?
The alias file included in the root folder of a per project install should be picked up and applied to bash aliases on provision similar to a global install of homestead.
What actually happened?
No aliases are included and instead a bunch of command not found errors are show when first entering the vm.
Accessing the vm each time afterwards produces a list of command not found messages for the exact number of aliases in the file so maybe it is being read, but due to some hidden characters it isn't being read properly. I've attempted to copy-paste and remove through bash any carriage returns (r), which seems to be the issue, but I can't seem to get passed this point. Would this be an issue related to using Windows versus Linux that could be resolved by running something over the alias file?
If you look at your Vagrantfile you should see this section:
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
This is where the aliases file is copied from your project root to ~/.bash_aliases in Homestead.
If you've edited this file on Windows with an editor that does not respect Linux end of line characters you may need to change the characters back.
Command line (inside Homestead:
awk '{ sub("\r$", ""); print }' /vagrant/aliases > /home/vagrant/.bash_aliases
I've confirmed this is an issue after editing the file. Thanks for the report.
TODO
We should potentially change
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
to
if File.exist? aliasesPath then
config.vm.provision "shell" do |s|
s.name = "Install ~/.bash_aliases"
s.inline = "awk '{ sub("\r$", ""); print }' /vagrant/aliases > /home/vagrant/.bash_aliases"
end
end
This would always install the file in the correct location with the proper formatting even if the user edits the file in an application that doesn't respect existing line endings.
Thanks @svpernova09 I applied that update to our Vagrantfile and it works great.
Most helpful comment
TODO
We should potentially change
to
This would always install the file in the correct location with the proper formatting even if the user edits the file in an application that doesn't respect existing line endings.