mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-27 08:10:08 +00:00
feat(scw): add new functions to handle profiles
This commit adds the following commands: - ssp (Scaleway Set Profile) allows to set the current SCW_PROFILE - sgp (Scaleway Get Profile) allows to show the current SCW_PROFILE - scw_profiles allows to list available profiles Completion and error handling is supported for the ssp command.
This commit is contained in:
parent
c22e5518ae
commit
9acee1babd
1 changed files with 48 additions and 0 deletions
|
@ -3,6 +3,54 @@ if ! command -v scw &> /dev/null; then
|
|||
return
|
||||
fi
|
||||
|
||||
function sgp() {
|
||||
echo "$SCW_PROFILE"
|
||||
}
|
||||
|
||||
# SCW profile selection
|
||||
function ssp() {
|
||||
if [[ -z "$1" ]]; then
|
||||
unset SCW_PROFILE
|
||||
echo SCW profile cleared.
|
||||
return
|
||||
fi
|
||||
|
||||
local -a available_profiles
|
||||
available_profiles=($(scw_profiles))
|
||||
if [[ -z "${available_profiles[(r)$1]}" ]]; then
|
||||
echo "${fg[red]}Profile '$1' not found in '$(scw_config_path)'" >&2
|
||||
echo "Available profiles: ${(j:, :)available_profiles:-no profiles found}${reset_color}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
export SCW_PROFILE=$1
|
||||
}
|
||||
|
||||
function scw_profiles() {
|
||||
scw autocomplete complete zsh 3 -- scw --profile 2> /dev/null
|
||||
}
|
||||
|
||||
function scw_config_path() {
|
||||
if [[ -v SCW_CONFIG_PATH ]]; then
|
||||
echo "$SCW_CONFIG_PATH"
|
||||
return
|
||||
fi
|
||||
|
||||
for f in "$XDG_CONFIG_HOME/scw/config.yaml" \
|
||||
"$HOME/.config/scw/config.yaml" \
|
||||
"$USERPROFILE/.config/scw/config.yaml"; do
|
||||
if [[ -f "$f" ]]; then
|
||||
echo "$f"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function _scw_profiles() {
|
||||
reply=($(scw_profiles))
|
||||
}
|
||||
compctl -K _scw_profiles ssp
|
||||
|
||||
# Load scw autocompletion if autocompletion not already loaded
|
||||
if ! command -v _scw &> /dev/null; then
|
||||
eval "$(scw autocomplete script shell=zsh)"
|
||||
|
|
Loading…
Reference in a new issue