github.com/beanworks/dcm@v0.0.0-20230726194615-49d2d0417e04/dcm.sh (about) 1 # Entry point of the dcm command 2 dcm() { 3 local OS=$(uname -s) 4 local ARCH=$(uname -m) 5 local BIN=$DCM_DIR/bin 6 7 8 if [[ "$OS" == "Darwin" ]] && [[ "$ARCH" == "arm64" ]]; then 9 BIN=$BIN/dcm-darwin-arm64 10 elif [[ "$OS" == "Darwin" ]] && [[ "$ARCH" == "x86_64" ]]; then 11 BIN=$BIN/dcm-darwin-amd64 12 elif [[ "$OS" == "Linux" ]] && [[ "$ARCH" == "x86_64" ]]; then 13 BIN=$BIN/dcm-linux-amd64 14 elif [[ "$OS" == "FreeBSD" ]] && [[ "$ARCH" == "x86_64" ]]; then 15 BIN=$BIN/dcm-freebsd-amd64 16 elif [[ "$OS" == "CYGWIN_NT-6.1" ]] && [[ "$ARCH" == "x86_64" ]]; then 17 BIN=$BIN/dcm-windows-amd64.exe 18 else 19 >&2 echo "Sorry, your OS ($OS) and Arch ($ARCH) is not currently supported by DCM." && \ 20 echo "Please submit your issue at https://github.com/beanworks/dcm/issues" 21 return 1 22 fi 23 24 case "$1" in 25 "goto" | "gt" | "cd" ) 26 cd $($BIN dir ${@:2}) 27 ;; 28 "unload" | "ul" ) 29 unset -f dcm > /dev/null 2>&1 30 unset DCM_DIR DCM_PROJECT > /dev/null 2>&1 31 ;; 32 * ) 33 $BIN ${@} 34 ;; 35 esac 36 } 37 38 # DCM command autocomplete handler 39 _dcm_complete() { 40 local cur=${COMP_WORDS[COMP_CWORD]} 41 local use="" 42 43 case $COMP_CWORD in 44 1) 45 use="help setup run build shell purge branch goto update unload" 46 ;; 47 2) 48 local prev_word=${COMP_WORDS[1]} 49 case $prev_word in 50 run|r) 51 use="execute init build start stop restart up" 52 ;; 53 purge|rm) 54 use="images containers all" 55 ;; 56 shell|sh|branch|br|goto|gt|cd|update|u) 57 use=`dcm list` 58 ;; 59 esac 60 ;; 61 esac 62 63 COMPREPLY=( $( compgen -W "$use" -- $cur ) ) 64 } 65 66 complete -o default -F _dcm_complete dcm