Skip to content

Commit

Permalink
Merge pull request #16 from trobrock/fish-support
Browse files Browse the repository at this point in the history
Support fish shell
  • Loading branch information
trobrock committed Mar 7, 2014
2 parents afa02bb + 42e01ed commit 7799572
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
script: "./test/test.sh"
env:
- TEST_SHELL=bash
- TEST_SHELL=fish
11 changes: 10 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@ Vagrant.configure("2") do |config|

config.vm.synced_folder "./", "/root/.chefvm"

config.vm.provision :shell, path: "test/test.sh"
config.vm.define "bash" do |bash|
bash.vm.provision :shell, path: "test/test.sh"
end

config.vm.define "fish" do |fish|
fish.vm.provision :shell do |s|
s.path = "test/test.sh"
s.args = "fish"
end
end
end
41 changes: 37 additions & 4 deletions libexec/chefvm-init
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ if [ "$1" = "-" ]; then
print=1
shift
fi

shell="$1"
if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
fi

resolve_link() {
Expand Down Expand Up @@ -55,7 +57,15 @@ if [ -z "$print" ]; then
exit 1
fi

echo "export PATH=\"\${PATH}:${_CHEFVM_ROOT}/bin\""
bin_path="${_CHEFVM_ROOT}/bin"
case "$shell" in
fish )
echo "eval 'set -x PATH \$PATH \"$bin_path\"';"
;;
* )
echo "export PATH=\"\$PATH:$bin_path\""
;;
esac

case "$shell" in
bash | zsh )
Expand All @@ -65,7 +75,28 @@ esac

commands=(`chefvm commands --sh`)
IFS="|"
cat <<EOS
case "$shell" in
fish )
cat <<EOS
eval '
function chefvm
set command "\$1"
if test [ "\$argv" -gt 0 ]
shift
end
switch "\$command"
case ${commands[*]}
eval \`chefvm "sh-\$command" "\$argv"\`
case '*'
command chefvm "\$command" "\$argv"
end
end';
eval 'chefvm setup';
EOS
;;
* )
cat <<EOS
chefvm() {
local command="\$1"
if [ "\$#" -gt 0 ]; then
Expand All @@ -81,3 +112,5 @@ chefvm() {
}
chefvm setup
EOS
;;
esac
2 changes: 1 addition & 1 deletion share/chefvm/version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

export _CHEFVM_VERSION="1.1.0"
export _CHEFVM_VERSION="1.2.0"
11 changes: 11 additions & 0 deletions test/test.bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [ $TRAVIS_BUILD_DIR ]; then
CODE_PATH=$TRAVIS_BUILD_DIR
else
CODE_PATH="$HOME/.chefvm"
fi

eval "$($CODE_PATH/bin/chefvm init -)"

bats $CODE_PATH/test
24 changes: 24 additions & 0 deletions test/test.fish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env fish

if test -n "$TRAVIS_BUILD_DIR"
set CODE_PATH $TRAVIS_BUILD_DIR

# clean the path on travis
for val in $PATH
if test -d $val
set path $path $val
end
end
set -x PATH $path
else
set CODE_PATH $HOME/.chefvm
end

function chefvm_init
eval $CODE_PATH/bin/chefvm init -
end

echo $PATH
eval (chefvm_init)

bats $CODE_PATH/test
18 changes: 13 additions & 5 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env bash

# This is for bootstrapping and run tests on the vm
shell=${1:-"$TEST_SHELL"}
shell=${shell:-"bash"}

if [ ! -x "$(which git 2> /dev/null)" ]; then
echo "[setup] Installing git"
sudo apt-get install -y git-core
fi

if [ ! -x "$(which bats 2> /dev/null)" ]; then
echo "[setup] Installing bats"
git clone https://github.com/sstephenson/bats.git
cd bats
pushd bats
sudo ./install.sh /usr/local
popd
fi

if [ "$shell" == "fish" ] && [ ! -x "$(which fish 2> /dev/null)" ]; then
echo "[setup] Installing fish"
sudo apt-get install -y fish
fi

if [ $TRAVIS_BUILD_DIR ]; then
Expand All @@ -18,6 +27,5 @@ else
CODE_PATH="$HOME/.chefvm"
fi

eval "$($CODE_PATH/bin/chefvm init -)"

bats $CODE_PATH/test
echo "[setup] Running tests"
exec $CODE_PATH/test/test.$shell.sh

0 comments on commit 7799572

Please sign in to comment.