Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Homestead Per Project Install Bash Aliases Commands Not Found

I've created a per project install of Homestead. I've included after.sh (in the root directory) to provision other packages like RethinkDB with no issues, but the aliases file (also in root directory) though appearing in the VM as ~/.bash_aliases isn't running any of the aliases when I'm type them in. So for example these aliases:

alias artisan='php artisan'
alias autoload='composer dump-autoload'

In the command prompt as:

artisan migrate:refresh --seed
autoload

Throw these errors:

Could not open input file: artisan
autoload: command not found

This happens for any of the aliases I try. I've checked that ~/.bash_aliases (or /home/vagrant/.bash_aliases) exists using nano, and it is definitely a copy of aliases. Just none of the commands are being used as if it doesn't exist or as if the file though in the right spot is inaccessible.

Anyone know why? or how to fix this? It's amazing how annoying not being able to use the aliases I typically would use locally, or on global install of Homestead when using this VM.

UPDATE

I noticed I get a list of command not found errors when I SSH into the VM that equal the number of aliases I've included. The same list appears if I run source ~/.bash_aliases. For complete clarity .bash_aliases is located in /home/vagrant next to the mapped source folder /home/vagrant/app, and the output from SSHing into the VM, and the associated aliases file are included:

SSH into VM

$ vagrant ssh
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-25-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Mon Feb 15 00:37:39 2016 from 10.0.2.2
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
vagrant@app:~$

Aliases File

# Homestead --------------------------------------------------------------------

alias ..="cd .."
alias ...="cd ../.."

alias h='cd ~'
alias c='clear'

alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'

# Laravel ----------------------------------------------------------------------

# Access Artisan when within project folder
alias artisan='php artisan'

# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"

# Composer --------------------------------------------------------------------

alias autoload='composer dump-autoload'

# App -------------------------------------------------------------------------

alias app="cd app"

After.sh File

#!/usr/bin/env bash

#
# Install RethinkDB on Ubuntu
# @see https://www.rethinkdb.com/docs/install/ubuntu/
#

# Add RethinkDB repository and install
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y rethinkdb

# Setup RethinkDB as a service using default configuration file
#sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf
#sudo vim /etc/rethinkdb/instances.d/instance1.conf
#sudo /etc/init.d/rethinkdb restart

# Setup RethinkDB as a service by copying the custom configuration file
sudo cp /home/vagrant/app/rethinkdb.conf /etc/rethinkdb/instances.d/instance1.conf
sudo /etc/init.d/rethinkdb restart

UPDATE 2

Nano output of .bash_aliases, which looks like my aliases file, but the output after this of alias truncates the first letter of the aliases.

# Homestead ----------------------------------------------------------------------

alias ..="cd .."
alias ...="cd ../.."

alias h='cd ~'
alias c='clear'

alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'

# Laravel ----------------------------------------------------------------------

# Access Artisan when within project folder
alias artisan='php artisan'

# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"

# Composer --------------------------------------------------------------------

alias autoload='composer dump-autoload'

Output from just typing alias into terminal:

vagrant@app:~$ alias
'lias ..='cd ..
'lias ...='cd ../..
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
'lias artisan='php artisan
'lias autoload='composer dump-autoload
'lias c='clear
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
'lias h='cd ~
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
'lias phpspec='vendor/bin/phpspec
'lias phpunit='vendor/bin/phpunit
'lias tinker='php artisan tinker --env=local

FINAL SOLUTION

Thanks to @JoshRumbut for solving this issue, see below for his comments.

vagrant@app:~$ tr -d '\r' <~/.bash_aliases >~/tmp
vagrant@app:~$ mv ~/tmp ~/.bash_aliases
vagrant@app:~$ unalias -a
vagrant@app:~$ source .bash_aliases
like image 779
mtpultz Avatar asked Oct 31 '22 11:10

mtpultz


1 Answers

Is bash configured to look in the .bash_aliases file?

What happens if you run source ~/.bash_aliases? Do they work then?

Edit: current theory is that a weird character, possibly the carriage return (\r) is embedded in the file somewhere, as in thus question: https://unix.stackexchange.com/questions/35642/why-are-these-aliases-failing

like image 196
Josh Rumbut Avatar answered Nov 09 '22 13:11

Josh Rumbut