Homestead: Alias file is not used in per project installs

Created on 14 Dec 2016  路  4Comments  路  Source: laravel/homestead

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

Versions

  • Vagrant: 1.9.1
  • Provider: Virtualbox 5.1.10
  • Homestead: 0.6.0

Host operating system

Windows 10 (64-bit)

Homestead.yaml

Not Applicable

Vagrant up output

Not Applicable

Expected behavior

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.

Actual behavior

What actually happened?
No aliases are included and instead a bunch of command not found errors are show when first entering the vm.

Steps to reproduce

  1. Install per project Laravel project with homestead dependency as per docs
  2. Add alias file to root of the project
  3. vagrant up and aliases aren't added
bug

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m4olivei picture m4olivei  路  4Comments

mattmcdonald-uk picture mattmcdonald-uk  路  3Comments

Quix0r picture Quix0r  路  4Comments

yazeed picture yazeed  路  3Comments

cschoeni picture cschoeni  路  4Comments