Skip to content

Instantly share code, notes, and snippets.

@bdangit
Forked from 7sDream/dvm.fish
Last active November 28, 2016 23:47
Show Gist options
  • Save bdangit/73203912eb4539f0b5198193257b0104 to your computer and use it in GitHub Desktop.
Save bdangit/73203912eb4539f0b5198193257b0104 to your computer and use it in GitHub Desktop.
Set up dvm command for fish shell.
# Docker Version Manager wrapper for *nix
# Implemented as a POSIX-compliant function
# Should work on sh, dash, bash, ksh, zsh
# To use, source this file from your bash profile
begin # This ensures the entire script is downloaded
set DVM_SCRIPT_SOURCE $_
# __dvm_has() {
# type "$1" > /dev/null 2>&1
# }
#
# function __dvm_has
# type "$1" >
# }
# Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors
# if __dvm_has "unsetopt"; then
# unsetopt nomatch 2>/dev/null
# DVM_CD_FLAGS="-q"
# fi
# Auto detect the DVM_DIR when not set
if test -z "$DVM_DIR"
if test -n (status -f)
set DVM_SCRIPT_SOURCE (status -f)
set ORIGIN_DIR (pwd)
set -x DVM_DIR (cd $DVM_CD_FLAGS $DVM_SCRIPT_SOURCE > /dev/null ; pwd)
cd "$ORIGIN_DIR"
set -e ORIGIN_DIR
else
set -Ux DVM_DIR (pwd)
end
end
set -e DVM_SCRIPT_SOURCE 2> /dev/null
function dvm
if not test -f "$DVM_DIR/dvm-helper/dvm-helper"
echo "Installation corrupt: dvm-helper is missing. Please reinstall dvm."
return 1
end
if test (uname) = "Darwin"
which gsed > /dev/null
if test $status -ne 0
echo "Install gnu-sed. \`brew install gnu-sed`"
return 1
end
end
set DVM_OUTPUT $DVM_DIR/.tmp/dvm-output.sh
set DVM_OUTPUT_FISH $DVM_DIR/.tmp/dvm-output.fish
rm -f "$DVM_OUTPUT"
rm -f "$DVM_OUTPUT_FISH"
env DVM_DIR=$DVM_DIR $DVM_DIR/dvm-helper/dvm-helper --shell sh $argv
if test -e "$DVM_OUTPUT"
# convert sh to fish
if test (uname) = "Darwin"
gsed -r -e "s%export (\w+)=\"%set -gx \1 %g" -e "s%:% %g" -e "s%\"\$%%g" "$DVM_OUTPUT" > "$DVM_OUTPUT_FISH"
else
sed -r -e "s%export (\w+)=\"%set -gx \1 %g" -e "s%:% %g" -e "s%\"\$%%g" "$DVM_OUTPUT" > "$DVM_OUTPUT_FISH"
end
source "$DVM_OUTPUT_FISH"
end
end
end
@bdangit
Copy link
Author

bdangit commented Nov 28, 2016

@milieu when i ran this, it was saying that -r is an illegal option. At the time, I just said f it and just install gsed.

However, just googled right now and it looks like mac chose to provide -E flag which does the same thing. duncanje/todo.txt-revive#1 I have not tested this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment