2017-02-18 07:25:48 +00:00
|
|
|
ENVY_CONFIG_DIR="${ENVY_CONFIG_DIR:-${HOME}/.envy}"
|
|
|
|
ENVY_DEFAULT_ENV="${ENVY_DEFAULT_ENV:-default}"
|
|
|
|
|
|
|
|
function _envy_start() {
|
|
|
|
_envy_load ${ENVY_DEFAULT_ENV} &>/dev/null || true
|
|
|
|
}
|
|
|
|
|
|
|
|
function _envy_load() {
|
2017-02-18 11:30:06 +00:00
|
|
|
local new_profile_path="${ENVY_CONFIG_DIR}/${1}"
|
2017-02-18 07:25:48 +00:00
|
|
|
|
2017-02-18 11:30:06 +00:00
|
|
|
if [[ ! -f ${new_profile_path} ]]; then
|
|
|
|
echo "Cannot find envy file '${new_profile_path}'"
|
2017-02-18 07:25:48 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2017-02-18 11:30:06 +00:00
|
|
|
source ${new_profile_path}
|
2017-02-18 07:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _envy_create() {
|
2017-02-18 11:30:06 +00:00
|
|
|
local new_profile_path="${ENVY_CONFIG_DIR}/${1}"
|
2017-02-18 07:25:48 +00:00
|
|
|
|
|
|
|
[[ -z "${1}" ]] && echo "No profile name argument" && return 1
|
|
|
|
[[ ! -d "${ENVY_CONFIG_DIR}" ]] && mkdir -p ${ENVY_CONFIG_DIR}
|
2017-02-18 11:30:06 +00:00
|
|
|
echo "#!/bin/bash" > ${new_profile_path}
|
|
|
|
echo "Created empty profile: ${new_profile_path}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _envy_edit() {
|
|
|
|
local profile_path="${ENVY_CONFIG_DIR}/${1}"
|
|
|
|
|
|
|
|
[[ -z "${1}" ]] && echo "No profile name argument" && return 1
|
|
|
|
[[ ! -f "${profile_path}" ]] && echo "Profile does not exists" && return 1
|
|
|
|
${EDITOR} ${profile_path}
|
2017-02-18 07:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function envy() {
|
|
|
|
case "${1}" in
|
|
|
|
create)
|
|
|
|
_envy_create ${2}
|
|
|
|
;;
|
|
|
|
|
2017-02-18 11:30:06 +00:00
|
|
|
edit)
|
|
|
|
_envy_edit ${2}
|
|
|
|
;;
|
|
|
|
|
2017-02-18 07:25:48 +00:00
|
|
|
*)
|
|
|
|
_envy_load ${1}
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
_envy_start
|